diff options
author | Daniel Hokka Zakrisson <daniel@hozac.com> | 2012-11-27 14:42:58 +0100 |
---|---|---|
committer | Daniel Hokka Zakrisson <daniel@hozac.com> | 2012-11-27 15:24:33 +0100 |
commit | 900790af41d420565ece40e64625084f2ea54224 (patch) | |
tree | ac7ec39804be137389ad4d32b1477522bf608563 | |
parent | d703f920775e8877b1fb9e2ae750a23bcc7e9534 (diff) | |
download | ansible-900790af41d420565ece40e64625084f2ea54224.tar.gz |
Reuse inventory object created by ansible-playbook in playbook
This reduces the amount of times an inventory script has to be invoked.
-rwxr-xr-x | bin/ansible-playbook | 3 | ||||
-rw-r--r-- | lib/ansible/playbook/__init__.py | 11 |
2 files changed, 9 insertions, 5 deletions
diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 8884f986c0..2d56df2d2a 100755 --- a/bin/ansible-playbook +++ b/bin/ansible-playbook @@ -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: diff --git a/lib/ansible/playbook/__init__.py b/lib/ansible/playbook/__init__.py index 314492e7be..ec8d944f3c 100644 --- a/lib/ansible/playbook/__init__.py +++ b/lib/ansible/playbook/__init__.py @@ -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 - self.inventory = ansible.inventory.Inventory(host_list) - self.inventory.subset(subset) + 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) |