You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/integration/targets/unarchive/tasks/test_unprivileged_user.yml

82 lines
2.3 KiB
YAML

- name: Create unarchivetest1 user
user:
name: unarchivetest1
uid: 1002610001
group: "{{ group_table[ansible_facts['distribution']] | default(omit) }}"
register: user
vars:
group_table:
MacOSX: staff
- name: Test unarchiving twice as unprivileged user
become: yes
become_user: unarchivetest1
block:
- name: prep our file
copy:
src: foo.txt
dest: "{{ user.home }}/foo-unarchive.txt"
- name: Prep a zip file as unarchivetest1 user
shell: zip unarchivetest1-unarchive.zip foo-unarchive.txt
args:
chdir: "{{ user.home }}"
creates: "{{ user.home }}/unarchivetest1-unarchive.zip"
- name: create our zip unarchive destination as unarchivetest1 user
file:
path: "{{ user.home }}/unarchivetest1-unarchive-zip"
state: directory
- name: unarchive a zip file as unarchivetest1 user
unarchive:
src: "{{ user.home }}/unarchivetest1-unarchive.zip"
dest: "{{ user.home }}/unarchivetest1-unarchive-zip"
remote_src: yes
list_files: True
register: unarchive10
- name: verify that the file was marked as changed
assert:
that:
- "unarchive10.changed == true"
# Verify that file list is generated
- "'files' in unarchive10"
- "{{unarchive10['files']| length}} == 1"
- "'foo-unarchive.txt' in unarchive10['files']"
- name: verify that the file was unarchived
file:
path: "{{ user.home }}/unarchivetest1-unarchive-zip/{{ item }}"
state: file
loop:
- foo-unarchive.txt
- name: repeat the last request to verify no changes
unarchive:
src: "{{ user.home }}/unarchivetest1-unarchive.zip"
dest: "{{ user.home }}/unarchivetest1-unarchive-zip"
remote_src: yes
list_files: True
register: unarchive10b
- name: verify that the task was not marked as changed
assert:
that:
- "unarchive10b.changed == false"
always:
- name: remove our unarchivetest1 user and files
user:
name: unarchivetest1
state: absent
remove: yes
become: no
- name: Remove user home directory on macOS
file:
path: /Users/unarchivetest1
state: absent
become: no
when: ansible_facts.distribution == 'MacOSX'