ansible: support su become method.

pull/242/head
David Wilson 7 years ago
parent 3322eaef45
commit 78c401ba4d

@ -131,6 +131,20 @@ def _connect_setns(spec):
} }
def _connect_su(spec):
return {
'method': 'su',
'enable_lru': True,
'kwargs': {
'username': spec['become_user'],
'password': spec['become_pass'],
'python_path': spec['python_path'],
'su_path': spec['become_exe'],
'connect_timeout': spec['timeout'],
}
}
def _connect_sudo(spec): def _connect_sudo(spec):
return { return {
'method': 'sudo', 'method': 'sudo',
@ -146,6 +160,20 @@ def _connect_sudo(spec):
} }
def _connect_mitogen_su(spec):
# su as a first-class proxied connection, not a become method.
return {
'method': 'su',
'kwargs': {
'username': spec['remote_user'],
'password': spec['password'],
'python_path': spec['python_path'],
'su_path': spec['become_exe'],
'connect_timeout': spec['timeout'],
}
}
def _connect_mitogen_sudo(spec): def _connect_mitogen_sudo(spec):
# sudo as a first-class proxied connection, not a become method. # sudo as a first-class proxied connection, not a become method.
return { return {
@ -170,7 +198,9 @@ CONNECTION_METHOD = {
'machinectl': _connect_machinectl, 'machinectl': _connect_machinectl,
'setns': _connect_setns, 'setns': _connect_setns,
'ssh': _connect_ssh, 'ssh': _connect_ssh,
'su': _connect_su,
'sudo': _connect_sudo, 'sudo': _connect_sudo,
'mitogen_su': _connect_mitogen_su,
'mitogen_sudo': _connect_mitogen_sudo, 'mitogen_sudo': _connect_mitogen_sudo,
} }
@ -266,8 +296,8 @@ class Connection(ansible.plugins.connection.ConnectionBase):
#: target machine (i.e. via sudo). #: target machine (i.e. via sudo).
context = None context = None
#: Only sudo is supported for now. #: Only sudo and su are supported for now.
become_methods = ['sudo'] become_methods = ['sudo', 'su']
#: Set to 'ansible_python_interpreter' by on_action_run(). #: Set to 'ansible_python_interpreter' by on_action_run().
python_path = None python_path = None

@ -110,11 +110,10 @@ Installation
Noteworthy Differences Noteworthy Differences
---------------------- ----------------------
* Ansible 2.3, 2.4 and 2.5 are supported. File bugs to register interest in * Ansible 2.3, 2.4 and 2.5 are supported on Python 2.7.
older releases.
* The ``sudo`` become method is available and ``su`` is planned. File bugs to * The ``su`` and ``sudo`` become methods are available. File bugs to register
register interest in additional methods. interest in more.
* The `docker <https://docs.ansible.com/ansible/2.5/plugins/connection/docker.html>`_, * The `docker <https://docs.ansible.com/ansible/2.5/plugins/connection/docker.html>`_,
`jail <https://docs.ansible.com/ansible/2.5/plugins/connection/jail.html>`_, `jail <https://docs.ansible.com/ansible/2.5/plugins/connection/jail.html>`_,
@ -123,8 +122,9 @@ Noteworthy Differences
`lxd <https://docs.ansible.com/ansible/2.5/plugins/connection/lxd.html>`_, `lxd <https://docs.ansible.com/ansible/2.5/plugins/connection/lxd.html>`_,
and `ssh <https://docs.ansible.com/ansible/2.5/plugins/connection/ssh.html>`_ and `ssh <https://docs.ansible.com/ansible/2.5/plugins/connection/ssh.html>`_
built-in connection types are supported, along with Mitogen-specific built-in connection types are supported, along with Mitogen-specific
:ref:`machinectl <machinectl>`, :ref:`mitogen_sudo <sudo>`, and :ref:`machinectl <machinectl>`, :ref:`mitogen_su <su>`, :ref:`mitogen_sudo
:ref:`setns <setns>` types. File bugs to register interest in others. <sudo>`, and :ref:`setns <setns>` types. File bugs to register interest in
others.
* Local commands execute in a reuseable interpreter created identically to * Local commands execute in a reuseable interpreter created identically to
interpreters on targets. Presently one interpreter per ``become_user`` interpreters on targets. Presently one interpreter per ``become_user``
@ -558,6 +558,31 @@ process.
as ``/bin/machinectl``. as ``/bin/machinectl``.
.. _su:
Su
~~
Su can be used as a connection method that supports connection delegation, or
as a become method.
When used as a become method:
* ``ansible_python_interpreter``
* ``ansible_su_exe``, ``ansible_become_exe``
* ``ansible_su_user``, ``ansible_become_user`` (default: ``root``)
* ``ansible_su_pass``, ``ansible_become_pass`` (default: assume passwordless)
* ``su_flags``, ``become_flags``
* ansible.cfg: ``timeout``
When used as the ``mitogen_su`` connection method:
* The inventory hostname has no special meaning.
* ``ansible_user``: username to su as.
* ``ansible_password``: password to su as.
* ``ansible_python_interpreter``
.. _sudo: .. _sudo:
Sudo Sudo

Loading…
Cancel
Save