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

Allow filtering of instances by labels in GCE dynamic inventory #38391 #38424

wants to merge 2 commits into
base: devel


None yet
4 participants

ykyr commented Apr 6, 2018


Parameter --instance-labels allows to filter instances by labels. It's possible to use multiple labels separated by ",".
The same labels can be used in playbooks.
Key:Value should be used as key_value.

  • Feature Pull Request

ansible 2.5.0
  config file = None
  configured module search path = [u'/home/ubuntu/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/ubuntu/.local/lib/python2.7/site-packages/ansible
  executable location = /home/ubuntu/.local/bin/ansible
  python version = 2.7.12 (default, Dec  4 2017, 14:50:18) [GCC 5.4.0 20160609]

Requires apache-libcloud 2.3.0

/ --list --instance-labels env_dev --pretty
  "": [
        "gce_image": "ubuntu-1604-xenial-v20180222",
        "gce_labels": {
          "env": "stage",
          "name": "db2",
          "type": "database"
  "g1-small": [
  "label_env_stage": [
  "label_name_db2": [
  "label_type_database": [

This comment has been minimized.

scottkof commented Apr 10, 2018

Thanks for this PR, it's useful. A couple of issues:

  1. The script breaks if ANY node doesn't have a label, here's the pertinent portion of the stack trace:
  File "", line 521, in group_instances
    for lab_key, lab_value in labels.items():
AttributeError: 'NoneType' object has no attribute 'items'
  1. Labels require apache-libcloud 2.3.0. The script and ini files only require version 0.13.

This comment has been minimized.

ykyr commented Apr 11, 2018

@scottkof Thank you for a good catch.

  1. I have already committed fix if node doesn't have labels.
  2. Unfortunately yes. These changes require apache-libcloud 2.3.0 because support of node labels was released in libcloud 2.3.0. Also added this as requirement to my PR.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment