Merge pull request #1172 from moreati/issue1083-become_exe

ansible_mitogen: Support templated become_exe option
pull/1174/head
Alex Willmer 4 weeks ago committed by GitHub
commit 04f7b7a282
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -419,7 +419,28 @@ class PlayContextSpec(Spec):
def _become_option(self, name): def _become_option(self, name):
plugin = self._connection.become plugin = self._connection.become
return plugin.get_option(name, self._task_vars, self._play_context) try:
return plugin.get_option(name, self._task_vars, self._play_context)
except AttributeError:
# A few ansible_mitogen connection plugins look more like become
# plugins. They don't quite fit Ansible's plugin.get_option() API.
# https://github.com/mitogen-hq/mitogen/issues/1173
fallback_plugins = {'mitogen_doas', 'mitogen_sudo', 'mitogen_su'}
if self._connection.transport not in fallback_plugins:
raise
fallback_options = {
'become_exe',
}
if name not in fallback_options:
raise
LOG.info(
'Used PlayContext fallback for plugin=%r, option=%r',
self._connection, name,
)
return getattr(self._play_context, name)
def _connection_option(self, name): def _connection_option(self, name):
try: try:
@ -505,15 +526,7 @@ class PlayContextSpec(Spec):
] ]
def become_exe(self): def become_exe(self):
# In Ansible 2.8, PlayContext.become_exe always has a default value due return self._become_option('become_exe')
# to the new options mechanism. Previously it was only set if a value
# ("somewhere") had been specified for the task.
# For consistency in the tests, here we make older Ansibles behave like
# newer Ansibles.
exe = self._play_context.become_exe
if exe is None and self._play_context.become_method == 'sudo':
exe = 'sudo'
return exe
def sudo_args(self): def sudo_args(self):
return [ return [

@ -21,6 +21,8 @@ To avail of fixes in an unreleased version, please download a ZIP file
In progress (unreleased) In progress (unreleased)
------------------------ ------------------------
* :gh:issue:`1083` :mod:`ansible_mitogen`: Templated become executable
(e.g. ``become_exe``).
v0.3.15 (2024-10-28) v0.3.15 (2024-10-28)

@ -33,6 +33,7 @@ ansible_host=localhost
ansible_user="{{ lookup('pipe', 'whoami') }}" ansible_user="{{ lookup('pipe', 'whoami') }}"
[tt_become_by_inv] [tt_become_by_inv]
tt-become-exe ansible_become=true ansible_become_exe="{{ '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-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 }}" tt-become-user ansible_become=true ansible_become_user="{{ 'root' | trim }}"

@ -12,6 +12,7 @@
- name: Templated become in inventory - name: Templated become in inventory
vars: vars:
expected_become_users: expected_become_users:
tt-become-exe: root
tt-become-pass: mitogen__pw_required tt-become-pass: mitogen__pw_required
tt-become-user: root tt-become-user: root
command: command:

@ -2,6 +2,7 @@
hosts: tt_become_bare hosts: tt_become_bare
gather_facts: false gather_facts: false
become: true become: true
become_exe: "{{ 'sudo' | trim }}"
become_user: "{{ 'root' | trim }}" become_user: "{{ 'root' | trim }}"
tasks: tasks:
- meta: reset_connection - meta: reset_connection
@ -20,6 +21,7 @@
hosts: tt_become_bare hosts: tt_become_bare
gather_facts: false gather_facts: false
become: true become: true
become_exe: "{{ 'sudo' | trim }}"
become_user: "{{ 'mitogen__pw_required' | trim }}" become_user: "{{ 'mitogen__pw_required' | trim }}"
vars: vars:
ansible_become_pass: "{{ 'pw_required_password' | trim }}" ansible_become_pass: "{{ 'pw_required_password' | trim }}"

@ -3,6 +3,7 @@
gather_facts: false gather_facts: false
vars: vars:
ansible_become: true ansible_become: true
ansible_become_exe: "{{ 'sudo' | trim }}"
ansible_become_user: "{{ 'root' | trim }}" ansible_become_user: "{{ 'root' | trim }}"
tasks: tasks:
- name: Templated become by play vars, no password - name: Templated become by play vars, no password
@ -20,6 +21,7 @@
gather_facts: false gather_facts: false
vars: vars:
ansible_become: true ansible_become: true
ansible_become_exe: "{{ 'sudo' | trim }}"
ansible_become_pass: "{{ 'pw_required_password' | trim }}" ansible_become_pass: "{{ 'pw_required_password' | trim }}"
ansible_become_user: "{{ 'mitogen__pw_required' | trim }}" ansible_become_user: "{{ 'mitogen__pw_required' | trim }}"
tasks: tasks:

@ -4,6 +4,7 @@
# FIXME Resetting the connection shouldn't require credentials # FIXME Resetting the connection shouldn't require credentials
# https://github.com/mitogen-hq/mitogen/issues/1132 # https://github.com/mitogen-hq/mitogen/issues/1132
become: true become: true
become_exe: "{{ 'sudo' | trim }}"
become_user: "{{ 'root' | trim }}" become_user: "{{ 'root' | trim }}"
tasks: tasks:
- name: Reset connection to target that will be delegate_to - name: Reset connection to target that will be delegate_to
@ -15,6 +16,7 @@
tasks: tasks:
- name: Templated become by task keywords, with delegate_to - name: Templated become by task keywords, with delegate_to
become: true become: true
become_exe: "{{ 'sudo' | trim }}"
become_user: "{{ 'root' | trim }}" become_user: "{{ 'root' | trim }}"
delegate_to: "{{ groups.tt_become_bare[0] }}" delegate_to: "{{ groups.tt_become_bare[0] }}"
command: command:
@ -33,6 +35,7 @@
# FIXME Resetting the connection shouldn't require credentials # FIXME Resetting the connection shouldn't require credentials
# https://github.com/mitogen-hq/mitogen/issues/1132 # https://github.com/mitogen-hq/mitogen/issues/1132
become: true become: true
become_exe: "{{ 'sudo' | trim }}"
become_user: "{{ 'mitogen__pw_required' | trim }}" become_user: "{{ 'mitogen__pw_required' | trim }}"
vars: vars:
ansible_become_pass: "{{ 'pw_required_password' | trim }}" ansible_become_pass: "{{ 'pw_required_password' | trim }}"
@ -52,6 +55,7 @@
- name: Templated become by task keywords, with delegate_to - name: Templated become by task keywords, with delegate_to
become: true become: true
become_exe: "{{ 'sudo' | trim }}"
become_user: "{{ 'mitogen__pw_required' | trim }}" become_user: "{{ 'mitogen__pw_required' | trim }}"
delegate_to: "{{ groups.tt_become_bare[0] }}" delegate_to: "{{ groups.tt_become_bare[0] }}"
vars: vars:

@ -58,6 +58,7 @@ ansible_python_interpreter={{ tt.python_path }}
ansible_user=mitogen__has_sudo_nopw ansible_user=mitogen__has_sudo_nopw
[tt_become_by_inv] [tt_become_by_inv]
tt-become-exe ansible_become=true ansible_become_exe="{{ '{{' }} '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-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 {{ '}}' }}" tt-become-user ansible_become=true ansible_become_user="{{ '{{' }} 'root' | trim {{ '}}' }}"

Loading…
Cancel
Save