Ansible facts and period update

Problem:
Not really a problem, more a question :slight_smile: We are no longer using puppet in managing our clients, only Ansible. The facts are populated when the host is deployed, no issues there. However, Puppet seemed to to some sort of “check in” every couple of hours (days?) and update the host facts. Ansible doesn’t seem to do that. Do I need to schedule an “ansible setup” job to simulate that? As all our hosts show no facts and a “last report” of the deployment date since the last ansible run.

Expected outcome:
Update the facts through ansible periodically and set “last report” to that time.

Foreman and Proxy versions:
F 3.4
K 4.6

Foreman and Proxy plugin versions:

Distribution and version:
Rocky 8

Do I need to schedule an “ansible setup” job to simulate that?

That could be the way, you can set up recurring execution of the job as you like (daily, hourly) and run some really simple playbook, I use for example this one:

---
- name: Ping Playbook
  hosts: all
  become: yes
  become_user: root
  gather_facts: true
  tasks:
    - name: Show host's hostname
      debug:
        msg: "{{ ansible_ssh_host }}"

Thank you @lstejska, I executed a job with the minimum playbook and the facts are updated fine.

However, the hosts are still all listed as “Last Report” of months ago and “Out of sync 100%”. I think I am missing something here. The only warning I see when executing the run book is:

[DEPRECATION WARNING]: [defaults]callback_whitelist option, normalizing names 
to new standard, use callbacks_enabled instead. This feature will be removed 
from ansible-core in version 2.15. Deprecation warnings can be disabled by 
setting deprecation_warnings=False in ansible.cfg.
[WARNING]: Callback disabled by environment. Disabling the Foreman callback
plugin.

Not sure if this could have anything to do with sending reports back to Foreman.

That’s an issue, it’s clearly saying that callbacks are disabled, so I would check again if facts really have been updated. On my setup running the playbook updates facts and also the last report time.

This is getting pretty weird.

I ran my ansible playbook with debug logging and found this at the top of the output:

ansible-playbook [core 2.13.3]
  config file = /usr/share/foreman-proxy/.ansible.cfg
  configured module search path = ['/usr/share/foreman-proxy/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.9/site-packages/ansible
  ansible collection location = /etc/ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible-playbook
  python version = 3.9.13 (main, Nov  8 2022, 17:21:43) [GCC 8.5.0 20210514 (Red Hat 8.5.0-15)]
  jinja version = 3.1.2
  libyaml = False
Using /usr/share/foreman-proxy/.ansible.cfg as config file
[DEPRECATION WARNING]: [defaults]callback_whitelist option, normalizing names 
to new standard, use callbacks_enabled instead. This feature will be removed 
from ansible-core in version 2.15. Deprecation warnings can be disabled by 
setting deprecation_warnings=False in ansible.cfg.
setting up inventory plugins
host_list declined parsing /tmp/d20221207-1196-589gnc/inventory/hosts as it did not pass its verify_file() method
Parsed /tmp/d20221207-1196-589gnc/inventory/hosts inventory source with script plugin
Loading callback plugin awx_display of type stdout, v2.0 from /usr/lib/python3.6/site-packages/ansible_runner/callbacks/awx_display.py
Loading collection theforeman.foreman from /usr/share/ansible/collections/ansible_collections/theforeman/foreman
Skipping callback 'awx_display', as we already have a stdout callback.
Skipping callback 'default', as we already have a stdout callback.
Skipping callback 'minimal', as we already have a stdout callback.
Skipping callback 'oneline', as we already have a stdout callback.
Loading callback plugin theforeman.foreman.foreman of type notification, v2.0 from /usr/share/ansible/collections/ansible_collections/theforeman/foreman/plugins/callback/foreman.py
[WARNING]: Callback disabled by environment. Disabling the Foreman callback
plugin.

Checking the ansible config file /usr/share/foreman-proxy/.ansible.cfg, which seems to be maintained by Foreman:

[defaults]
callback_whitelist = theforeman.foreman.foreman
local_tmp = /tmp
host_key_checking = False
stdout_callback = yaml
roles_path = /etc/ansible/roles:/usr/share/ansible/roles
collections_paths = /etc/ansible/collections:/usr/share/ansible/collections

[callback_foreman]
report_type = foreman
proxy_url = https://foreman.example.com:9090
url = https://foreman.example.com
ssl_cert = /etc/foreman-proxy/foreman_ssl_cert.pem
ssl_key = /etc/foreman-proxy/foreman_ssl_key.pem
verify_certs = /etc/foreman-proxy/foreman_ssl_ca.pem

[ssh_connection]
ssh_args = -o ProxyCommand=none -C -o ControlMaster=auto -o ControlPersist=60s

seems to be fine, as the (even though deprecated) whitelist parameter is set and you can also see in the log above, the the plugin gets loaded.

According to this pull request on the callback plugin:

the ability was introduced for the callback plugin to be disabled on a case by case basis. For that it checks the environment variable FOREMAN_CALLBACK_DISABLE, which I cannot find set anywhere. The default of this should be 0, meaning activated.

But the warning message clearly indicates, that this environment variable was either set to 1 or the default check doesn’t work.

I am not sure where else I can search.

Pinging @aruzicka

How are you running it? From foreman?

Yes, I scheduled job in Foreman with the “Ansible Playbook” template and used the minimal playbook posted at the top of this thread.

Well, then that behaviour is expected, not sure why and how it works for lstejskal. Facts are only uploaded for the job template which has the ansible_run_host feature assigned to it. By default, the job template to apply assigned roles has this feature assigned. This will probably change in the foreseeable future, but right now this is what we have

Oh I see, haven’t been aware of that so far. Thank you for the clarification.

Is it possible to define a new job template with the ansible_run_host feature assigned and use it to collect facts? To me it looks like this is an internal setting as I can’t find the feature list exposed at the job template “Ansible Roles - Ansible Default”.

You can reassign the feature to a different job template in Administer > Remote execution features but currently it can be assigned to only one template at a time

Understood, thank you @aruzicka. In that case I would need to wait until multiple templates can produce facts for Ansible. I will raise a redmine feature request for it, if there isn’t already one.

There already is Bug #35585: Unable to enable callback plugin per-template - Ansible - Foreman and it is even being worked on.

1 Like

I was just about to start searching :slight_smile: Thank you @aruzicka