Foreman / Ansible - Set dictionaries parameters

HI :slight_smile:

I’m trying to set dictionaries “key/value” and “array” in my “Host Parametres” from Foreman.

This is my code with “Ansible-Playbook” command : (And it works well)

- hosts: all
  - chrony
      driftfile: /var/lib/chrony/drift
      logdir: /var/log/chrony
      makestep: '1.0 3'
      rtcsync: true

My problem is that when i set “chrony_commands.xxxxxx” or "chrony_commands[‘xxxx’] in my host parameters in foreman, they are not used…

How can i do it ?

Thx for help

I think this is related to the changes made in the Foreman inventory script now developed by Ansible.

We got the same problems and after speaking to some Ansible developers it seems that this change is going to work in Ansible 2.8.

Maybe I’m missing what you exactly set in Foreman. Are you trying to define host parameter with name “chrony_commands.xxxxx”?

What is your Foreman version? Note that host parameters in Foreman 1.21 and below are only strings. In 1.22 (next Foreman version), parameters can have complex types. Also in newer version of foreman_ansible plugin, which is already available with 1.2.1, we added so called ansible variables, that allow defining arrays and dictionaries natively in Foreman.


Ty for your reply.
My Foreman version is “1.20.1”.
Yes, I’m trying to call arrays and dictionaries in Foreman (From Host/Group parametres), but it doesn’t work.

Ok, i’m waiting for 1.21 :slight_smile:

I know this is a very old thread, but was wondering if this was every put in place?? its actually something im looking for myself and have tried different variations to get this to work with no luck.

my ansible vars are the below and i have tried to use ssh_config.PermitRootLogin and also ssh_config.[PermitRootLogin] with the string prohibit-password, but its not getting applied.

Port: 22
PermitRootLogin: “yes”
AuthorizedKeysFile: .ssh/authorized_keys

Dia dhuit, @cflannigan !

What version of Foreman are you on?
Are you just getting set up?

Have had the foreman instance up a while and moving away from puppet to ansible so the ansbile side is new and just testing some roles…

The below are the versions for foreman and the ansible collection.

  • ansible-collection-theforeman-foreman-2.1.0-1.el7.noarch
  • foreman-2.5.1-1.el7.noarch

Thanks @cflannigan

It looks like you’re trying to set up SSH via the host parameters?
We have a few options listed in the docs, did you get nowhere with these options:

Thanks for the info, its not just SSH i have a few other roles that are the same that use the dictionary key:value approach. Just example used was for configuring the sshd_config file to be able to manage that setup.

I also have sysctl parameters and others, so its not isolated to just ssh-key management its more overall functionality. If the dictionary key:value is not possible thats ok i can re-write the ansible roles, just was hoping it was possible as it would make things easier…

Example of the sysctl

  net.ipv6.conf.all.disable_ipv6: 1
  net.ipv6.conf.default.diable_ipv6: 1

Sorry i have managed to figure it out, looks like theforeman can only manage default variables any OS Specific variables in the vars directory are static and cannot be adjusted through the parameters…

After i moved all my vars from the OS specific vars to the defaults it allowed me to override them through theforeman host parms using ssh_config.Key → string → value

1 Like

Cool. Thanks for the update @cflannigan - I was trying to chase down a proper answer for you.

Yes, Foreman can only detect variables listed in defaults.yml. I think you can still define an ansible variable manually for a particular role, if it.can not be automatically detected and imported.

1 Like