mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Reuse inventory object created by ansible-playbook in playbook
This reduces the amount of times an inventory script has to be invoked.
This commit is contained in:
parent
d703f92077
commit
900790af41
2 changed files with 9 additions and 5 deletions
|
@ -105,7 +105,7 @@ def main(args):
|
|||
pb = ansible.playbook.PlayBook(
|
||||
playbook=playbook,
|
||||
module_path=options.module_path,
|
||||
host_list=options.inventory,
|
||||
inventory=inventory,
|
||||
forks=options.forks,
|
||||
remote_user=options.remote_user,
|
||||
remote_pass=sshpass,
|
||||
|
@ -120,7 +120,6 @@ def main(args):
|
|||
extra_vars=extra_vars,
|
||||
private_key_file=options.private_key_file,
|
||||
only_tags=only_tags,
|
||||
subset=options.subset,
|
||||
)
|
||||
|
||||
if options.listhosts:
|
||||
|
|
|
@ -60,7 +60,8 @@ class PlayBook(object):
|
|||
sudo_user = C.DEFAULT_SUDO_USER,
|
||||
extra_vars = None,
|
||||
only_tags = None,
|
||||
subset = C.DEFAULT_SUBSET):
|
||||
subset = C.DEFAULT_SUBSET,
|
||||
inventory = None):
|
||||
|
||||
"""
|
||||
playbook: path to a playbook file
|
||||
|
@ -77,6 +78,7 @@ class PlayBook(object):
|
|||
runner_callbacks: more callbacks, this time for the runner API
|
||||
stats: holds aggregrate data about events occuring to each host
|
||||
sudo: if not specified per play, requests all plays use sudo mode
|
||||
inventory: can be specified instead of host_list to use a pre-existing inventory object
|
||||
"""
|
||||
|
||||
self.SETUP_CACHE = SETUP_CACHE
|
||||
|
@ -107,8 +109,11 @@ class PlayBook(object):
|
|||
self.private_key_file = private_key_file
|
||||
self.only_tags = only_tags
|
||||
|
||||
if inventory is None:
|
||||
self.inventory = ansible.inventory.Inventory(host_list)
|
||||
self.inventory.subset(subset)
|
||||
else:
|
||||
self.inventory = inventory
|
||||
|
||||
self.basedir = os.path.dirname(playbook)
|
||||
(self.playbook, self.play_basedirs) = self._load_playbook_from_file(playbook)
|
||||
|
|
Loading…
Reference in a new issue