Fix become integration test. (#78313)

* Don't set become_flags in become integration test.

Setting the flags in the test overrides the default value in the become plugins, which was not intentional.

* Remove hack for broken implicit tilde support.

It was only broken because the tests were overriding the default become flags for sudo.

* Simplify assertions.
pull/78315/head
Matt Clay 2 years ago committed by GitHub
parent 619a1fa7e2
commit 27d39be580
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -2,7 +2,7 @@
raw: whoami
register: whoami
- name: implicit tilde expansion reflects become user (broken={{ become_test_config.implicit_tilde_broken | default(False) }}) ({{ become_test }})
- name: implicit tilde expansion reflects become user ({{ become_test }})
stat:
path: "~"
register: stat_home_implicit
@ -32,13 +32,13 @@
- name: verify results from previous tasks ({{ become_test }})
assert:
that:
- "whoami.stdout|trim == '{{ ansible_become_user }}'"
- "whoami.stdout|trim == ansible_become_user"
- "stat_home_implicit.stat.exists == True"
- "stat_home_implicit.stat.path|basename == '{{ ansible_become_user }}' or (become_test_config.implicit_tilde_broken | default(False))"
- "stat_home_implicit.stat.path|basename == ansible_become_user"
- "stat_home_explicit.stat.exists == True"
- "stat_home_explicit.stat.path|basename == '{{ ansible_become_user }}'"
- "stat_home_explicit.stat.path|basename == ansible_become_user"
- "put_file.uid == test_user.uid"
- "put_file.gid == test_user.group"
@ -46,4 +46,4 @@
- "fetch_file.remote_checksum == put_file.checksum"
- "stat_file.stat.exists == True"
- "stat_file.stat.path|dirname|basename == '{{ ansible_become_user }}'"
- "stat_file.stat.path|dirname|basename == ansible_become_user"

@ -9,7 +9,6 @@
vars:
ansible_become: yes
ansible_become_user: "{{ become_test_config.user }}"
ansible_become_flags: "{{ become_test_config.flags | default(None) }}"
ansible_become_method: "{{ become_test_config.method }}"
ansible_become_password: "{{ become_test_config.password | default(None) }}"
loop: "{{

@ -1,7 +1,6 @@
become_test: >-
{{ become_test_config.method }} from {{ connection_user.stdout }} to {{ become_test_config.user }}
{{ 'with' if become_test_config.password else 'without' }} password
{{ 'with flags: ' + become_test_config.flags if become_test_config.flags | default('') else 'without flags' }}
become_methods:
- method: sudo
@ -10,9 +9,6 @@ become_methods:
# 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' }}"
# Implicit tilde support `~` is broken on systems which do not set HOME to that of the become user.
# Explicit tilde support `~username` is unaffected.
implicit_tilde_broken: "{{ ansible_distribution == 'MacOSX' }}"
- method: su
user: "{{ test_user_name }}"
password: "{{ test_user_plaintext_password if connection_user.stdout != 'root' else None }}"

Loading…
Cancel
Save