fact not being set when using raw module

Hello, I’m trying to to run a raw command against a linux host which does not have python installed. Here is my playbook:

  • hosts: all
    gather_facts: false
    tasks:
  • name: Get OS Release Information
    raw: uname -a
    register: os_information
  • debug:
    var: os_information
  • set_fact:
    os_information: “{{ os_information.stdout }}”

It looks like it works but the fact cache for this host is still empty.

ok: [2caf4ecbb1f4] => {“ansible_facts”: {“os_information”: {“changed”: true, “failed”: false, “rc”: 0, “stderr”: “Shared connection to 2caf4ecbb1f4 closed.\r\n”, “stdout”: “Linux 2caf4ecbb1f4 4.9.60-linuxkit-aufs #1 SMP Mon Nov 6 16:00:12 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux\r\n”, “stdout_lines”: [“Linux 2caf4ecbb1f4 4.9.60-linuxkit-aufs #1 SMP Mon Nov 6 16:00:12 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux”]}}, “changed”: false}

Any ideas?

Thanks!

fact cache is populated by gathered facts, by default set_fact does not.

Hey Brian, could you elaborate on that? What does set_fact do if it does not populate the fact cache?

Also, I should note that I am using AWX so I am checking the option that says “use fact cache”

It sets a var at the host scope, not really a gathered fact, though
the name is misleading.

So is it possible to populate a manual fact to the persistent cache with a playbook?

In latest versions, with the addition of the 'cacheable' option.

First of all, I guess I should try actually reading things (from set_fact):“These variables will be available to subsequent plays during an ansible-playbook run, but will not be saved across executions even if you use a fact cache.”

And I am running the latest version of AWX that is available as far as I know, but maybe this isn’t new enough? Is there any documentation available o the ‘cacheable’ option? I’ll actually read it this time.

`ansible-doc set_fact` will give you the documentation of the
installed version you have available. This is not directly an awx
version issue but an ansible one.

In any case here are the docs for the latest stable version:
http://docs.ansible.com/ansible/latest/modules/set_fact_module.html

the option was added in Ansible 2.4

That’s super helpful. Thank you much!