Skip to content

Commit

Permalink
Merge pull request mitogen-hq#1192 from moreati/issue-1083-become_method
Browse files Browse the repository at this point in the history
ansible_mitogen: Templated become method
  • Loading branch information
moreati authored Nov 7, 2024
2 parents 61c8267 + e120cd2 commit 8e64459
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ def become_flags(self):
return self._become_option('become_flags')

def become_method(self):
return self._play_context.become_method
return self._connection.become.name

def become_user(self):
return self._become_option('become_user')
Expand Down
2 changes: 2 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ To avail of fixes in an unreleased version, please download a ZIP file
In progress (unreleased)
------------------------

* :gh:issue:`1083` :mod:`ansible_mitogen`: Templated become method
(e.g. ``ansible_become_method``).


v0.3.17 (2024-11-07)
Expand Down
1 change: 1 addition & 0 deletions tests/ansible/hosts/default.hosts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ ansible_user="{{ lookup('pipe', 'whoami') }}"
[tt_become_by_inv]
tt-become-exe ansible_become=true ansible_become_exe="{{ 'sudo' | trim }}" ansible_become_user=root
tt-become-flags ansible_become=true ansible_become_flags="{{ '--set-home --stdin --non-interactive' | trim }}" ansible_become_user=root
tt-become-method ansible_become=true ansible_become_method="{{ 'sudo' | trim }}" ansible_become_user=root
tt-become-pass ansible_become=true ansible_become_pass="{{ 'pw_required_password' | trim }}" ansible_become_user=mitogen__pw_required
tt-become-user ansible_become=true ansible_become_user="{{ 'root' | trim }}"

Expand Down
1 change: 1 addition & 0 deletions tests/ansible/integration/become/templated_by_inv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
expected_become_users:
tt-become-exe: root
tt-become-flags: root
tt-become-method: root
tt-become-pass: mitogen__pw_required
tt-become-user: root
command:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
become: true
become_exe: "{{ 'sudo' | trim }}"
become_flags: "{{ '--set-home --stdin --non-interactive' | trim }}"
become_method: "{{ 'sudo' | trim }}"
become_user: "{{ 'root' | trim }}"
tasks:
- meta: reset_connection
Expand All @@ -24,6 +25,7 @@
become: true
become_exe: "{{ 'sudo' | trim }}"
become_flags: "{{ '--set-home --stdin --non-interactive' | trim }}"
become_method: "{{ 'sudo' | trim }}"
become_user: "{{ 'mitogen__pw_required' | trim }}"
vars:
ansible_become_pass: "{{ 'pw_required_password' | trim }}"
Expand Down
2 changes: 2 additions & 0 deletions tests/ansible/integration/become/templated_by_play_vars.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ansible_become: true
ansible_become_exe: "{{ 'sudo' | trim }}"
ansible_become_flags: "{{ '--set-home --stdin --non-interactive' | trim }}"
ansible_become_method: "{{ 'sudo' | trim }}"
ansible_become_user: "{{ 'root' | trim }}"
tasks:
- name: Templated become by play vars, no password
Expand All @@ -24,6 +25,7 @@
ansible_become: true
ansible_become_exe: "{{ 'sudo' | trim }}"
ansible_become_flags: "{{ '--set-home --stdin --non-interactive' | trim }}"
ansible_become_method: "{{ 'sudo' | trim }}"
ansible_become_pass: "{{ 'pw_required_password' | trim }}"
ansible_become_user: "{{ 'mitogen__pw_required' | trim }}"
tasks:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
become: true
become_exe: "{{ 'sudo' | trim }}"
become_flags: "{{ '--set-home --stdin --non-interactive' | trim }}"
become_method: "{{ 'sudo' | trim }}"
become_user: "{{ 'root' | trim }}"
tasks:
- name: Reset connection to target that will be delegate_to
Expand All @@ -19,6 +20,7 @@
become: true
become_exe: "{{ 'sudo' | trim }}"
become_flags: "{{ '--set-home --stdin --non-interactive' | trim }}"
become_method: "{{ 'sudo' | trim }}"
become_user: "{{ 'root' | trim }}"
delegate_to: "{{ groups.tt_become_bare[0] }}"
command:
Expand All @@ -39,6 +41,7 @@
become: true
become_exe: "{{ 'sudo' | trim }}"
become_flags: "{{ '--set-home --stdin --non-interactive' | trim }}"
become_method: "{{ 'sudo' | trim }}"
become_user: "{{ 'mitogen__pw_required' | trim }}"
vars:
ansible_become_pass: "{{ 'pw_required_password' | trim }}"
Expand All @@ -60,6 +63,7 @@
become: true
become_exe: "{{ 'sudo' | trim }}"
become_flags: "{{ '--set-home --stdin --non-interactive' | trim }}"
become_method: "{{ 'sudo' | trim }}"
become_user: "{{ 'mitogen__pw_required' | trim }}"
delegate_to: "{{ groups.tt_become_bare[0] }}"
vars:
Expand Down
1 change: 1 addition & 0 deletions tests/ansible/templates/test-targets.j2
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ ansible_user=mitogen__has_sudo_nopw
[tt_become_by_inv]
tt-become-exe ansible_become=true ansible_become_exe="{{ '{{' }} 'sudo' | trim {{ '}}' }}" ansible_become_user=root
tt-become-flags ansible_become=true ansible_become_flags="{{ '{{' }} '--set-home --stdin --non-interactive' | trim {{ '}}' }}" ansible_become_user=root
tt-become-method ansible_become=true ansible_become_method="{{ '{{' }} 'sudo' | trim {{ '}}' }}" ansible_become_user=root
tt-become-pass ansible_become=true ansible_become_pass="{{ '{{' }} 'pw_required_password' | trim {{ '}}' }}" ansible_become_user=mitogen__pw_required
tt-become-user ansible_become=true ansible_become_user="{{ '{{' }} 'root' | trim {{ '}}' }}"

Expand Down

0 comments on commit 8e64459

Please sign in to comment.