Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcp_compute inventory fails to parse with retrieve_image_info and multiple projects. #651

Open
juan-perdomo opened this issue Oct 30, 2024 · 0 comments

Comments

@juan-perdomo
Copy link

SUMMARY

When I am using the google.cloud.gcp_compute to generate and inventory with the retrieve_image_info: true option enabled and there is multiple projects I get an error that says it fails to parse. This is not an issue with a single project or if run multiple projects but retrieve_image_info: false.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

google.cloud.gcp_compute

ANSIBLE VERSION
ansible [core 2.17.5]
COLLECTION VERSION
(.venv) ➜  inventory ansible-galaxy collection list google.cloud 

# /usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible_collections
Collection   Version
------------ -------
google.cloud 1.4.1  
CONFIGURATION
(.venv) ➜  inventory ansible-config dump --only-changed
CONFIG_FILE() = None
PAGER(env: PAGER) = less
OS / ENVIRONMENT

MAc

STEPS TO REPRODUCE

Run the following yaml
ansible-inventory -i gcp.yaml --graph

---
plugin: google.cloud.gcp_compute
projects:
  - project-infra-test
  - project-infra-stg
  - project-infra-prd
auth_kind: serviceaccount
service_account_file: /pathtojason.json
retrieve_image_info: true
keyed_groups:
  - prefix: NETWORK
    key: networkInterfaces[0].network.name
  - prefix: PROJECT
    key: project
  - prefix: IMAGE
    key: image
hostnames:
  # List host by name instead of the default public ip
  - name
filters:
  - NOT labels.goog-gke-node = ""
EXPECTED RESULTS

I would expect to parse through all the projects and group them as expected with only one project.

ACTUAL RESULTS

When I run the command it wont provide any inventory and will error out. Note that if the list of projects is large enough. even with retrieve_image_info: true it will return image: null for all hosts.

(.venv) ➜  inventory ansible-inventory -i gcp.yaml --graph -vvvv         
ansible-inventory [core 2.17.5]
  config file = None
  configured module search path = ['/Users/user.name/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible
  ansible collection location = /Users/user.name/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible-inventory
  python version = 3.12.7 (main, Oct  1 2024, 02:05:46) [Clang 15.0.0 (clang-1500.3.9.4)] (/usr/local/Cellar/ansible/10.5.0/libexec/bin/python)
  jinja version = 3.1.4
  libyaml = True
No config file found; using defaults
setting up inventory plugins
Loading collection ansible.builtin from 
host_list declined parsing /Users/user.name/notes/AWX/ansible/inventory/gcp.yaml as it did not pass its verify_file() method
script declined parsing /Users/user.name/notes/AWX/ansible/inventory/gcp.yaml as it did not pass its verify_file() method
Loading collection google.cloud from /usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible_collections/google/cloud
Using inventory plugin 'ansible_collections.google.cloud.plugins.inventory.gcp_compute' to process inventory source '/Users/user.name/notes/AWX/ansible/inventory/gcp.yaml'
toml declined parsing /Users/user.name/notes/AWX/ansible/inventory/gcp.yaml as it did not pass its verify_file() method
[WARNING]:  * Failed to parse /Users/user.name/notes/AWX/ansible/inventory/gcp.yaml with auto plugin: 'https://www.googleapis.com/compute/v1/projects/project-infra-test/zones/us-
central1-a/disks/solarwinds-npm-nta'
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible/inventory/manager.py", line 292, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible/plugins/inventory/auto.py", line 58, in parse
    plugin.parse(inventory, loader, path, cache=cache)
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible_collections/google/cloud/plugins/inventory/gcp_compute.py", line 622, in parse
    self._add_hosts(value, config_data, project_disks=project_disks)
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible_collections/google/cloud/plugins/inventory/gcp_compute.py", line 438, in _add_hosts
    host = GcpInstance(
           ^^^^^^^^^^^^
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible_collections/google/cloud/plugins/inventory/gcp_compute.py", line 178, in __init__
    self.convert()
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible_collections/google/cloud/plugins/inventory/gcp_compute.py", line 208, in convert
    self.json["image"] = self._get_image()
                         ^^^^^^^^^^^^^^^^^
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible_collections/google/cloud/plugins/inventory/gcp_compute.py", line 277, in _get_image
    image = self.project_disks[disk["source"]]
            ~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^
[WARNING]:  * Failed to parse /Users/user.name/notes/AWX/ansible/inventory/gcp.yaml with yaml plugin: Plugin configuration YAML file, not YAML inventory
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible/inventory/manager.py", line 292, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible/plugins/inventory/yaml.py", line 113, in parse
    raise AnsibleParserError('Plugin configuration YAML file, not YAML inventory')
[WARNING]:  * Failed to parse /Users/user.name/notes/AWX/ansible/inventory/gcp.yaml with ini plugin: Invalid host pattern '---' supplied, '---' is normally a sign this is a YAML file.
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible/inventory/manager.py", line 292, in parse_source
    plugin.parse(self._inventory, self._loader, source, cache=cache)
  File "/usr/local/Cellar/ansible/10.5.0/libexec/lib/python3.12/site-packages/ansible/plugins/inventory/ini.py", line 137, in parse
    raise AnsibleParserError(e)
[WARNING]: Unable to parse /Users/user.name/notes/AWX/ansible/inventory/gcp.yaml as an inventory source
[WARNING]: No inventory was parsed, only implicit localhost is available
@all:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant