Closed cortadosaxophone closed 2 weeks ago
Files identified in the description:
If these files are incorrect, please update the component name
section of the description or use the component bot command.
Also note that this fails the same way with this:
vars:
ansible_user: “{{ item.user }}”
please show the -vvv
output of the error
Closing this as it is a duplicate of at least #16776. Sorry to be of any trouble. Thank you for reaching out @bcoca. This is working as designed, and I found a solution to my specific problem to accommodate existing org ansible structure (as in, within a task file called in a one-entry-point playbook:
# assume I have created a list of {user: some_user, host: some_host} dicts
- name: "use inventory to get mirror hosts"
ansible.builtin.add_host:
ansible_ssh_host: "{{ item.host }}"
ansible_ssh_user: "{{ item.user }}"
inventory_hostname: "{{ item.host }}"
groups: "mirror_hosts"
name: "{{ item.host }}"
loop:
"{{ mirror_config }}"
# run_once is called because this is a task in a playbook using N hosts
- name: "do something with group"
ansible.builtin.file:
path: "/home/{{ ansible_ssh_user }}/touchfile.txt"
state: "touch"
mode: "0644"
loop:
"{{ groups['mirror_hosts'] }}"
run_once: true
delegate_to: "{{ item }}"
A colleague also sent this to me this morning: https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_delegation.html#templating-in-delegation-context
Summary
I am trying to run a small set of commands that override the playbook's normal user and nodes, using a list of dictionaries. While I can loop through and assign
item.host
todelegate_to
, I am unable to assignitem.user
toremote_user
. The play terminates withitem is undefined
.Issue Type
Bug Report
Component Name
ssh
Ansible Version
Configuration
OS / Environment
RHEL 8.6
Steps to Reproduce
Expected Results
Note that this is output when I set
remote_user
to a value.Actual Results