Closed life5ign closed 3 years ago
Files identified in the description:
If these files are inaccurate, please update the component name
section of the description or use the !component
bot command.
cc @Charliekenney23 @InTheCloudDan @LBGarber @decentral1se @displague @rmcintosh click here for bot help
I don't think this is a bug, but a design choice that doesn't fit your expectations. (Or is the behavior you expect documented?) In that case, this would be a feature (and should have an option which allows to switch to this behavior.)
You are completely right. "Linode labels are used by default as the hostnames." https://docs.ansible.com/ansible/latest/collections/community/general/linode_inventory.html
It is by design and documented, my bad.
Also, I realized that Google sent me to an old version of the documentation, which I didn't realize, so I didn't know about the latest options.
I guess I would like to request this feature, unless the compose
option above allows me to set ansible_host
to the value of the public ip address, like, for example, the aws_ec2 plugin. Do you know if it does allow this?
So with the current way it works, would I have to set my linode labels to the reverse dns values (or public ips) for each server, in order to have inventory_hostname
be something that can actually be connected to by ansible (ssh in my case)? I think these dns and ips are static in linode (if they weren't this wouldn't work), but it seems a roundabout to have to do this.
Oh wow, I can't believe this just worked:
I added
compose:
ansible_host: 'ipv4[0]'
to my linode inventory plugin file, making a pure guess that it might grab the primary key ipv4
's value, from the object returned by the ansible-inventory --host whatever_host
call. It did! I think this should be added to the documentation... I still have the issue of choosing the public and not the private ip from the "ipv4" value (a list), which presents a bit of an issue, but I guess I can regex for it, since compose
uses jinja filters. It could be useful to have this value be a dictionary with keys for public and private ips, so it would be easier to choose.
@Life5ign Thanks for adding the solution too, feel free to open a PR adding this to docs if you've found it useful for others too.
Oh wow, I can't believe this just worked:
I added
compose: ansible_host: 'ipv4[0]'
to my linode inventory plugin file, making a pure guess that it might grab the primary key
ipv4
's value, from the object returned by theansible-inventory --host whatever_host
call. It did! I think this should be added to the documentation... I still have the issue of choosing the public and not the private ip from the "ipv4" value (a list), which presents a bit of an issue, but I guess I can regex for it, sincecompose
uses jinja filters. It could be useful to have this value be a dictionary with keys for public and private ips, so it would be easier to choose.
I opened https://github.com/ansible-collections/community.general/pull/3203 which also includes an example for pulling the private IP address in addition to pulling in the complete information available in the upstream Linode APIv4.
This will negate the need to try and detect public vs private addresses via regex since the API provides this information already.
Since this is addressed by #3200, I'll close. If that's too inflexible, the solution from #3203 will allow to better handle this. (#3200 also works for already released versions.)
Summary
The ansible linode dynamic inventory plugin is not using discovered ipv4 addresses as ansible_host, and is trying to resolve linode tag name instead. It is getting the information about linodes from linode_api4, but, when trying to run ansible or ansible-playbook on the host/group patterns, it simply tries to resolve the linode tag name, and can't (not in DNS).
Also posted: https://devops.stackexchange.com/questions/13833/ansible-linode-inventory-module-not-letting-ansible-or-ansible-playbook-use-lino
Issue Type
Bug Report
Component Name
linode
Ansible Version
Configuration
OS / Environment
Ubuntu 20.04 LTS (PopOS)
Steps to Reproduce
Inventory plugin file:
static inventory file to group the output groups of the dynamic inventory
ansible-inventory --graph linode
and, ansible-inventory --host app-2
plus a bunch of other parameters including some hosts with one ipv4 address, some hosts with two (a public and a private). None are able to be reached by ssh by ansible.
Expected Results
I expect a host correctly identified by the linode inventory plugin to have a connection parameter ansible_host equal to its public ipv4 address (if this is how it works).
Actual Results
Code of Conduct