1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Update playbook to be transport aware

This adds transport variable to playbook.py.  It can be set with
'connection' in the playbook file.
This commit is contained in:
Stephen Fromm 2012-04-11 09:39:04 -07:00
parent b506567c37
commit 40fc9a3249

View file

@ -55,6 +55,7 @@ class PlayBook(object):
remote_user = C.DEFAULT_REMOTE_USER, remote_user = C.DEFAULT_REMOTE_USER,
remote_pass = C.DEFAULT_REMOTE_PASS, remote_pass = C.DEFAULT_REMOTE_PASS,
remote_port = C.DEFAULT_REMOTE_PORT, remote_port = C.DEFAULT_REMOTE_PORT,
transport = C.DEFAULT_TRANSPORT,
override_hosts = None, override_hosts = None,
extra_vars = None, extra_vars = None,
debug = False, debug = False,
@ -73,6 +74,7 @@ class PlayBook(object):
self.remote_user = remote_user self.remote_user = remote_user
self.remote_pass = remote_pass self.remote_pass = remote_pass
self.remote_port = remote_port self.remote_port = remote_port
self.transport = transport
self.debug = debug self.debug = debug
self.verbose = verbose self.verbose = verbose
self.callbacks = callbacks self.callbacks = callbacks
@ -272,7 +274,7 @@ class PlayBook(object):
# ***************************************************** # *****************************************************
def _run_module(self, pattern, host_list, module, args, vars, remote_user, def _run_module(self, pattern, host_list, module, args, vars, remote_user,
async_seconds, async_poll_interval, only_if, sudo): async_seconds, async_poll_interval, only_if, sudo, transport):
''' run a particular module step in a playbook ''' ''' 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)] hosts = [ h for h in host_list if (h not in self.stats.failures) and (h not in self.stats.dark)]
@ -285,7 +287,8 @@ class PlayBook(object):
remote_port=self.remote_port, module_vars=vars, remote_port=self.remote_port, module_vars=vars,
setup_cache=SETUP_CACHE, basedir=self.basedir, setup_cache=SETUP_CACHE, basedir=self.basedir,
conditional=only_if, callbacks=self.runner_callbacks, conditional=only_if, callbacks=self.runner_callbacks,
extra_vars=self.extra_vars, debug=self.debug, sudo=sudo extra_vars=self.extra_vars, debug=self.debug, sudo=sudo,
transport=transport
) )
if async_seconds == 0: if async_seconds == 0:
@ -296,7 +299,7 @@ class PlayBook(object):
# ***************************************************** # *****************************************************
def _run_task(self, pattern=None, host_list=None, task=None, def _run_task(self, pattern=None, host_list=None, task=None,
remote_user=None, handlers=None, conditional=False, sudo=False): remote_user=None, handlers=None, conditional=False, sudo=False, transport=None):
''' run a single task in the playbook and recursively run any subtasks. ''' ''' run a single task in the playbook and recursively run any subtasks. '''
# load the module name and parameters from the task entry # load the module name and parameters from the task entry
@ -328,7 +331,7 @@ class PlayBook(object):
# run the task in parallel # run the task in parallel
results = self._run_module(pattern, host_list, module_name, results = self._run_module(pattern, host_list, module_name,
module_args, module_vars, remote_user, async_seconds, module_args, module_vars, remote_user, async_seconds,
async_poll_interval, only_if, sudo) async_poll_interval, only_if, sudo, transport)
self.stats.compute(results) self.stats.compute(results)
@ -423,7 +426,7 @@ class PlayBook(object):
# ***************************************************** # *****************************************************
def _do_setup_step(self, pattern, vars, user, port, sudo, vars_files=None): def _do_setup_step(self, pattern, vars, user, port, sudo, transport, vars_files=None):
''' push variables down to the systems and get variables+facts back up ''' ''' push variables down to the systems and get variables+facts back up '''
# this enables conditional includes like $facter_os.yml and is only done # this enables conditional includes like $facter_os.yml and is only done
@ -454,6 +457,7 @@ class PlayBook(object):
remote_pass=self.remote_pass, remote_port=self.remote_port, remote_pass=self.remote_pass, remote_port=self.remote_port,
setup_cache=SETUP_CACHE, setup_cache=SETUP_CACHE,
callbacks=self.runner_callbacks, sudo=sudo, callbacks=self.runner_callbacks, sudo=sudo,
transport=transport,
).run() ).run()
self.stats.compute(setup_results, setup=True) self.stats.compute(setup_results, setup=True)
@ -493,15 +497,16 @@ class PlayBook(object):
user = pg.get('user', self.remote_user) user = pg.get('user', self.remote_user)
port = pg.get('port', self.remote_port) port = pg.get('port', self.remote_port)
sudo = pg.get('sudo', False) sudo = pg.get('sudo', False)
transport = pg.get('connection', self.transport)
self.callbacks.on_play_start(pattern) self.callbacks.on_play_start(pattern)
# push any variables down to the system # and get facts/ohai/other data back up # push any variables down to the system # and get facts/ohai/other data back up
self._do_setup_step(pattern, vars, user, port, sudo, None) self._do_setup_step(pattern, vars, user, port, sudo, transport, None)
# now with that data, handle contentional variable file imports! # now with that data, handle contentional variable file imports!
if len(vars_files) > 0: if len(vars_files) > 0:
self._do_setup_step(pattern, vars, user, port, sudo, vars_files) self._do_setup_step(pattern, vars, user, port, sudo, transport, vars_files)
# run all the top level tasks, these get run on every node # run all the top level tasks, these get run on every node
for task in tasks: for task in tasks:
@ -511,7 +516,8 @@ class PlayBook(object):
task=task, task=task,
handlers=handlers, handlers=handlers,
remote_user=user, remote_user=user,
sudo=sudo sudo=sudo,
transport=transport
) )
# handlers only run on certain nodes, they are flagged by _flag_handlers # handlers only run on certain nodes, they are flagged by _flag_handlers
@ -530,7 +536,8 @@ class PlayBook(object):
host_list=triggered_by, host_list=triggered_by,
conditional=True, conditional=True,
remote_user=user, remote_user=user,
sudo=sudo sudo=sudo,
transport=transport
) )
# end of execution for this particular pattern. Multiple patterns # end of execution for this particular pattern. Multiple patterns