Please provide the playbook AND the actual output from running the playbook so 
we can see which task produces which output.

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123

On Sep 30, 2022, at 4:01 PM, Vichu 
<[email protected]<mailto:[email protected]>> wrote:

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
On Saturday, October 1, 2022 at 1:12:48 AM UTC+5:30 
[email protected]<http://nist.gov> wrote:
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".

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123<tel:(202)%20355-4123>
On Sep 30, 2022, at 3:34 PM, Vichu <[email protected]> wrote:

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.
On Saturday, October 1, 2022 at 12:50:02 AM UTC+5:30 
[email protected]<http://nist.gov/> wrote:
- hosts: pocansibletest

This absolutely IS your inventory host. delegate_to and connection: local only 
tell ansible where to run. They do not affect the "inventory".

Walter
--
Walter Rowe, Division Chief
Infrastructure Services, OISM
Mobile: 202.355.4123<tel:(202)%20355-4123>

On Sep 30, 2022, at 3:15 PM, Vichu <[email protected]> wrote:

Below is the ansible version am using and giving out issue

ansible [core 2.13.4]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/rundeck/.ansible/plugins/modules', 
'/usr/share/ansible/plugins/modules']
  ansible python module location = 
/usr/local/lib/python3.8/dist-packages/ansible
  ansible collection location = 
/home/rundeck/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/local/bin/ansible
  python version = 3.8.10 (default, Jun 22 2022, 20:18:18) [GCC 9.4.0]
  jinja version = 3.1.2
  libyaml = True

Also to confirm the playbook gives appropriate hostnames on ansible v2.7
ansible 2.7.18.post0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', 
u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.5 (default, Nov 16 2020, 22:23:17) [GCC 4.8.5 20150623 
(Red Hat 4.8.5-44)]

Thanks & Regards,
Vichu
On Friday, September 30, 2022 at 11:10:11 PM UTC+5:30 Vichu wrote:
Hi Team,

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 }}"

Thanks & Regards,
Vichu

--
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/6fa83903-211a-4e27-8649-0954a2751fc6n%40googlegroups.com<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F6fa83903-211a-4e27-8649-0954a2751fc6n%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7C86b1aa72967449e8654108daa31e919f%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638001648931157840%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=N%2FE0BYNa6ZFRM9QYyMPKbq94NwG6bKkA7YfooMOYGz8%3D&reserved=0>.


--
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/913e3b8e-8a2b-4e84-8bde-d6336ddfb32en%40googlegroups.com<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2F913e3b8e-8a2b-4e84-8bde-d6336ddfb32en%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7C86b1aa72967449e8654108daa31e919f%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638001648931157840%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=9BqjhkQ2xrnJdEmxZTNg7Hj0mF9nGIgq579Hyp8IF8E%3D&reserved=0>.


--
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
[email protected]<mailto:[email protected]>.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/eb38d917-ed6b-47a6-ab05-6bb67883edaan%40googlegroups.com<https://gcc02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgroups.google.com%2Fd%2Fmsgid%2Fansible-project%2Feb38d917-ed6b-47a6-ab05-6bb67883edaan%2540googlegroups.com%3Futm_medium%3Demail%26utm_source%3Dfooter&data=05%7C01%7Cwalter.rowe%40nist.gov%7C86b1aa72967449e8654108daa31e919f%7C2ab5d82fd8fa4797a93e054655c61dec%7C1%7C0%7C638001648931157840%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=tzAdG0Zy2vqwEyNcNbEThokrbfKBnXwvBVgzUvX7kys%3D&reserved=0>.

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/7690D5E8-ADDF-4D2F-B456-A4FBEABEF2E7%40nist.gov.

Reply via email to