Can I set a default value for the enabled_value?

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 found that the enabled_var and enabled_value variables are ways to determine whether to enable a host or not using a host variable from an inventory source. InventorySource new fields · Issue #7819 · ansible/awx · GitHub

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:

all:
  hosts:
  vars:
    is_it_actually_enabled: yup  # default for all
  children:
    updates1:
      hosts:
        trusty1.example.net:
          is_it_actually_enabled: nope
          disabled_reason: idk
        trusty2.example.net:
    updates2:
      hosts:
        xenial1.example.net:
        xenial2.example.net:

Am I doomed to having to set it up per host? Or is there some way to get it set up on a higher level, inventory or otherwise.

The ‘ultimate’’ way to setup a default is to use a role and then add them to defaults/main.yml in the role, that has the lowest precedence.

Setting it in the ‘all’ group, in inventory or via vars plugin should be fine also. It has low precedence and affects ‘all hosts’.

As for you having no success … well, can you show a play using that inventory and display the variable per host?

Yeah, i should’ve been more specific :sweat_smile:
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.

then I change my config to such:

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!