Skip to content

Add custom hostname set in GCE to the hostnames block of the inventory plugin #219

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions plugins/inventory/gcp_compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@
hostnames:
description: A list of options that describe the ordering for which
hostnames should be assigned. Currently supported hostnames are
'public_ip', 'private_ip', or 'name'.
default: ['public_ip', 'private_ip', 'name']
'public_ip', 'private_ip', 'name', or 'custom_hostname'.
'name' is the instance name in GCE.
'custom_hostname' is the custom hostname set when creating the
instance. Falls back to 'name' if a custom hostname is not
defined.
default: ['public_ip', 'private_ip', 'name', 'custom_hostname']
type: list
auth_kind:
description:
Expand Down Expand Up @@ -236,6 +240,12 @@ def hostname(self):
name = self._get_privateip()
elif order == "name":
name = self.json[u"name"]
elif order == "custom_hostname":
if "hostname" in self.json:
name = self.json[u"hostname"]
else:
name = self.json[u"name"]

else:
raise AnsibleParserError("%s is not a valid hostname precedent" % order)

Expand Down