Sudo support operational in both playbooks and main program. Implementation could use some cleanup.

This commit is contained in:
Michael DeHaan 2012-03-29 22:58:10 -04:00
parent 81e3496037
commit 2372a3b734
4 changed files with 53 additions and 33 deletions

View file

@ -255,7 +255,7 @@ class PlayBook(object):
# *****************************************************
def _run_module(self, pattern, host_list, module, args, remote_user,
async_seconds, async_poll_interval, only_if):
async_seconds, async_poll_interval, only_if, sudo):
''' run a particular module step in a playbook '''
hosts = [ h for h in host_list if (h not in self.stats.failures) and (h not in self.stats.dark)]
@ -268,6 +268,7 @@ class PlayBook(object):
remote_port=self.remote_port,
setup_cache=SETUP_CACHE, basedir=self.basedir,
conditional=only_if, callbacks=self.runner_callbacks,
sudo=sudo
)
if async_seconds == 0:
@ -278,7 +279,7 @@ class PlayBook(object):
# *****************************************************
def _run_task(self, pattern=None, host_list=None, task=None,
remote_user=None, handlers=None, conditional=False):
remote_user=None, handlers=None, conditional=False, sudo=False):
''' run a single task in the playbook and recursively run any subtasks. '''
# load the module name and parameters from the task entry
@ -307,7 +308,7 @@ class PlayBook(object):
# run the task in parallel
results = self._run_module(pattern, host_list, module_name,
module_args, remote_user, async_seconds,
async_poll_interval, only_if)
async_poll_interval, only_if, sudo)
self.stats.compute(results)
@ -402,7 +403,7 @@ class PlayBook(object):
# *****************************************************
def _do_setup_step(self, pattern, vars, user, port, vars_files=None):
def _do_setup_step(self, pattern, vars, user, port, sudo, vars_files=None):
''' push variables down to the systems and get variables+facts back up '''
# this enables conditional includes like $facter_os.yml and is only done
@ -432,7 +433,7 @@ class PlayBook(object):
timeout=self.timeout, remote_user=user,
remote_pass=self.remote_pass, remote_port=self.remote_port,
setup_cache=SETUP_CACHE,
callbacks=self.runner_callbacks,
callbacks=self.runner_callbacks, sudo=sudo,
).run()
self.stats.compute(setup_results, setup=True)
@ -464,15 +465,16 @@ class PlayBook(object):
handlers = pg.get('handlers', [])
user = pg.get('user', C.DEFAULT_REMOTE_USER)
port = pg.get('port', C.DEFAULT_REMOTE_PORT)
sudo = pg.get('sudo', False)
self.callbacks.on_play_start(pattern)
# push any variables down to the system # and get facts/ohai/other data back up
self._do_setup_step(pattern, vars, user, port, None)
self._do_setup_step(pattern, vars, user, port, sudo, None)
# now with that data, handle contentional variable file imports!
if len(vars_files) > 0:
self._do_setup_step(pattern, vars, user, port, vars_files)
self._do_setup_step(pattern, vars, user, port, sudo, vars_files)
# run all the top level tasks, these get run on every node
for task in tasks:
@ -482,6 +484,7 @@ class PlayBook(object):
task=task,
handlers=handlers,
remote_user=user,
sudo=sudo
)
# handlers only run on certain nodes, they are flagged by _flag_handlers
@ -499,7 +502,8 @@ class PlayBook(object):
handlers=[],
host_list=triggered_by,
conditional=True,
remote_user=user
remote_user=user,
sudo=sudo
)
# end of execution for this particular pattern. Multiple patterns