Browse code

fixed pull's ansible/git invocation options (#30938)

* fixed ansible/git invocation options

now falls back to using localhost as 'all' does not include implicit accidentally anymore

fixes #30636

(cherry picked from commit fc745920c74f52e0ee6705808c01f8bdd4bed1cb)

Brian Coca authored on 2017/09/28 08:50:36
Showing 2 changed files
... ...
@@ -53,6 +53,7 @@ Ansible Changes By Release
53 53
 * fixed typo and missed include/import conversion in import_tasks docs
54 54
 * updated porting docs with note about inventory_dir
55 55
 * removed extension requirement for yaml inventory plugin to restore previous behaviour
56
+* fixed ansible-pull to now correctly deal with inventory
56 57
 
57 58
 <sdfasdfsadfsdflkjsdfklj3oiqrua id="2.4"></a>
58 59
 
... ...
@@ -67,6 +67,21 @@ class PullCLI(CLI):
67 67
                                  "look for a playbook based on the host's fully-qualified domain name,"
68 68
                                  'on the host hostname and finally a playbook named *local.yml*.', }
69 69
 
70
+    def _get_inv_cli(self):
71
+
72
+        inv_opts = ''
73
+        if getattr(self.options, 'inventory'):
74
+            for inv in self.options.inventory:
75
+                if isinstance(inv, list):
76
+                    inv_opts += " -i '%s' " % ','.join(inv)
77
+                elif ',' in inv or os.path.exists(inv):
78
+                    inv_opts += ' -i %s ' % inv
79
+
80
+        if not inv_opts:
81
+            inv_opts = " -i localhost, "
82
+
83
+        return inv_opts
84
+
70 85
     def parse(self):
71 86
         ''' create an options parser for bin/ansible '''
72 87
 
... ...
@@ -158,15 +173,7 @@ class PullCLI(CLI):
158 158
 
159 159
         # Attempt to use the inventory passed in as an argument
160 160
         # It might not yet have been downloaded so use localhost as default
161
-        inv_opts = ''
162
-        if getattr(self.options, 'inventory'):
163
-            for inv in self.options.inventory:
164
-                if isinstance(inv, list):
165
-                    inv_opts += " -i '%s' " % ','.join(inv)
166
-                elif ',' in inv or os.path.exists(inv):
167
-                    inv_opts += ' -i %s ' % inv
168
-        else:
169
-            inv_opts = "-i 'localhost,'"
161
+        inv_opts = self._get_inv_cli()
170 162
 
171 163
         # FIXME: enable more repo modules hg/svn?
172 164
         if self.options.module_name == 'git':
... ...
@@ -231,8 +238,7 @@ class PullCLI(CLI):
231 231
         if self.options.vault_password_files:
232 232
             for vault_password_file in self.options.vault_password_files:
233 233
                 cmd += " --vault-password-file=%s" % vault_password_file
234
-        if inv_opts:
235
-            cmd += ' %s' % inv_opts
234
+
236 235
         for ev in self.options.extra_vars:
237 236
             cmd += ' -e "%s"' % ev
238 237
         if self.options.ask_sudo_pass or self.options.ask_su_pass or self.options.become_ask_pass:
... ...
@@ -250,6 +256,11 @@ class PullCLI(CLI):
250 250
 
251 251
         os.chdir(self.options.dest)
252 252
 
253
+        # redo inventory options as new files might exist now
254
+        inv_opts = self._get_inv_cli()
255
+        if inv_opts:
256
+            cmd += inv_opts
257
+
253 258
         # RUN THE PLAYBOOK COMMAND
254 259
         display.debug("running ansible-playbook to do actual work")
255 260
         display.debug('EXEC: %s' % cmd)