mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix an issue where git-pull fails with AttributeError
As part of 94f3b9bfab
the code was changed to support dynamically adding localhost to the inventory. This change introduced an crash when run via ansible-pull
```
Starting ansible-pull at 2014-01-20 23:09:57
Traceback (most recent call last):
File "/tmp/ansible/bin/ansible", line 157, in <module>
(runner, results) = cli.run(options, args)
File "/tmp/ansible/bin/ansible", line 82, in run
hosts = inventory_manager.list_hosts(pattern)
File "/tmp/ansible/lib/ansible/inventory/__init__.py", line 372, in list_hosts
result = [ h.name for h in self.get_hosts(pattern) ]
File "/tmp/ansible/lib/ansible/inventory/__init__.py", line 136, in get_hosts
subset = self._get_hosts(self._subset)
File "/tmp/ansible/lib/ansible/inventory/__init__.py", line 177, in _get_hosts
that = self.__get_hosts(p)
File "/tmp/ansible/lib/ansible/inventory/__init__.py", line 198, in __get_hosts
hpat = self._hosts_in_unenumerated_pattern(name)
File "/tmp/ansible/lib/ansible/inventory/__init__.py", line 275, in _hosts_in_unenumerated_pattern
ungrouped.add_host(new_host)
AttributeError: 'NoneType' object has no attribute 'add_host'
```
The root cause is there is no group for the host to be added to. I fixed this case by creating the ungrouped group when it doesn't exist and then adding the host to the newly added group. This fixes the regression for me.
This commit is contained in:
parent
4b9127f0af
commit
761fe8cc04
1 changed files with 4 additions and 0 deletions
|
@ -272,6 +272,10 @@ class Inventory(object):
|
||||||
new_host.set_variable("ansible_python_interpreter", sys.executable)
|
new_host.set_variable("ansible_python_interpreter", sys.executable)
|
||||||
new_host.set_variable("ansible_connection", "local")
|
new_host.set_variable("ansible_connection", "local")
|
||||||
ungrouped = self.get_group("ungrouped")
|
ungrouped = self.get_group("ungrouped")
|
||||||
|
if ungrouped is None:
|
||||||
|
self.add_group(Group('ungrouped'))
|
||||||
|
ungrouped = self.get_group('ungrouped')
|
||||||
|
|
||||||
ungrouped.add_host(new_host)
|
ungrouped.add_host(new_host)
|
||||||
results.append(new_host)
|
results.append(new_host)
|
||||||
return results
|
return results
|
||||||
|
|
Loading…
Reference in a new issue