-
Notifications
You must be signed in to change notification settings - Fork 330
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
Please allow me to generate the inventory_hostname #104
Comments
Maybe one way to do this, would be to allow adding azure/plugins/inventory/azure_rm.py Line 328 in 4467d13
And do something like: compose_inventory_hostname = constructable_config_compose.pop("inventory_hostname") And pass that to get_hostname here: azure/plugins/inventory/azure_rm.py Line 333 in 4467d13
inventory_hostname = self._get_hostname(h, compose_inventory_hostname, strict=constructable_config_strict) Then _get_hostname would change to something like this: def _get_hostname(self, host, compose=None, strict=False):
if not compose:
return host.default_inventory_hostname
try:
return self._compose(compose, h.hostvars)
except Exception as e:
if strict:
raise AnsibleParserError("Could not generate inventory_hostname for host %s from hostvar_expressions.inventory_hostname: %s" % (host.default_inventory_hostname, to_native(e)))
return host.default_inventory_hostname Any comments on doing it like this? Or would using something other than |
Can a maintainer review this? I think this would solve a similar issue we are having where we want to be able to pull in hosts by ip address instead of the vm name. |
This PR has been reviewed and will be merged soon. Thank you! |
* Make inventory_hostname configurable with hostvar_expressions Resolves #104 * inventory: add default_inventory_hostname to hostvars This allows for hostvar_expressions like: hostvar_expressions: inventory_hostname: tags.vm_name | default(default_inventory_hostname) * inventory: document overriding default_inventory_hostname * Use hostnames instead of hostvar_expressions * Move azure_rm hostnames param documentation to doc_fragment
SUMMARY
I would like to define my own formula for generating the inventory_hostname. As Azure does not allow renaming VMs, I need to use a tag to get our names for the VM. I want to use our standardize tag name so that I can add vars in
host_vars/
as required.ISSUE TYPE
COMPONENT NAME
azure_rm inventory plugin
ADDITIONAL INFORMATION
This is a continuation of ansible/ansible#54065 which only requested the ability to configure the legacy behavior.
I want to define my own inventory_hostname as mentiond here:
azure/plugins/inventory/azure_rm.py
Lines 366 to 368 in 4467d13
For reference, this is the section that currently defines the legacy/unique hostname definition:
azure/plugins/inventory/azure_rm.py
Lines 504 to 508 in 4467d13
In both cases, this uses
vm_model['name']
but I explicitly do NOT want to usevm_model['name']
because Azure doesn't let me rename VMs.The text was updated successfully, but these errors were encountered: