Skip to content

Commit

Permalink
issue #477: fix sudo_args selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
dw committed Jan 27, 2019
1 parent 9aff8ed commit e7fe95a
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions ansible_mitogen/transport_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ def optional_secret(value):
return mitogen.core.Secret(value)


def first_true(it, default=None):
"""
Return the first truthy element from `it`.
"""
for elem in it:
if elem:
return elem
return default


class Spec(with_metaclass(abc.ABCMeta, object)):
"""
A source for variables that comprise a connection configuration.
Expand Down Expand Up @@ -350,15 +360,15 @@ def become_exe(self):
def sudo_args(self):
return [
mitogen.core.to_text(term)
for s in (
self._play_context.sudo_flags,
self._play_context.become_flags,
# Ansible 2.3.
getattr(C, 'DEFAULT_BECOME_FLAGS', ''),
getattr(C, 'DEFAULT_SUDO_FLAGS', ''),

for term in ansible.utils.shlex.shlex_split(
first_true((
self._play_context.become_flags,
self._play_context.sudo_flags,
# Ansible 2.3.
getattr(C, 'DEFAULT_BECOME_FLAGS', ''),
getattr(C, 'DEFAULT_SUDO_FLAGS', '')
), default='')
)
for term in ansible.utils.shlex.shlex_split(s or '')
]

def mitogen_via(self):
Expand Down

0 comments on commit e7fe95a

Please sign in to comment.