1

Iam using the foreman.py script for creating a dynamic inventory. How can I use the collected facts from the foreman.facts file in my ansible playbooks?

ll /etc/ansible/foreman*

-rw-r--r--. 1 root root  613597 Jun  3 16:38 /etc/ansible/foreman.cache
-rw-r--r--. 1 root root 1331584 Jun  3 16:38 /etc/ansible/foreman.facts
-rw-r--r--. 1 root root       2 Jun  3 16:38 /etc/ansible/foreman.hostcollections
-rw-r--r--. 1 root root   42427 Jun  3 16:38 /etc/ansible/foreman.index
-rw-r--r--. 1 root root     506 Jun  3 16:17 /etc/ansible/foreman.ini
-rw-r--r--. 1 root root   32539 Jun  3 16:38 /etc/ansible/foreman.params

Thank you very much!

Best regards

Michael Hampton
  • 244,070
  • 43
  • 506
  • 972
brotaxt
  • 11
  • 2
  • What have you tried to use them so far ? Because it should be as simple as using any other fact discovered on any other host in any inventory => `"{{ name_of_var }}"` – Zeitounator Jun 03 '19 at 16:23
  • Did you try to inspect `hostvars['somehost']` to see what you get in there ? – Zeitounator Jun 04 '19 at 06:46
  • yes, this does not work. :-/ I must load the facts from the generated json file (foreman.facts) because some of my target hosts are not reachable via ssh directry. I want to use the collected facts for some remote job handling inside the foreman. Ive tried to include the file on play-level and on task-level. (via vars_files: and include_vars:) When I print the variables with the mentioned hostvars prefix I can see the content of the whole file!? - name: Print variable debug: msg: "{{ hostvars['Testhost'] }}" – brotaxt Jun 04 '19 at 07:01

1 Answers1

2

It's working now!

I've imported the foreman.facts file into my ansible-playbook in the following way:

vars_files:
  - /etc/ansible/foreman.facts

After that, I am able to use the variables. e.g.

when: foreman['model_name'] == "VMware Virtual Platform"
Anton Danilov
  • 5,082
  • 2
  • 13
  • 23
brotaxt
  • 21
  • 1