I’m having trouble with dynamic inventory in AWX. I’m trying to create Ansible inventory groups based on instance tags. I’m configuring the inventory plugin using Source Variables in AWX.
My inventory configuration (in Source Variables) includes something like this to group by tags:
[WARNING]: * Failed to parse /runner/inventory/gcp_compute.yml with auto
plugin: Invalid group name format, expected a string or a list of them or
dictionary, got: <class 'builtin_function_or_method'>
I’ve checked:
YAML syntax (it’s valid)
GCP tag data: tags.items is a list of strings (e.g., ["web", "db"])
My setup:
Ansible version: (e.g., 2.15.12)
google.cloud collection: (e.g., 1.3.0 or 1.5.0)
AWX on GKE
Why am I getting this error, and how can I create groups from my GCP instance tags?
So the error is coming from trying to use “tags.items” since “items” is a function built into Ansible and the keyed_groups paramater “key” can’t accept that. I think you may be approaching using keyed groups the wrong way as it will take a property from the host’s discovered details and create groups for each value (or key_value if the value is a dictionary). The “prefix” will be added to front of the group name.
For example, if a host has tags “env:dev” and “team:devops” with a keyed group setup like
keyed_groups:
- key: tags
prefix: gcp
The resulting groups would be:
gcp_env_dev
gcp_team_devops
note: “tags” is coming from the host’s details that are auto-discovered from GCP
If you wanted to filter or add conditions on when a group is created, you would probably want to look at the “groups” option. This allows you to define the group name and what property conditions need to be met before the host is added to the group.
I don’t have a GCP account so I unfortunately couldn’t test these, but the plugin looks similar to the Azure version which I am familiar with. I also found this write-up that has some good info and examples How To Setup Ansible Dynamic Inventory on Google Cloud
Hopefully this helps gets you going! Feel free to post any follow-up questions or if you were able to get working.