From 88743d11ae638660fdb2be433d5ea7586574e67f Mon Sep 17 00:00:00 2001 From: Bob Lee Date: Wed, 5 Sep 2018 14:45:56 -0400 Subject: [PATCH] Update documentation for gcp_compute (#43791) Added examples on how to use "keyed_groups", "hostnames", and "compose" The compose example shows how to set the ansible_host var for a host to either the public or private ip. This is necessary when you set your hostname by name instead of ip --- plugins/inventory/gcp_compute.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/plugins/inventory/gcp_compute.py b/plugins/inventory/gcp_compute.py index af18bcf..2b35c0c 100644 --- a/plugins/inventory/gcp_compute.py +++ b/plugins/inventory/gcp_compute.py @@ -60,11 +60,21 @@ projects: filters: - machineType = n1-standard-1 - scheduling.automaticRestart = true AND machineType = n1-standard-1 - scopes: - https://www.googleapis.com/auth/compute service_account_file: /tmp/service_account.json auth_kind: serviceaccount +keyed_groups: + # Create groups from GCE labels + - prefix: gcp + key: labels +hostnames: + # List host by name instead of the default public ip + - name +compose: + # Set an inventory parameter to use the Public IP address to connect to the host + # For Private ip use "networkInterfaces[0].networkIP" + ansible_host: networkInterfaces[0].accessConfigs[0].natIP ''' from ansible.errors import AnsibleError, AnsibleParserError