From 8a754e0858d922e955e71b253c139e071ecec432 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 18:04:21 +0200 Subject: Adding upstream version 2.14.3. Signed-off-by: Daniel Baumann --- test/integration/targets/become/aliases | 4 ++ test/integration/targets/become/files/copy.txt | 1 + test/integration/targets/become/meta/main.yml | 2 + test/integration/targets/become/tasks/become.yml | 49 ++++++++++++++++++++++++ test/integration/targets/become/tasks/main.yml | 20 ++++++++++ test/integration/targets/become/vars/main.yml | 14 +++++++ 6 files changed, 90 insertions(+) create mode 100644 test/integration/targets/become/aliases create mode 100644 test/integration/targets/become/files/copy.txt create mode 100644 test/integration/targets/become/meta/main.yml create mode 100644 test/integration/targets/become/tasks/become.yml create mode 100644 test/integration/targets/become/tasks/main.yml create mode 100644 test/integration/targets/become/vars/main.yml (limited to 'test/integration/targets/become') diff --git a/test/integration/targets/become/aliases b/test/integration/targets/become/aliases new file mode 100644 index 0000000..0c490f1 --- /dev/null +++ b/test/integration/targets/become/aliases @@ -0,0 +1,4 @@ +destructive +shippable/posix/group1 +context/target +gather_facts/no diff --git a/test/integration/targets/become/files/copy.txt b/test/integration/targets/become/files/copy.txt new file mode 100644 index 0000000..b8d834d --- /dev/null +++ b/test/integration/targets/become/files/copy.txt @@ -0,0 +1 @@ +testing tilde expansion with become diff --git a/test/integration/targets/become/meta/main.yml b/test/integration/targets/become/meta/main.yml new file mode 100644 index 0000000..0cef72c --- /dev/null +++ b/test/integration/targets/become/meta/main.yml @@ -0,0 +1,2 @@ +dependencies: + - setup_test_user diff --git a/test/integration/targets/become/tasks/become.yml b/test/integration/targets/become/tasks/become.yml new file mode 100644 index 0000000..d31634f --- /dev/null +++ b/test/integration/targets/become/tasks/become.yml @@ -0,0 +1,49 @@ +- name: test becoming user ({{ become_test }}) + raw: whoami + register: whoami + +- name: implicit tilde expansion reflects become user ({{ become_test }}) + stat: + path: "~" + register: stat_home_implicit + +- name: explicit tilde expansion reflects become user ({{ become_test }}) + stat: + path: "~{{ ansible_become_user }}" + register: stat_home_explicit + +- name: put a file ({{ become_test }}) + copy: + src: copy.txt + dest: "~{{ ansible_become_user }}/{{ ansible_become_method }}-{{ ansible_become_user }}-copy.txt" + register: put_file + +- name: fetch a file ({{ become_test }}) + fetch: + src: "~{{ ansible_become_user }}/{{ ansible_become_method }}-{{ ansible_become_user }}-copy.txt" + dest: "{{ output_dir }}" + register: fetch_file + +- name: explicit tilde expansion reflects become user ({{ become_test }}) + stat: + path: "~{{ ansible_become_user }}/{{ ansible_become_method }}-{{ ansible_become_user }}-copy.txt" + register: stat_file + +- name: verify results from previous tasks ({{ become_test }}) + assert: + that: + - "whoami.stdout|trim == ansible_become_user" + + - "stat_home_implicit.stat.exists == True" + - "stat_home_implicit.stat.path|basename == ansible_become_user" + + - "stat_home_explicit.stat.exists == True" + - "stat_home_explicit.stat.path|basename == ansible_become_user" + + - "put_file.uid == test_user.uid" + - "put_file.gid == test_user.group" + + - "fetch_file.remote_checksum == put_file.checksum" + + - "stat_file.stat.exists == True" + - "stat_file.stat.path|dirname|basename == ansible_become_user" diff --git a/test/integration/targets/become/tasks/main.yml b/test/integration/targets/become/tasks/main.yml new file mode 100644 index 0000000..4a2ce64 --- /dev/null +++ b/test/integration/targets/become/tasks/main.yml @@ -0,0 +1,20 @@ +- name: determine connection user + command: whoami + register: connection_user + vars: + ansible_become: no + +- name: include become tests + include_tasks: become.yml + vars: + ansible_become: yes + ansible_become_user: "{{ become_test_config.user }}" + ansible_become_method: "{{ become_test_config.method }}" + ansible_become_password: "{{ become_test_config.password | default(None) }}" + loop: "{{ + (become_methods | selectattr('skip', 'undefined') | list)+ + (become_methods | selectattr('skip', 'defined') | rejectattr('skip') | list) + }}" + loop_control: + loop_var: become_test_config + label: "{{ become_test }}" diff --git a/test/integration/targets/become/vars/main.yml b/test/integration/targets/become/vars/main.yml new file mode 100644 index 0000000..d9c1cd0 --- /dev/null +++ b/test/integration/targets/become/vars/main.yml @@ -0,0 +1,14 @@ +become_test: >- + {{ become_test_config.method }} from {{ connection_user.stdout }} to {{ become_test_config.user }} + {{ 'with' if become_test_config.password else 'without' }} password + +become_methods: + - method: sudo + user: "{{ test_user_name }}" + password: "{{ test_user_plaintext_password if connection_user.stdout != 'root' else None }}" + # Some systems are not configured to allow sudo for non-root users. + # The tests could be updated in the future to temporarily enable sudo for the connection user. + skip: "{{ connection_user.stdout != 'root' and ansible_distribution == 'FreeBSD' }}" + - method: su + user: "{{ test_user_name }}" + password: "{{ test_user_plaintext_password if connection_user.stdout != 'root' else None }}" -- cgit v1.2.3