From 17b4b1f85caed19c6f42d5dfbb9e816d480f80f8 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Tue, 18 Aug 2015 03:17:58 -0400 Subject: [PATCH] added ability to limit in ansilbe pull refactored the options a bit, new inventory_opts made sense to always group fixes #7917 --- lib/ansible/cli/__init__.py | 15 +++++++-------- lib/ansible/cli/adhoc.py | 1 + lib/ansible/cli/playbook.py | 2 +- lib/ansible/cli/pull.py | 3 +++ 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/ansible/cli/__init__.py b/lib/ansible/cli/__init__.py index eaeccf14584..0308cbedd21 100644 --- a/lib/ansible/cli/__init__.py +++ b/lib/ansible/cli/__init__.py @@ -221,7 +221,7 @@ class CLI(object): @staticmethod def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False, runtask_opts=False, vault_opts=False, - async_opts=False, connect_opts=False, subset_opts=False, check_opts=False, diff_opts=False, epilog=None, fork_opts=False): + async_opts=False, connect_opts=False, subset_opts=False, check_opts=False, inventory_opts=False, epilog=None, fork_opts=False): ''' create an options parser for most ansible scripts ''' #FIXME: implemente epilog parsing @@ -232,12 +232,16 @@ class CLI(object): parser.add_option('-v','--verbose', dest='verbosity', default=0, action="count", help="verbose mode (-vvv for more, -vvvv to enable connection debugging)") - if runtask_opts: + if inventory_opts: parser.add_option('-i', '--inventory-file', dest='inventory', help="specify inventory host file (default=%s)" % C.DEFAULT_HOST_LIST, default=C.DEFAULT_HOST_LIST, action="callback", callback=CLI.expand_tilde, type=str) parser.add_option('--list-hosts', dest='listhosts', action='store_true', help='outputs a list of matching hosts; does not execute anything else') + parser.add_option('-l', '--limit', default=C.DEFAULT_SUBSET, dest='subset', + help='further limit selected hosts to an additional pattern') + + if runtask_opts: parser.add_option('-M', '--module-path', dest='module_path', help="specify path(s) to module library (default=%s)" % C.DEFAULT_MODULE_PATH, default=None, action="callback", callback=CLI.expand_tilde, type=str) @@ -247,8 +251,6 @@ class CLI(object): if fork_opts: parser.add_option('-f','--forks', dest='forks', default=C.DEFAULT_FORKS, type='int', help="specify number of parallel processes to use (default=%s)" % C.DEFAULT_FORKS) - parser.add_option('-l', '--limit', default=C.DEFAULT_SUBSET, dest='subset', - help='further limit selected hosts to an additional pattern') if vault_opts: parser.add_option('--ask-vault-pass', default=False, dest='ask_vault_pass', action='store_true', @@ -318,11 +320,8 @@ class CLI(object): help="don't make any changes; instead, try to predict some of the changes that may occur") parser.add_option('--syntax-check', dest='syntax', action='store_true', help="perform a syntax check on the playbook, but do not execute it") - - if diff_opts: parser.add_option("-D", "--diff", default=False, dest='diff', action='store_true', - help="when changing (small) files and templates, show the differences in those files; works great with --check" - ) + help="when changing (small) files and templates, show the differences in those files; works great with --check") if meta_opts: parser.add_option('--force-handlers', default=C.DEFAULT_FORCE_HANDLERS, dest='force_handlers', action='store_true', diff --git a/lib/ansible/cli/adhoc.py b/lib/ansible/cli/adhoc.py index 828c6f89706..58180e3ccd5 100644 --- a/lib/ansible/cli/adhoc.py +++ b/lib/ansible/cli/adhoc.py @@ -38,6 +38,7 @@ class AdHocCLI(CLI): self.parser = CLI.base_parser( usage='%prog [options]', runas_opts=True, + inventory_opts=True, async_opts=True, output_opts=True, connect_opts=True, diff --git a/lib/ansible/cli/playbook.py b/lib/ansible/cli/playbook.py index 1ccec43faac..156477ddb0d 100644 --- a/lib/ansible/cli/playbook.py +++ b/lib/ansible/cli/playbook.py @@ -44,7 +44,7 @@ class PlaybookCLI(CLI): runas_opts=True, subset_opts=True, check_opts=True, - diff_opts=True, + inventory_opts=True, runtask_opts=True, vault_opts=True, fork_opts=True, diff --git a/lib/ansible/cli/pull.py b/lib/ansible/cli/pull.py index bf3aaf7e828..cef9dfd9db5 100644 --- a/lib/ansible/cli/pull.py +++ b/lib/ansible/cli/pull.py @@ -52,6 +52,7 @@ class PullCLI(CLI): vault_opts=True, runtask_opts=True, subset_opts=True, + inventory_opts=True, ) # options unique to pull @@ -182,6 +183,8 @@ class PullCLI(CLI): cmd += ' -K' if self.options.tags: cmd += ' -t "%s"' % self.options.tags + if self.options.limit: + cmd += ' -l "%s"' % self.options.limit os.chdir(self.options.dest)