diff --git a/bin/ansible-playbook b/bin/ansible-playbook index 8884f986c0a..2d56df2d2a1 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 314492e7be1..ec8d944f3cf 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)