Error in using delegate_to module

Hi Team,

Below is my "delegate_to" playbook

--- # delegate to
- hosts: webserver
user: test
sudo: yes
gather_facts: yes
connection: ssh
tasks:
- name: ping server
command: ping -c 4 172.25.10.102 > /home/test/ansible
delegate_to: 127.0.0.1
- name: install
command: yum install httpd -y

While running the above the playbook i'm getting the following error for my ping related task

TASK [ping server] ************************************************************************************************************
fatal: [172.25.10.102 -> 127.0.0.1]: FAILED! => {"changed": true, "cmd": ["ping", "-c", "4", "172.25.10.102", ">", "/home/test/ansible"], "delta": "0:00:00.005166", "end": "2018-12-30 23:15:50.544823", "msg": "non-zero return code", "rc": 2, "start": "2018-12-30 23:15:50.539657", "stderr": "ping: /home/test/ansible: Name or service not known", "stderr_lines": ["ping: /home/test/ansible: Name or service not known"], "stdout": "", "stdout_lines": []}
fatal: [172.25.10.101 -> 127.0.0.1]: FAILED! => {"changed": true, "cmd": ["ping", "-c", "4", "172.25.10.102", ">", "/home/test/ansible"], "delta": "0:00:00.005299", "end": "2018-12-30 23:15:50.544884", "msg": "non-zero return code", "rc": 2, "start": "2018-12-30 23:15:50.539585", "stderr": "ping: /home/test/ansible: Name or service not known", "stderr_lines": ["ping: /home/test/ansible: Name or service not known"], "stdout": "", "stdout_lines": []}
fatal: [172.25.10.107 -> 127.0.0.1]: FAILED! => {"changed": true, "cmd": ["ping", "-c", "4", "172.25.10.102", ">", "/home/test/ansible"], "delta": "0:00:00.004638", "end": "2018-12-30 23:15:50.576417", "msg": "non-zero return code", "rc": 2, "start": "2018-12-30 23:15:50.571779", "stderr": "ping: /home/test/ansible: Name or service not known", "stderr_lines": ["ping: /home/test/ansible: Name or service not known"], "stdout": "", "stdout_lines": []}
to retry, use: --limit @/home/test/ansible/playbook/delegatto.retry

I m using ansible v 2.7.5

  • post-author-pic
    John M
    01-02-2019

    I am not sure what you are trying to accomplish with the delegation. This ping should work. Try this:


    # Test we can logon to 'webservers' and execute python with json lib.

    # ansible webservers -m ping

    # Example from an Ansible Playbook

    - ping:

    # Induce an exception to see what happens

    - ping:

    data: crash


    Also, what is the ip address you are pinging? 

Looking For Team Training?

Learn More