Skip to content

Commit

Permalink
Avoid default inventory proccessing for pull (#32135)
Browse files Browse the repository at this point in the history
* Avoid default inventory proccessing for pull

- now pull's own special inventory processing should work correctly
- also removed ineffective set_defaults

fixes #31449

* use class property instead

* only do localhost for adhoc

(cherry picked from commit aad5d1432583c4aa4105b774f38c80498e85de59)
  • Loading branch information
bcoca committed Oct 25, 2017
1 parent 11153df commit ca71a50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 11 deletions.
9 changes: 4 additions & 5 deletions lib/ansible/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class CLI(with_metaclass(ABCMeta, object)):
# -F (quit-if-one-screen) -R (allow raw ansi control chars)
# -S (chop long lines) -X (disable termcap init and de-init)
LESS_OPTS = 'FRSX'
SKIP_INVENTORY_DEFAULTS = False

def __init__(self, args, callback=None):
"""
Expand Down Expand Up @@ -424,8 +425,7 @@ def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False,

if inventory_opts:
parser.add_option('-i', '--inventory', '--inventory-file', dest='inventory', action="append",
help="specify inventory host path (default=[%s]) or comma separated host list. "
"--inventory-file is deprecated" % C.DEFAULT_HOST_LIST)
help="specify inventory host path or comma separated host list. --inventory-file is deprecated")
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',
Expand Down Expand Up @@ -605,8 +605,8 @@ def parse(self):
skip_tags.add(tag.strip())
self.options.skip_tags = list(skip_tags)

# process inventory options
if hasattr(self.options, 'inventory'):
# process inventory options except for CLIs that require their own processing
if hasattr(self.options, 'inventory') and not self.SKIP_INVENTORY_DEFAULTS:

if self.options.inventory:

Expand All @@ -616,7 +616,6 @@ def parse(self):

# Ensure full paths when needed
self.options.inventory = [unfrackpath(opt, follow=False) if ',' not in opt else opt for opt in self.options.inventory]

else:
self.options.inventory = C.DEFAULT_HOST_LIST

Expand Down
10 changes: 4 additions & 6 deletions lib/ansible/cli/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ class PullCLI(CLI):
"look for a playbook based on the host's fully-qualified domain name,"
'on the host hostname and finally a playbook named *local.yml*.', }

SKIP_INVENTORY_DEFAULTS = True

def _get_inv_cli(self):

inv_opts = ''
Expand All @@ -77,9 +79,6 @@ def _get_inv_cli(self):
elif ',' in inv or os.path.exists(inv):
inv_opts += ' -i %s ' % inv

if not inv_opts:
inv_opts = " -i localhost, "

return inv_opts

def parse(self):
Expand Down Expand Up @@ -125,9 +124,6 @@ def parse(self):
self.parser.add_option("--check", default=False, dest='check', action='store_true',
help="don't make any changes; instead, try to predict some of the changes that may occur")

# for pull we don't want a default
self.parser.set_defaults(inventory=None)

super(PullCLI, self).parse()

if not self.options.dest:
Expand Down Expand Up @@ -177,6 +173,8 @@ def run(self):
# Attempt to use the inventory passed in as an argument
# It might not yet have been downloaded so use localhost as default
inv_opts = self._get_inv_cli()
if not inv_opts:
inv_opts = " -i localhost, "

# FIXME: enable more repo modules hg/svn?
if self.options.module_name == 'git':
Expand Down

0 comments on commit ca71a50

Please sign in to comment.