In playbooks, each pattern stanza can reference it's own user to run as, so you can
run things as multiple sets of users (if you want) in the same playbook.
This commit is contained in:
parent
61d064d011
commit
78a254fc52
2 changed files with 12 additions and 8 deletions
|
@ -1,9 +1,6 @@
|
||||||
- pattern: '*'
|
- pattern: '*'
|
||||||
hosts: /etc/ansible/hosts
|
hosts: /etc/ansible/hosts
|
||||||
tasks:
|
tasks:
|
||||||
- do:
|
|
||||||
- restart apache for kicks
|
|
||||||
- command /sbin/service apache restart
|
|
||||||
- do:
|
- do:
|
||||||
- configure template & module variables for future template calls
|
- configure template & module variables for future template calls
|
||||||
- setup a=2 b=3 c=4
|
- setup a=2 b=3 c=4
|
||||||
|
|
|
@ -88,7 +88,8 @@ class PlayBook(object):
|
||||||
}
|
}
|
||||||
return results
|
return results
|
||||||
|
|
||||||
def _run_task(self, pattern=None, task=None, host_list=None, handlers=None, conditional=False):
|
def _run_task(self, pattern=None, task=None, host_list=None,
|
||||||
|
remote_user=None, handlers=None, conditional=False):
|
||||||
'''
|
'''
|
||||||
run a single task in the playbook and
|
run a single task in the playbook and
|
||||||
recursively run any subtasks.
|
recursively run any subtasks.
|
||||||
|
@ -115,10 +116,10 @@ class PlayBook(object):
|
||||||
module_args=module_args,
|
module_args=module_args,
|
||||||
host_list=host_list,
|
host_list=host_list,
|
||||||
forks=self.forks,
|
forks=self.forks,
|
||||||
remote_user=self.remote_user, # FIXME: read from playbook
|
|
||||||
remote_pass=self.remote_pass,
|
remote_pass=self.remote_pass,
|
||||||
module_path=self.module_path,
|
module_path=self.module_path,
|
||||||
timeout=self.timeout
|
timeout=self.timeout,
|
||||||
|
remote_user=remote_user
|
||||||
)
|
)
|
||||||
results = runner.run()
|
results = runner.run()
|
||||||
|
|
||||||
|
@ -198,6 +199,7 @@ class PlayBook(object):
|
||||||
pattern = pg['pattern']
|
pattern = pg['pattern']
|
||||||
tasks = pg['tasks']
|
tasks = pg['tasks']
|
||||||
handlers = pg['handlers']
|
handlers = pg['handlers']
|
||||||
|
user = pg.get('user', C.DEFAULT_REMOTE_USER)
|
||||||
|
|
||||||
self.host_list = pg.get('hosts', '/etc/ansible/hosts')
|
self.host_list = pg.get('hosts', '/etc/ansible/hosts')
|
||||||
|
|
||||||
|
@ -205,7 +207,11 @@ class PlayBook(object):
|
||||||
print "PLAY: [%s] from [%s] ********** " % (pattern, self.host_list)
|
print "PLAY: [%s] from [%s] ********** " % (pattern, self.host_list)
|
||||||
|
|
||||||
for task in tasks:
|
for task in tasks:
|
||||||
self._run_task(pattern=pattern, task=task, handlers=handlers)
|
self._run_task(
|
||||||
|
pattern=pattern,
|
||||||
|
task=task,
|
||||||
|
handlers=handlers,
|
||||||
|
remote_user=user)
|
||||||
for task in handlers:
|
for task in handlers:
|
||||||
if type(task.get("run", None)) == list:
|
if type(task.get("run", None)) == list:
|
||||||
self._run_task(
|
self._run_task(
|
||||||
|
@ -213,7 +219,8 @@ class PlayBook(object):
|
||||||
task=task,
|
task=task,
|
||||||
handlers=handlers,
|
handlers=handlers,
|
||||||
host_list=task.get('run',[]),
|
host_list=task.get('run',[]),
|
||||||
conditional=True
|
conditional=True,
|
||||||
|
remote_user=user
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue