Ok, got this working in the latest git:
Usage (as your user account)
$ ansible all -m service -a “name=httpd state=restarted” -u username --sudo # or -s
From a playbook, just add a sudo: True bit and change the user line:
user: username
sudo: True
The implementation is… creative.
Rather than deal with paramiko input and output streams over a pty/shell, which is … well, words I cannot use on a public mailing list how
complicated … I am redirecting all output to a file, and then moving the file once the command execution is complete, and then using SFTP to wait until
the “complete” file actually exists rather than rely on paramiko’s broken “exit code ready” logic and so forth. It’s dark magic, but it seems to work
fine. Hopefully that’s true of everyone’s distributions. I’ll say it’s not super efficient now because it hammers the system saying "is it done yet, is it
done yet, every 1 second. We could probably do some exponential back off if needed… as well as come up with a sane maximum timeout value
after which we could rule the command dead… but I didn’t want to make yet another timeout parameter for that, and using the SSH timeout variable
wouldn’t be right, and it’s not an async thing either.
Anyway, should work fine…
Please help test and let me know.
Thanks!
–Michael
My playbook is hanging at the setup phase. Here’s a snippet from my TB after Ctrl-C:
Process Process-4:
Traceback (most recent call last):
File “/usr/lib/python2.7/multiprocessing/process.py”, line 258, in _bootstrap
self.run()
File “/usr/lib/python2.7/multiprocessing/process.py”, line 114, in run
self._target(*self._args, **self._kwargs)
File “/home/matthew/overlord/lib/ve/local/lib/python2.7/site-packages/ansible/runner.py”, line 55, in _executor_hook
while not job_queue.empty():
File “”, line 2, in empty
File “/usr/lib/python2.7/multiprocessing/managers.py”, line 755, in _callmethod
self._connect()
File “/usr/lib/python2.7/multiprocessing/managers.py”, line 742, in _connect
conn = self._Client(self._token.address, authkey=self._authkey)
File “/usr/lib/python2.7/multiprocessing/connection.py”, line 169, in Client
c = SocketClient(address)
File “/usr/lib/python2.7/multiprocessing/connection.py”, line 289, in SocketClient
s.connect(address)
File “/usr/lib/python2.7/socket.py”, line 224, in meth
return getattr(self._sock,name)(*args)
error: [Errno 2] No such file or directory
(This is on Ubuntu Oneiric (11.10))
Unfortunately control-C messages are just that, control-C messages.
They don't tell you anything and if I could hide them, I would,
because they
aren't really errors. You'd get them anyway from any control-C.
Run with "-T 5" for a really short SSH timeout.... it may be you have
some legitimate host connections that need to timeout, such as host
names that are offline
or mis-entered.
Currently the code will also wait for the command to complete
indefinitely, so you MIGHT be seeing that, i.e. command never wrote
a result file because the module died. Adding some debug in
connection.py to print the result_file path and looking for the
result_file+"_pre" file and seeing if anything is in it may be
worthwhile in that case -- my setup module works fine over sudo.