ansible/test/integration/roles/test_sudo/tasks/main.yml
Will Thames 5bb759e7ab Elevate privileges when checking for file existence
Certain OSs default to home directories as 0700
Without elevating privileges, checking for file existence
fails.
2015-11-11 23:42:35 +10:00

81 lines
1.8 KiB
YAML

- include_vars: default.yml
- name: Create test user
sudo: true
user:
name: "{{ sudo_test_user }}"
- name: test becoming user
shell: whoami
sudo: True
sudo_user: "{{ sudo_test_user }}"
register: results
- assert:
that:
- "results.stdout == '{{ sudo_test_user }}'"
- name: tilde expansion honors sudo in file
sudo: True
sudo_user: "{{ sudo_test_user }}"
file:
path: "~/foo.txt"
state: touch
- name: check that the path in the user's home dir was created
sudo: True
sudo_user: "{{ sudo_test_user }}"
stat:
path: "~{{ sudo_test_user }}/foo.txt"
register: results
- assert:
that:
- "results.stat.exists == True"
- "results.stat.path|dirname|basename == '{{ sudo_test_user }}'"
- name: tilde expansion honors sudo in template
sudo: True
sudo_user: "{{ sudo_test_user }}"
template:
src: "bar.j2"
dest: "~/bar.txt"
- name: check that the path in the user's home dir was created
sudo: True
sudo_user: "{{ sudo_test_user }}"
stat:
path: "~{{ sudo_test_user }}/bar.txt"
register: results
- assert:
that:
- "results.stat.exists == True"
- "results.stat.path|dirname|basename == '{{ sudo_test_user }}'"
- name: tilde expansion honors sudo in copy
sudo: True
sudo_user: "{{ sudo_test_user }}"
copy:
src: baz.txt
dest: "~/baz.txt"
- name: check that the path in the user's home dir was created
sudo: True
sudo_user: "{{ sudo_test_user }}"
stat:
path: "~{{ sudo_test_user }}/baz.txt"
register: results
- assert:
that:
- "results.stat.exists == True"
- "results.stat.path|dirname|basename == '{{ sudo_test_user }}'"
- name: Remove test user and their home dir
sudo: true
user:
name: "{{ sudo_test_user }}"
state: "absent"
remove: "yes"