Thanks for the feedback!

Unfortunately, I'm not that familiar with Python to grab the whole process, 
but I checked what you suggested, and at least in the REST I see when 
opening the instance detail, I **don't** see the "hostname" key. I only 
have the "name" one. But that should be correct, according to the config 
above, it should take the hostname from the "name" attribute.
Il giorno martedì 21 giugno 2022 alle 16:53:46 UTC+2 Brian Coca ha scritto:

> Compose happens to late to set inventory_hostname, this is not a
> 'settable variable' but a variable that reflects the name with which
> the host was added to inventory.
>
> Being able to choose what to use as inventory_hostname depends on the
> inventory plugin,
> many allow you to set inventory_hostname others do not.
>
> In this case, the gcp_compute inventory plugin does allow it, and from
> the docs it should work with 'name'
>
> hostnames:
> description: A list of options that describe the ordering for which
> hostnames should be assigned. Currently supported hostnames are
> 'public_ip', 'private_ip', 'name' or 'labels.vm_name'.
> default: ['public_ip', 'private_ip', 'name']
>
> But docs can be wrong, so I looked at the code:
>
> https://github.com/ansible-collections/google.cloud/blob/0cd64a4a68b7d4393c97b801e3f24e6b63882294/plugins/inventory/gcp_compute.py#L231
> ,
> this does seem to use the hostnames options/ordering to assign the
> name. That code is then used to create the host
>
> https://github.com/ansible-collections/google.cloud/blob/0cd64a4a68b7d4393c97b801e3f24e6b63882294/plugins/inventory/gcp_compute.py#L302
> (which sets inventory_hostname to hostname()).
>
> So the only thing I can think of .. the API is not returning 'name' as
> part of the host information.
> ----------
> Brian Coca
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/af834341-eb3f-42ad-b683-099908aaddeen%40googlegroups.com.

Reply via email to