Commit 6e7bb4fd authored by David Wilson's avatar David Wilson

ansible: support local connections too

parent 71a6b9e3
...@@ -47,14 +47,13 @@ class Connection(ansible.plugins.connection.ConnectionBase): ...@@ -47,14 +47,13 @@ class Connection(ansible.plugins.connection.ConnectionBase):
def connected(self): def connected(self):
return self.router is not None return self.router is not None
def _connect(self): def _connect_local(self):
if self.connected: return mitogen.service.call(self.parent, 500, {
return 'method': 'local',
}
path = os.environ['LISTENER_SOCKET_PATH']
self.router, self.parent = mitogen.unix.connect(path)
host = mitogen.service.call(self.parent, 500, cast({ def _connect_ssh(self):
return mitogen.service.call(self.parent, 500, cast({
'method': 'ssh', 'method': 'ssh',
'hostname': self._play_context.remote_addr, 'hostname': self._play_context.remote_addr,
'username': self._play_context.remote_user, 'username': self._play_context.remote_user,
...@@ -64,18 +63,33 @@ class Connection(ansible.plugins.connection.ConnectionBase): ...@@ -64,18 +63,33 @@ class Connection(ansible.plugins.connection.ConnectionBase):
'ssh_path': self._play_context.ssh_executable, 'ssh_path': self._play_context.ssh_executable,
})) }))
if not self._play_context.become: def _connect_sudo(self, via):
self.context = host return mitogen.service.call(self.parent, 500, cast({
else:
self.context = mitogen.service.call(self.parent, 500, cast({
'method': 'sudo', 'method': 'sudo',
'username': self._play_context.become_user, 'username': self._play_context.become_user,
'password': self._play_context.password, 'password': self._play_context.password,
'python_path': '/usr/bin/python', 'python_path': '/usr/bin/python',
'via': host, 'via': via,
'debug': True, 'debug': True,
})) }))
def _connect(self):
if self.connected:
return
path = os.environ['LISTENER_SOCKET_PATH']
self.router, self.parent = mitogen.unix.connect(path)
if self._play_context.connection == 'local':
host = self._connect_local()
else:
host = self._connect_ssh(self)
if not self._play_context.become:
self.context = host
else:
self.context = self._connect_sudo(via=host)
def call_async(self, func, *args, **kwargs): def call_async(self, func, *args, **kwargs):
self._connect() self._connect()
print[func, args, kwargs] print[func, args, kwargs]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment