Good Day!! Am not able to use Connection: local and Delegate_to together in my playbooks.
Actual Result - Both debug outputs give me the same hostname. Expected Result: First debug should have given me the localhost hostname and second debug should have given me the “pocansibletest” as per the playbook. But doesnt work as expected.
Playbook:
hosts: pocansibletest
connection: local
become: false
remote_user: admin
tasks:
name: Set VM_Name as fact
set_fact:
vm_name: “{{ inventory_hostname }}”
name: Test host name without delegation
shell: hostname
register: name_without_del
name: Debug host name without delegation
debug:
msg: “Debug host name without delegation - {{ name_without_del.stdout }}”
name: Test host name with delegation
delegate_to: “{{vm_name}}”
shell: hostname
register: name_with_del
name: Debug host name with delegation
debug:
msg: “Debug host name with delegation - {{ name_with_del.stdout }}”
Yes your are right but the below task does not give the hostname of “pocansibletest” and gives the hostname of the localhost itself in ansible v6. But the same works perfectly on ansible v2.7 without any changes to playbook.
name: Test host name with delegation
delegate_to: “{{vm_name}}”
shell: hostname
register: name_with_del
The requirement for me is to run many tasks on localhost and delegate some tasks to remote hosts using delegate_to directive. But with ansible v6 its always executing on localhost and I see inappropriate behaviour and failures.
You set_fact vm_name to inventory_hostname in the first task. This assigns “pocansibletest” to vm_name. If you then delegate_to vm_name you are delegating to “pocansibletest”.
The connection: local doesn’t factor into this. All tasks are still operating on the inventory “pocansibletest”.
Yes you are right, thats my understanding, but what output I get is the hostname where the ansible playbook has triggered. So its not working as expected with Ansible V6