2014-12-03 18:45:54 +00:00
|
|
|
- include_vars: default.yml
|
|
|
|
|
|
|
|
- name: Create test user
|
2014-11-24 21:36:31 +00:00
|
|
|
sudo: true
|
2014-12-03 18:45:54 +00:00
|
|
|
user:
|
|
|
|
name: "{{ sudo_test_user }}"
|
|
|
|
|
2014-11-24 21:36:31 +00:00
|
|
|
- name: test becoming user
|
|
|
|
shell: whoami
|
|
|
|
sudo: True
|
|
|
|
sudo_user: "{{ sudo_test_user }}"
|
|
|
|
register: results
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "results.stdout == '{{ sudo_test_user }}'"
|
|
|
|
|
2014-12-03 18:45:54 +00:00
|
|
|
- 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
|
2015-11-11 13:42:35 +00:00
|
|
|
sudo: True
|
|
|
|
sudo_user: "{{ sudo_test_user }}"
|
2014-12-03 18:45:54 +00:00
|
|
|
stat:
|
|
|
|
path: "~{{ sudo_test_user }}/foo.txt"
|
|
|
|
register: results
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "results.stat.exists == True"
|
2014-12-04 19:35:03 +00:00
|
|
|
- "results.stat.path|dirname|basename == '{{ sudo_test_user }}'"
|
2014-12-03 18:45:54 +00:00
|
|
|
|
|
|
|
- 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
|
2015-11-11 13:42:35 +00:00
|
|
|
sudo: True
|
|
|
|
sudo_user: "{{ sudo_test_user }}"
|
2014-12-03 18:45:54 +00:00
|
|
|
stat:
|
|
|
|
path: "~{{ sudo_test_user }}/bar.txt"
|
|
|
|
register: results
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "results.stat.exists == True"
|
2014-12-04 19:35:03 +00:00
|
|
|
- "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
|
2015-11-11 13:42:35 +00:00
|
|
|
sudo: True
|
|
|
|
sudo_user: "{{ sudo_test_user }}"
|
2014-12-04 19:35:03 +00:00
|
|
|
stat:
|
|
|
|
path: "~{{ sudo_test_user }}/baz.txt"
|
|
|
|
register: results
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- "results.stat.exists == True"
|
|
|
|
- "results.stat.path|dirname|basename == '{{ sudo_test_user }}'"
|
2014-12-03 18:45:54 +00:00
|
|
|
|
|
|
|
- name: Remove test user and their home dir
|
2014-11-24 21:36:31 +00:00
|
|
|
sudo: true
|
2014-12-03 18:45:54 +00:00
|
|
|
user:
|
|
|
|
name: "{{ sudo_test_user }}"
|
|
|
|
state: "absent"
|
|
|
|
remove: "yes"
|
|
|
|
|