diff --git a/plugins/connection/ssh.py b/plugins/connection/ssh.py index b5622aab..3742e3f3 100644 --- a/plugins/connection/ssh.py +++ b/plugins/connection/ssh.py @@ -376,15 +376,13 @@ class Connection(SSH.Connection): # to a command etc... It's somewhat ugly but maybe it can be # improved somehow... _pad = 'lxc-attach --clear-env --name %s' % self.container_name - cmd = '%s -- su - %s -c %s' % ( + cmd = '%s %s -- su - %s -c %s' % ( + self._play_context.become_method, _pad, self.container_user, shlex_quote(cmd) ) - if self._play_context.become: - cmd = ' '.join((self._play_context.become_method, cmd)) - return super(Connection, self).exec_command(cmd, in_data, sudoable) def _container_check(self): diff --git a/tests/host_vars/localhost.yml b/tests/host_vars/localhost.yml index 3dcf60b8..deedd6f9 100644 --- a/tests/host_vars/localhost.yml +++ b/tests/host_vars/localhost.yml @@ -15,3 +15,5 @@ bridges: - "br-mgmt" + +ansible_connection: local diff --git a/tests/test-connection-plugin.yml b/tests/test-connection-plugin.yml index facf185a..7cc82e04 100644 --- a/tests/test-connection-plugin.yml +++ b/tests/test-connection-plugin.yml @@ -91,6 +91,7 @@ command: whoami vars: container_user: testing + ansible_become: False register: whoami_output changed_when: false failed_when: