From 3587ffdef37434f149c0ff9fdc4a950f1de1793c Mon Sep 17 00:00:00 2001 From: Michael DeHaan Date: Sat, 11 Aug 2012 14:05:24 -0400 Subject: [PATCH] Allow /bin/ansible to use --limit --- bin/ansible | 4 ++-- lib/ansible/runner/__init__.py | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/bin/ansible b/bin/ansible index 1e53aba064b..2117abd1d07 100755 --- a/bin/ansible +++ b/bin/ansible @@ -45,7 +45,7 @@ class Cli(object): def parse(self): ''' create an options parser for bin/ansible ''' - parser = utils.base_parser(constants=C, runas_opts=True, async_opts=True, + parser = utils.base_parser(constants=C, runas_opts=True, subset_opts=True, async_opts=True, output_opts=True, connect_opts=True, usage='%prog [options]') parser.add_option('-a', '--args', dest='module_args', help="module arguments", default=C.DEFAULT_MODULE_ARGS) @@ -96,7 +96,7 @@ class Cli(object): pattern=pattern, callbacks=self.callbacks, sudo=options.sudo, sudo_pass=sudopass,sudo_user=options.sudo_user, - transport=options.connection + transport=options.connection, subset=options.subset ) if options.seconds: diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py index 5462b94628c..e3379644b04 100644 --- a/lib/ansible/runner/__init__.py +++ b/lib/ansible/runner/__init__.py @@ -123,7 +123,8 @@ class Runner(object): sudo_user=C.DEFAULT_SUDO_USER, # ex: 'root' module_vars=None, # a playbooks internals thing is_playbook=False, # running from playbook or not? - inventory=None # reference to Inventory object + inventory=None, # reference to Inventory object + subset=None # subset pattern ): # storage & defaults @@ -133,6 +134,7 @@ class Runner(object): self.generated_jid = str(random.randint(0, 999999999999)) self.transport = transport self.inventory = utils.default(inventory, lambda: ansible.inventory.Inventory(host_list)) + self.module_vars = utils.default(module_vars, lambda: {}) self.sudo_user = sudo_user self.connector = connection.Connection(self) @@ -153,6 +155,10 @@ class Runner(object): self.is_playbook = is_playbook # misc housekeeping + if subset and self.inventory._subset is None: + # don't override subset when passed from playbook + self.inventory.subset(subset) + if self.transport == 'ssh' and remote_pass: raise errors.AnsibleError("SSH transport does not support passwords, only keys or agents") if self.transport == 'local':