Bug #30095
closedAnsible facts disappear immediately after role is run
Description
Cloned from https://bugzilla.redhat.com/show_bug.cgi?id=1807677
Description of problem:
Ansible facts disappear immediately after role is run
How reproducible:
Assign a role to a host, run playbook and watch the facts page. Will see a number of Ansible facts getting populated. However, as soon as the playbook is finished, all those Ansible facts disappear (except for one custom fact).
Steps to Reproduce:
Create the role:
cat tasks/main.yml --> Not working
- name: Set OS-dependent variables
include_vars: "{{ role_path }}/vars/{{ ansible_facts.os_family }}.yml"
failed_when: false
- debug:
msg: "{{ testvar }}"
cat tasks/main.yml --> Working
- name: Set OS-dependent variables
include_vars: "{{ item }}"
failed_when: false
loop:
- "{{ role_path }}/vars/{{ ansible_facts.os_family }}.yml"
cat vars/RedHat.yml
testvar: Red Hat var
Actual results:
The issue is caused by include_vars directive - but only when not using the loop directive. See both examples above, one is working fine, the other one causes all facts to be deleted from Satellite and adding that one variable/fact coming from RedHat.yml.
You should be able to observe this issue in /var/log/foreman/production.log. First non-working example, then working (look at timestamps).- grep "Import facts" production.log
2020-02-21T09:20:09 [I|app|8185609a] Import facts for 'host.example.com' completed. Added: 496, Updated: 0, Deleted 1 facts
2020-02-21T09:20:13 [I|app|a6569bb4] Import facts for 'host.example.com' completed. Added: 1, Updated: 0, Deleted 496 facts
2020-02-21T09:21:51 [I|app|e70b6bec] Import facts for 'host.example.com' completed. Added: 496, Updated: 0, Deleted 1 facts
Expected results:
Facts should not disappear
Additional info:
Updated by Ondřej Ezr almost 3 years ago
- Subject changed from Ansible facts disappear immediately after role is run to Ansible facts disappear immediately after role is run
- Status changed from New to Resolved
- Triaged changed from No to Yes
- Pull request https://github.com/theforeman/foreman-ansible-modules/pull/1155 added