Ansible variable is always overridden with the global default

Problem:
According to the documentation, in order to manage an Ansible variable inside of Foreman, you go to Configure -> Variables and select the Override check box and give it a sensible default.
Then you can go to a host and add the variable name with a value for that host.

However, no matter what you do at the host or host group level, the Ansible role will always receive the global default value. Is this the intended behavior?

Interestingly enough, the YAML dump at the host shows the correctly overridden value at the host level.

Expected outcome:
The Ansbile role should use the setting from the host or host group and only if not found, use the global default.

Foreman and Proxy versions:
Foreman 2.2
Katello 3.17

Foreman and Proxy plugin versions:
Ansible 2.9

Distribution and version:
CentOS 7

Other relevant data:

Hi @rbremer

I half-remember something about this from a while back…

Can you check your setup against this doc about Ansible precedence:

I remember putting this together long ago:

If it doesn’t help clarify, hopefully someone else will have a wiser answer. If I find any more info, I’ll add it here.

The first document is Ansible only and as the variables are passed in by Foreman, should not really be a factor for my case.

The second link is what I followed - and together with the info buttons on the configure -> variables page - leads to the conclusion (at least for me):

  • you need to click “override” in order to manage the variable inside of Foreman (see Procedure, point 2: Select the Ansible variable that you want to override and manage with Foreman.)
  • you then add the variable to the host/host group (see Procedure at the end: To use the Ansible variable, add the variable as a parameter to your host or host group, or add the variable as a global parameter.)

So in my understanding, I click the box, give it a default value (for instance ntp_timezone: Etc/UTC) and then add it to the host in order to give it a more granular value (eq Americas/Chicago). YAML dump concurs but the actual execution puts Etc/UTC into the variable for that host.

Hey @rbremer
I should have probably elaborated a bit more. I think people hit upon this problem from the docs, as many users did:

If you use an Ansible role to run a task as a user that is not the Effective User, there is a strict order of precedence for overriding Ansible variables.

Yep, I was stumbling at that one too. In my setup the ssh user and effective user are identical, so I was hoping to not be affected by this paragraph. Which, btw, I also cannot fully comprehend as the Ansible docs do not cover variables passed in by Foreman, so I think I would need a lot more understanding of the internals to make sense of it.

1 Like

I’ll try and find someone who might better explain this, and thus help us make better docs :slight_smile:
Thanks!

1 Like

Thank you @mcorr :slight_smile:

It looks like the priority is as follows:
value of variable in foreman with override checked > host parameter > hostgroup parameter > global parameter > role default.

I have no idea if this is intended, but it kinda makes sense. The way I think about it is: If you set the override on a variable you are essentially saying “this is the value I want to use, no matter what”, hence an override. If you assign it to the host/hostgroup/global parameter, that value is used, unless overriden.

Hi Adam,

thank makes a lot of sense to me. Thank you for the clarification. The (i) tooltip is just misleading in that case, it starts with “Marks the variable to be managed by Foreman…”

So I did assume I need to mark them in order to be able to manage them.

Maybe a better tooltip could start with: “Marks the variable as a global override. The value specified here will be used for all hosts …”