Foreman parameters in ansible playbooks/roles

Hi,

when I run an imported ansible role on katello, there is a task “Display all parameters known for the Foreman host”. How can I access these parameters from imported ansible playbooks/roles?

Regards,
Toni

When you run an imported Ansible role on Katello, the task “Display all parameters known for the Foreman host” shows all variables available for that host. In Foreman, you can find this in the Job Templates page by searching for Ansible Roles - Ansible Default. The corresponding task in this default playbook template is available on GitHub here.

You can access these parameters in your own playbooks or roles using a debug task. For example:

---
- hosts: all
  tasks:
    - name: Display all Foreman host parameters
      debug:
        var: foreman

Using this task in your own playbooks will generate the same output as when you run the Ansible roles from Foreman.

That’s it. Thank you very much.

All my playbooks and roles run on foreman/katello. Is it somehow possible to access “purpose_usage”?
I know it is possible by using “Theforeman.Foreman” Collection but maybe there is a better way to get the values.

Are you asking how to print a specific host parameter in an Ansible playbook?
You can do it like this:

- name: Print a specific host parameter
  debug:
    var: hostvars[inventory_hostname].purpose_usage

This will display the value of the purpose_usage parameter for each host in your inventory.

1 Like

“purpose_usage” is not listed when I run this playbook:

- hosts: all
  tasks:
  - debug:
      var: hostvars[inventory_hostname]

What am I missing?

Do you see other host params?

I’m not sure that “purpose_usage” is a host parameter, unless you’ve added it manually.

1 Like

Yeah, that’s what I thought @tonido meant.