ansible-collections / ansible-collections/google.cloud

gcp_compute inventory fails to parse when a compute instances has no labels when the labels entry is specified

Open Beginner friendly
#494 2 comments 2 reactions 0 assignees View on GitHub
stale
Dominant language
Python
Stars
105
Forks
144
Avg merge
5d 10h
Merged PRs (30d)
4

Description

##### SUMMARY
The gcp_compute inventory allows you to use labels as name.
However once specified it requires all compute instances to have at least one label.
This should not be a requirement. If the label is not available, it should go with the next specified ordering. If not labels at all are present, it should have the same behavior.

##### ISSUE TYPE
- Bug Report

##### COMPONENT NAME
gcp_compute.py inventory plugin

##### ANSIBLE VERSION

```paste below
ansible 2.10.17
config file = /tmp/tmp7wm48acw/ansible.cfg
configured module search path = ['/tmp/tmp7wm48acw/.library']
ansible python module location = /usr/local/lib/python3.9/site-packages/ansible
executable location = /usr/local/bin/ansible
python version = 3.9.3 (default, Apr 2 2021, 21:01:41) [GCC 8.3.0]
```

##### COLLECTION VERSION

```paste below
** sidenote inventory is pinned to git commit ec093086ab2b7ab203e23e1d45ba7944a737f7b8

# /root/.ansible/collections/ansible_collections
Collection Version
------------ -------
google.cloud 1.0.2

# /usr/local/lib/python3.9/site-packages/ansible_collections
Collection Version
------------ -------
google.cloud 1.0.2
```

##### OS / ENVIRONMENT

##### STEPS TO REPRODUCE

```yaml
1 - Create a vm without any labels
2 - Add labels.name (or another label) to the hostnames entry in the inventory
```

##### EXPECTED RESULTS

The VM without any labels should use the next entry in the hostname section if no labels are present

##### ACTUAL RESULTS

The inventory stops parsing

```paste below
[WARNING]: * Failed to parse /tmp/tmp7wm48acw/inventory/gcp/us_east1.gcp.yml with ansible_collections.google.cloud.plugins.inventory.gcp_compute plugin: 'labels'
```

Contributor guide

Open the contributing guide

Research direction

Start in the gcp_compute.py inventory plugin and reproduce the failure with a compute instance that has no labels while labels.name is listed in the hostnames configuration. Trace the fallback ordering described in the report; done means unlabeled instances no longer stop inventory parsing and use the next hostname entry.

Written by the indexing model from the issue text.

Assessment

Tech stack
google-cloud, python
Domain
cloud
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.