I’m trying to get a list of Ubuntu instances from a GCE project. This is what my inventory file looks like.
plugin: gcp_compute
projects:
filters:
- disks.licenses:ubuntu
auth_kind: serviceaccount
service_account_file: ~/google_cloud/service_account/key/.json
I have referred to this page for the gcp_compute plugin: https://docs.ansible.com/ansible/latest/plugins/inventory/gcp_compute.html
And when it refers to filters, the documentation links to this page: https://cloud.google.com/compute/docs/reference/rest/v1/instances/list
When I run:
gcloud compute instances list --filter="(disks.licenses:ubuntu)" --format=json
… it works just fine and only returns Ubuntu instances.
However, running
`
ansible-inventory -i .gcp.yml --list
`
… with the “disks.licenses:ubuntu:” filter returns the following:
`
[WARNING]: * Failed to parse /Users/username/.ansible/inventory/.gcp.yml with yaml plugin: Plugin configuration YAML file, not YAML inventory
[WARNING]: * Failed to parse /Users/username/.ansible/inventory/.gcp.yml with ini plugin:
/Users/username/.ansible/inventory/.gcp.yml:1: Expected key=value host variable assignment, got: gcp_compute
[WARNING]: * Failed to parse /Users/username/.ansible/inventory/.gcp.yml with auto plugin: [{‘domain’: ‘global’, ‘reason’: ‘invalid’,
‘message’: “Invalid value for field ‘filter’: ‘disks.licenses:ubuntu’. Invalid list filter expression.”}]
[WARNING]: Unable to parse /Users/username/.ansible/inventory/.gcp.yml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
{
“_meta”: {
“hostvars”: {}
},
“all”: {
“children”: [
“ungrouped”
]
},
“ungrouped”: {}
}
`
Has anyone been able to resolve this sort of issue before? If so, what did you do?