|
|
@ -213,6 +213,12 @@ class Spec(with_metaclass(abc.ABCMeta, object)):
|
|
|
|
:data:`True` if privilege escalation should be active.
|
|
|
|
:data:`True` if privilege escalation should be active.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
|
|
|
|
def become_flags(self):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
The command line arguments passed to the become executable.
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
@abc.abstractmethod
|
|
|
|
def become_method(self):
|
|
|
|
def become_method(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -290,10 +296,9 @@ class Spec(with_metaclass(abc.ABCMeta, object)):
|
|
|
|
@abc.abstractmethod
|
|
|
|
@abc.abstractmethod
|
|
|
|
def sudo_args(self):
|
|
|
|
def sudo_args(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
The list of additional arguments that should be included in a become
|
|
|
|
The list of additional arguments that should be included in a sudo
|
|
|
|
invocation.
|
|
|
|
invocation.
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
# TODO: split out into sudo_args/become_args.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@abc.abstractmethod
|
|
|
|
@abc.abstractmethod
|
|
|
|
def mitogen_via(self):
|
|
|
|
def mitogen_via(self):
|
|
|
@ -419,7 +424,29 @@ class PlayContextSpec(Spec):
|
|
|
|
|
|
|
|
|
|
|
|
def _become_option(self, name):
|
|
|
|
def _become_option(self, name):
|
|
|
|
plugin = self._connection.become
|
|
|
|
plugin = self._connection.become
|
|
|
|
|
|
|
|
try:
|
|
|
|
return plugin.get_option(name, self._task_vars, self._play_context)
|
|
|
|
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',
|
|
|
|
|
|
|
|
'become_flags',
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
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:
|
|
|
@ -443,6 +470,9 @@ class PlayContextSpec(Spec):
|
|
|
|
def become(self):
|
|
|
|
def become(self):
|
|
|
|
return self._connection.become
|
|
|
|
return self._connection.become
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def become_flags(self):
|
|
|
|
|
|
|
|
return self._become_option('become_flags')
|
|
|
|
|
|
|
|
|
|
|
|
def become_method(self):
|
|
|
|
def become_method(self):
|
|
|
|
return self._play_context.become_method
|
|
|
|
return self._play_context.become_method
|
|
|
|
|
|
|
|
|
|
|
@ -481,7 +511,7 @@ class PlayContextSpec(Spec):
|
|
|
|
return self._play_context.private_key_file
|
|
|
|
return self._play_context.private_key_file
|
|
|
|
|
|
|
|
|
|
|
|
def ssh_executable(self):
|
|
|
|
def ssh_executable(self):
|
|
|
|
return C.config.get_config_value("ssh_executable", plugin_type="connection", plugin_name="ssh", variables=self._task_vars.get("vars", {}))
|
|
|
|
return self._connection_option('ssh_executable')
|
|
|
|
|
|
|
|
|
|
|
|
def timeout(self):
|
|
|
|
def timeout(self):
|
|
|
|
return self._play_context.timeout
|
|
|
|
return self._play_context.timeout
|
|
|
@ -505,30 +535,10 @@ 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 ansible.utils.shlex.shlex_split(self.become_flags() or '')
|
|
|
|
mitogen.core.to_text(term)
|
|
|
|
|
|
|
|
for term in ansible.utils.shlex.shlex_split(
|
|
|
|
|
|
|
|
first_true((
|
|
|
|
|
|
|
|
self._play_context.become_flags,
|
|
|
|
|
|
|
|
# Ansible <=2.7.
|
|
|
|
|
|
|
|
getattr(self._play_context, 'sudo_flags', ''),
|
|
|
|
|
|
|
|
# Ansible <=2.3.
|
|
|
|
|
|
|
|
getattr(C, 'DEFAULT_BECOME_FLAGS', ''),
|
|
|
|
|
|
|
|
getattr(C, 'DEFAULT_SUDO_FLAGS', '')
|
|
|
|
|
|
|
|
), default='')
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def mitogen_via(self):
|
|
|
|
def mitogen_via(self):
|
|
|
|
return self._connection.get_task_var('mitogen_via')
|
|
|
|
return self._connection.get_task_var('mitogen_via')
|
|
|
@ -663,6 +673,9 @@ class MitogenViaSpec(Spec):
|
|
|
|
def become(self):
|
|
|
|
def become(self):
|
|
|
|
return bool(self._become_user)
|
|
|
|
return bool(self._become_user)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def become_flags(self):
|
|
|
|
|
|
|
|
return self._host_vars.get('ansible_become_flags')
|
|
|
|
|
|
|
|
|
|
|
|
def become_method(self):
|
|
|
|
def become_method(self):
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
self._become_method or
|
|
|
|
self._become_method or
|
|
|
@ -758,7 +771,7 @@ class MitogenViaSpec(Spec):
|
|
|
|
mitogen.core.to_text(term)
|
|
|
|
mitogen.core.to_text(term)
|
|
|
|
for s in (
|
|
|
|
for s in (
|
|
|
|
self._host_vars.get('ansible_sudo_flags') or '',
|
|
|
|
self._host_vars.get('ansible_sudo_flags') or '',
|
|
|
|
self._host_vars.get('ansible_become_flags') or '',
|
|
|
|
self.become_flags() or '',
|
|
|
|
)
|
|
|
|
)
|
|
|
|
for term in ansible.utils.shlex.shlex_split(s)
|
|
|
|
for term in ansible.utils.shlex.shlex_split(s)
|
|
|
|
]
|
|
|
|
]
|
|
|
|