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
Undefined 'ansible_host' in local_action hostvars #21269
Comments
Also debug in any case ignores connections as it runs 'in memory' on the controller at all times, using local_action is irrelevant for this type of module. Can you show any other case in which this is an issue that does not match the above? |
The bug surfaced when trying to wait for a host to reboot with a task like this:
This appeared to be best option in environments where inventory_hostname is not necessarily reachable (which ours is), as described in workaround for #16139. debug was just our attempt to replicate as simply as possible. |
well, this wouldn't work for the same reason, |
Sorry @bcoca I am confused. We picked up this example from #16139, it appeared that going to hostvars[inventory_hostname]['ansible_host'] might work, given that inventory_hostname would still point to the remote system we're waiting for. Are you saying it's expected for ansible_host to not be defined in that context? I do notice that:
Task 2 will show the host, task 5 will not, which confused us. If this is not a bug and there is not expected to be any way to access the remote IP if inventory_hostname isn't reachable feel free to close, we have the set_fact workaround it just felt like this might be a bug. |
it would be a bug if you defined ansible_host in inventory and it is not appearing when you reference it, it is not a bug if you are expecting the return of the connection to define it. |
ISSUE TYPE
COMPONENT NAME
local_action
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
Seen on Fedora 25 and RHEL 7.
SUMMARY
There appears to be a problem where the ansible_host inventory variable appears unset if used within a local_action.
STEPS TO REPRODUCE
EXPECTED RESULTS
We expected Task 4 to output the ansible_host value of "54.158.245.48".
Per #16139 it appears that this is the recommended way to do something like wait_for in a local_action when waiting for a system to restart. Without it, there appears to be no way to access the host in situations where inventory_hostname cannot be reached from the local system running ansible.
ACTUAL RESULTS
Solution from #16139 appears to no longer work as ansible_host is not defined by default within inventory_vars. (unless you set it yourself explicitly)
We did find a simple workaround just using a set_fact to assign some variable to the value of ansible_host, then using it within the local_action.
The text was updated successfully, but these errors were encountered: