I supply AWX with inventory sources yaml files.
I need a ‘easy to configure’ way to exclude hosts in an inventory from jobs with a reason attached.
I came up with an idea to (ab)use the enabled_var .
I would like to set a default value for this enabled_value for all my hosts.
I figured that this could be done on the inventory.yml
In the inventory source, enabled_var is set to is_it_actually_enabled with the enabled_value set to yup
But I have had no success with this inventory yaml:
Yeah, i should’ve been more specific
I use a gitops approach to configure AWX, changing my inventory triggers an inventory sync pipeline.
You are correct that a play would display the variables correctly (using inventory from my original post)
TASK [Show is_it_actually_enabled value for each host] *****************************************************************
ok: [trusty1.example.net] => {
"msg": "Host trusty1.example.net has is_it_actually_enabled set to: nope"
}
ok: [trusty2.example.net] => {
"msg": "Host trusty2.example.net has is_it_actually_enabled set to: yup"
}
But in AWX, I can’t get the hosts to become enabled again once they are disabled. Unless I explicitly set the enabled_var on the host itself with the correct enabled_value, that will work.
So currently, I explicitly disabled trusty1 by setting to enabled_var on host level.
all:
hosts:
vars:
is_it_actually_enabled: yup # default for this group
children:
updates1:
hosts:
trusty1.example.net:
trusty2.example.net:
is_it_actually_enabled: yup
But after the inventory sync, trusty1 was not re-enabled.
So I am wondering if this enabled_var does not look at variables in the way a play does (or maybe my gitops messes up during sync, but that does not seem likely to me).
I also noticed that, when looking at the variables on AWX, only trusty2 has the value defined. but I imagine this is normal for variables inherited from the parent vs a variable directly defined on host level.
Ah, so the issue is trying to set the default in awx itself, not for play run. That won’t work, awx does not ‘resolve’ the inventory as ansible-playbook does.
Feared as much, tried it nevertheless. It is as you say, the enabled_var is only checked on host level.
I’ll just settle for adjusting the playbook to skip hosts that have the given variable.
Thanks for the responses!