The basic idea is sudo /bin/sh -c 'quoted_command'. We use Paramiko's low-level API to set a timeout, get a pseudo tty, execute sudo and the (shell quoted) command atomically, wait just until sudo is ready to accept the password before sending it down the pipe, and then return the command's stdout and stderr.
This should be faster, as there are no unneeded sleeps. There are no permissions issues reading the output. It will raise socket.timeout if the command takes too long. However, this is a per-read timeout, not a total execution timeout, so as long as the command is writing output and you are reading it, it will not time out.
Local and non-sudo commands remain unchanged, but should probably adopt a similar approach.
Since this is a significant change, it needs a lot of testing. Also, someone smarter than I should double-check the quoting and execution, since it is a security issue.
You still need jinja2 if using /usr/bin/ansible vs /usr/bin/ansible-playbook though
this could change later by fetching the ansible file with a 'slurp' module.
OR a per-user directory when running from playbooks. Technically this info is also available via the SETUP_CACHE
but that is a bit more complex of a construct and it would be better to not cross the streams.
See test/yaml_hosts for an example.
Hosts can be part of multiple groups.
Groups can also have variables, inherited by the hosts.
There is no variable scope, last variable seen wins.
This introduces the Inventory class.
Playbook uses the internals of Runner to limit the number of hosts to poll
asynchronously. To accomodate this, Inventory can be restricted to specific
hosts.
OR a per-user directory when running from playbooks. Technically this info is also available via the SETUP_CACHE
but that is a bit more complex of a construct and it would be better to not cross the streams.