mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add sudo/su become_methods for become tests (#30266)
* Add sudo/su become_methods for become tests * Fix test on osx
This commit is contained in:
parent
9d5671db76
commit
dc5f83c09b
4 changed files with 276 additions and 81 deletions
81
test/integration/targets/become/tasks/default.yml
Normal file
81
test/integration/targets/become/tasks/default.yml
Normal file
|
@ -0,0 +1,81 @@
|
|||
- name: Create test user (become_method=default)
|
||||
become: True
|
||||
become_user: root
|
||||
user:
|
||||
name: "{{ become_test_user }}"
|
||||
|
||||
- name: test becoming user (become_method=default)
|
||||
shell: whoami
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stdout == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in file (become_method=default)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
file:
|
||||
path: "~/foo.txt"
|
||||
state: touch
|
||||
|
||||
- name: check that the path in the user's home dir was created (become_method=default)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/foo.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in template (become_method=default)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
template:
|
||||
src: "bar.j2"
|
||||
dest: "~/bar.txt"
|
||||
|
||||
- name: check that the path in the user's home dir was created (become_method=default)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/bar.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in copy (become_method=default)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
copy:
|
||||
src: baz.txt
|
||||
dest: "~/baz.txt"
|
||||
|
||||
- name: check that the path in the user's home dir was created (become_method=default)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/baz.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: Remove test user and their home dir (become_method=default)
|
||||
become: True
|
||||
become_user: root
|
||||
user:
|
||||
name: "{{ become_test_user }}"
|
||||
state: "absent"
|
||||
remove: "yes"
|
||||
force: "yes"
|
|
@ -1,83 +1,5 @@
|
|||
- include_vars: default.yml
|
||||
|
||||
- name: Create test user
|
||||
become: True
|
||||
become_user: root
|
||||
user:
|
||||
name: "{{ become_test_user }}"
|
||||
|
||||
- name: test becoming user
|
||||
shell: whoami
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stdout == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in file
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
file:
|
||||
path: "~/foo.txt"
|
||||
state: touch
|
||||
|
||||
- name: check that the path in the user's home dir was created
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/foo.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in template
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
template:
|
||||
src: "bar.j2"
|
||||
dest: "~/bar.txt"
|
||||
|
||||
- name: check that the path in the user's home dir was created
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/bar.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in copy
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
copy:
|
||||
src: baz.txt
|
||||
dest: "~/baz.txt"
|
||||
|
||||
- name: check that the path in the user's home dir was created
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/baz.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: Remove test user and their home dir
|
||||
become: True
|
||||
become_user: root
|
||||
user:
|
||||
name: "{{ become_test_user }}"
|
||||
state: "absent"
|
||||
remove: "yes"
|
||||
force: "yes"
|
||||
- include: default.yml
|
||||
- include: sudo.yml
|
||||
- include: su.yml
|
||||
|
|
102
test/integration/targets/become/tasks/su.yml
Normal file
102
test/integration/targets/become/tasks/su.yml
Normal file
|
@ -0,0 +1,102 @@
|
|||
- name: Create test user (become_method=su)
|
||||
become: True
|
||||
become_user: root
|
||||
become_method: su
|
||||
user:
|
||||
name: "{{ become_test_user }}"
|
||||
when: ansible_distribution != "MacOSX"
|
||||
|
||||
|
||||
- name: Create test user (become_method=su)
|
||||
become: True
|
||||
become_user: root
|
||||
become_method: su
|
||||
user:
|
||||
name: "{{ become_test_user }}"
|
||||
# explicitly set user shell since the default shell on OS X is /usr/bin/false
|
||||
shell: /bin/bash
|
||||
when: ansible_distribution == "MacOSX"
|
||||
|
||||
- name: test becoming user (become_method=su)
|
||||
shell: whoami
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: su
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stdout == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in file (become_method=su)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: su
|
||||
file:
|
||||
path: "~/foo.txt"
|
||||
state: touch
|
||||
|
||||
- name: check that the path in the user's home dir was created (become_method=su)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: su
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/foo.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in template (become_method=su)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: su
|
||||
template:
|
||||
src: "bar.j2"
|
||||
dest: "~/bar.txt"
|
||||
|
||||
- name: check that the path in the user's home dir was created (become_method=su)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: su
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/bar.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in copy (become_method=su)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: su
|
||||
copy:
|
||||
src: baz.txt
|
||||
dest: "~/baz.txt"
|
||||
|
||||
- name: check that the path in the user's home dir was created (become_method=su)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: su
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/baz.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: Remove test user and their home dir (become_method=su)
|
||||
become: True
|
||||
become_user: root
|
||||
become_method: su
|
||||
user:
|
||||
name: "{{ become_test_user }}"
|
||||
state: "absent"
|
||||
remove: "yes"
|
||||
force: "yes"
|
90
test/integration/targets/become/tasks/sudo.yml
Normal file
90
test/integration/targets/become/tasks/sudo.yml
Normal file
|
@ -0,0 +1,90 @@
|
|||
- name: Create test user (become_method=sudo)
|
||||
become: True
|
||||
become_user: root
|
||||
become_method: sudo
|
||||
user:
|
||||
name: "{{ become_test_user }}"
|
||||
|
||||
- name: test becoming user (become_method=sudo)
|
||||
shell: whoami
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: sudo
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stdout == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in file (become_method=sudo)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: sudo
|
||||
file:
|
||||
path: "~/foo.txt"
|
||||
state: touch
|
||||
|
||||
- name: check that the path in the user's home dir was created (become_method=sudo)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: sudo
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/foo.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in template (become_method=sudo)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: sudo
|
||||
template:
|
||||
src: "bar.j2"
|
||||
dest: "~/bar.txt"
|
||||
|
||||
- name: check that the path in the user's home dir was created (become_method=sudo)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: sudo
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/bar.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: tilde expansion honors become in copy (become_method=sudo)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: sudo
|
||||
copy:
|
||||
src: baz.txt
|
||||
dest: "~/baz.txt"
|
||||
|
||||
- name: check that the path in the user's home dir was created (become_method=sudo)
|
||||
become: True
|
||||
become_user: "{{ become_test_user }}"
|
||||
become_method: sudo
|
||||
stat:
|
||||
path: "~{{ become_test_user }}/baz.txt"
|
||||
register: results
|
||||
|
||||
- assert:
|
||||
that:
|
||||
- "results.stat.exists == True"
|
||||
- "results.stat.path|dirname|basename == '{{ become_test_user }}'"
|
||||
|
||||
- name: Remove test user and their home dir (become_method=sudo)
|
||||
become: True
|
||||
become_user: root
|
||||
become_method: sudo
|
||||
user:
|
||||
name: "{{ become_test_user }}"
|
||||
state: "absent"
|
||||
remove: "yes"
|
||||
force: "yes"
|
Loading…
Reference in a new issue