Skip to content

Commit 35fb7c7

Browse files
authored
fix: gather_facts requires inventory (#810) (#811)
backport #810 gather_facts requires inventory, when running as CLI it always has inventory but when run as Activation the inventory is missing. Ignore the gather_facts if no inventory is provided and print a warning message. https://issues.redhat.com/browse/AAP-47846
2 parents 0e60045 + 2f26b15 commit 35fb7c7

File tree

4 files changed

+30
-3
lines changed

4 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- Add support for playbook that has set_stats in it
88
### Fixed
99
- Fix a bug in the processing of a playbook that has a set_fact in it
10+
- Fix a bug in gather_facts. It needs inventory, else its ignored
1011

1112

1213
## [1.1.6] - 20205-04-25

ansible_rulebook/engine.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,13 @@ async def run_rulesets(
286286
rulesets = {}
287287
for ruleset, _ in ruleset_queues:
288288
if ruleset.gather_facts and not hosts_facts:
289-
hosts_facts = collect_ansible_facts(inventory)
289+
if inventory:
290+
hosts_facts = collect_ansible_facts(inventory)
291+
else:
292+
logger.warning(
293+
"Ignoring gather_facts, since it requires inventory"
294+
)
295+
290296
ruleset_names.append(ruleset.name)
291297
rulesets[ruleset.name] = ruleset
292298

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
---
2+
- name: 92 gather facts sans inventory
3+
hosts: all
4+
gather_facts: true
5+
sources:
6+
- name: range
7+
range:
8+
limit: 5
9+
rules:
10+
- name: r1
11+
condition: event.i == 1
12+
action:
13+
none:

tests/test_examples.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,16 @@ def __exit__(self, *args):
5454
self.task.cancel()
5555

5656

57+
RULEBOOK_NAMES = [
58+
("examples/01_noop.yml"),
59+
("examples/92_gather_facts_sans_inventory.yml"),
60+
]
61+
62+
63+
@pytest.mark.parametrize("rulebook", RULEBOOK_NAMES)
5764
@pytest.mark.asyncio
58-
async def test_01_noop():
59-
ruleset_queues, event_log = load_rulebook("examples/01_noop.yml")
65+
async def test_01_noop(rulebook):
66+
ruleset_queues, event_log = load_rulebook(rulebook)
6067

6168
queue = ruleset_queues[0][1]
6269
queue.put_nowait(dict(i=1))

0 commit comments

Comments
 (0)