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
Ansible seems to have issues resolving nested variables for delegate_to
#79450
Comments
Files identified in the description: If these files are incorrect, please update the |
Ansible 2.12 I get a different issue:
Ansible 2.14 I reproduce as
Note this appears to happen when the my_execution_node is the same as the current node
and succeeds on for example
So your task Still trying to test this. |
note that |
@lathama : I do not understand, entirely. I do not think that it happens when the randomly selected node is the same as the node that is triggering the delegated execution: First, sticking to your example, Ansible displays this:
The fact, that it says
Comparing the output of SSH (on MacOS): This looks very familiar - it's the same issue I get on my Mac - Compare with the README.md in the repo at https://github.com/The-Judge/ansible-delegate-demo/blob/main/README.md :
It's just what my MacOS SSH version displays ... Somehow, this information seems not to be handed over to the task, Ansible internal ... I just do not know how to better describe this. |
A colleague of mine just identified #28231 which seems to have addressed this in Ansible 2.3 in 2018 already and it seems to be related to In line 11 of main.yml, I do this:
From my understanding, from there
This works fine! But using the same variable in the shell - task below (in line 9 of sub_task.yml), results in this issue:
And now it comes: If
How to call this anything else but a bug??? |
Same effect with
|
Found a workaround: If the random element is picked and assigned to a fact in a YAML file which is executed using roles/test/tasks/get_random_element.yml: ---
- name: take 'list' and return a single element from it 'elem'
set_fact:
elem: "{{ list|random }}"
... roles/test/tasks/main.yml: ---
- name: get random element from groups[my_group_name]
include_tasks: get_random_element.yml
vars:
list: "{{ groups[my_group_name] }}"
- name: Main Level Task
include_tasks: sub_task.yml
vars:
my_execution_node: "{{ elem }}"
... |
Summary
Under reproducible circumstances, Ansible seems to randomly have issues resolving variables. I provided a demo to show the behavior.
Issue Type
Bug Report
Component Name
delegate_to
Ansible Version
Configuration
OS / Environment
Manager node OSes: MacOS, Ubuntu
Node OS (Destinations): Debian
Steps to Reproduce
A complete Ansible setup to reproduce the issue, along with the outputs from an affected run in the README, can be found on this extra provided Repo: https://github.com/The-Judge/ansible-delegate-demo
Expected Results
I expect that ansible is resolving all variables passed to it and does not come up with something half-resolved like:
Failed to connect to the host via ssh: ssh: Could not resolve hostname inventory_hostname: Name or service not known
whereinventory_hostname
is used as a hostname half way.Actual Results
fatal: [sbsdevcore01 -> sbsdevcore02]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: ssh: Could not resolve hostname inventory_hostname: nodename nor servname provided, or not known", "unreachable": true}
Code of Conduct
The text was updated successfully, but these errors were encountered: