ansible_mitogen: Support templated become_user
This reads the become username from the `become_user` attribute of the play
context, to the `"become_user"` option of the loaded become plugin. This has
been supported by vanilla Ansible since Ansible 2.10 (ansible-base 2.10).
To support this I've also switched from using the `play_context.become` (a
bool), to `connection.become` (an instance of the appropriate) become plugin.
New tests have been added, modelled on those for templated connection
parameters (see #1147, #1153, #1159).
See
- 480b106d65
refs #1083
Co-authored-by: mordek <m.pirog@bonasoft.pl>
pull/1148/head
parent
3b2b03bd97
commit
bf6607e27e
@ -0,0 +1,14 @@
|
|||||||
|
- name: integration/become/templated_by_inv.yml
|
||||||
|
hosts: tt_become_by_inv
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- meta: reset_connection
|
||||||
|
- name: Templated become in inventory
|
||||||
|
command:
|
||||||
|
cmd: whoami
|
||||||
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
register: become_templated_by_inv_whoami
|
||||||
|
failed_when:
|
||||||
|
- become_templated_by_inv_whoami is failed
|
||||||
|
or become_templated_by_inv_whoami.stdout != 'root'
|
@ -0,0 +1,16 @@
|
|||||||
|
- name: integration/become/templated_by_play_keywords.yml
|
||||||
|
hosts: tt_become_bare
|
||||||
|
gather_facts: false
|
||||||
|
become: true
|
||||||
|
become_user: "{{ 'root' | trim }}"
|
||||||
|
tasks:
|
||||||
|
- meta: reset_connection
|
||||||
|
- name: Templated become by play keywords
|
||||||
|
command:
|
||||||
|
cmd: whoami
|
||||||
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
register: become_templated_by_play_keywords_whoami
|
||||||
|
failed_when:
|
||||||
|
- become_templated_by_play_keywords_whoami is failed
|
||||||
|
or become_templated_by_play_keywords_whoami.stdout != 'root'
|
@ -0,0 +1,16 @@
|
|||||||
|
- name: integration/become/templated_by_play_vars.yml
|
||||||
|
hosts: tt_become_bare
|
||||||
|
gather_facts: false
|
||||||
|
vars:
|
||||||
|
ansible_become: true
|
||||||
|
ansible_become_user: "{{ 'root' | trim }}"
|
||||||
|
tasks:
|
||||||
|
- name: Templated become by play vars
|
||||||
|
command:
|
||||||
|
cmd: whoami
|
||||||
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
register: become_templated_by_play_vars_whoami
|
||||||
|
failed_when:
|
||||||
|
- become_templated_by_play_vars_whoami is failed
|
||||||
|
or become_templated_by_play_vars_whoami.stdout != 'root'
|
@ -0,0 +1,27 @@
|
|||||||
|
- name: integration/become/templated_by_task_keywords.yml
|
||||||
|
hosts: tt_become_bare
|
||||||
|
gather_facts: false
|
||||||
|
# FIXME Resetting the connection shouldn't require credentials
|
||||||
|
# https://github.com/mitogen-hq/mitogen/issues/1132
|
||||||
|
become: true
|
||||||
|
become_user: "{{ 'root' | trim }}"
|
||||||
|
tasks:
|
||||||
|
- name: Reset connection to target that will be delegate_to
|
||||||
|
meta: reset_connection
|
||||||
|
|
||||||
|
- name: Test connection template by task keywords, with delegate_to
|
||||||
|
hosts: test-targets[0]
|
||||||
|
gather_facts: false
|
||||||
|
tasks:
|
||||||
|
- name: Templated become by task keywords, with delegate_to
|
||||||
|
become: true
|
||||||
|
become_user: "{{ 'root' | trim }}"
|
||||||
|
delegate_to: "{{ groups.tt_become_bare[0] }}"
|
||||||
|
command:
|
||||||
|
cmd: whoami
|
||||||
|
changed_when: false
|
||||||
|
check_mode: false
|
||||||
|
register: become_templated_by_task_with_delegate_to_whoami
|
||||||
|
failed_when:
|
||||||
|
- become_templated_by_task_with_delegate_to_whoami is failed
|
||||||
|
or become_templated_by_task_with_delegate_to_whoami.stdout != 'root'
|
Loading…
Reference in New Issue