From 1b090a6c0a4edcfe6e905343efe45ddbe2175906 Mon Sep 17 00:00:00 2001 From: David Wilson Date: Tue, 27 Feb 2018 15:41:16 +0545 Subject: [PATCH] ansible: fix become:true with sudo:true --- ansible_mitogen/connection/mitogen.py | 10 +++++++--- examples/playbook/ansible.cfg | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ansible_mitogen/connection/mitogen.py b/ansible_mitogen/connection/mitogen.py index 77de6714..a9b64f5c 100644 --- a/ansible_mitogen/connection/mitogen.py +++ b/ansible_mitogen/connection/mitogen.py @@ -28,6 +28,7 @@ from __future__ import absolute_import import logging import os +import sys import time import ansible.errors @@ -105,7 +106,7 @@ class Connection(ansible.plugins.connection.ConnectionBase): }) ) - def _connect_sudo(self, via): + def _connect_sudo(self, via=None, python_path=None): """ Fetch a reference to a sudo Context matching the play context from ContextService in the master process. @@ -118,7 +119,7 @@ class Connection(ansible.plugins.connection.ConnectionBase): 'method': 'sudo', 'username': self._play_context.become_user, 'password': self._play_context.password, - 'python_path': '/usr/bin/python', + 'python_path': python_path or '/usr/bin/python', 'via': via, })) @@ -140,7 +141,10 @@ class Connection(ansible.plugins.connection.ConnectionBase): self.router, self.parent = mitogen.unix.connect(path) if self.original_transport == 'local': - self.context = self._connect_local() + if not self._play_context.become: + self.context = self._connect_local() + else: + self.context = self._connect_sudo(python_path=sys.executable) else: self.host = self._connect_ssh() if not self._play_context.become: diff --git a/examples/playbook/ansible.cfg b/examples/playbook/ansible.cfg index b8db9596..24867260 100644 --- a/examples/playbook/ansible.cfg +++ b/examples/playbook/ansible.cfg @@ -1,7 +1,6 @@ [defaults] inventory = hosts strategy_plugins = ../../ansible_mitogen/strategy -strategy = mitogen retry_files_enabled = False [ssh_connection]