title: using for loop in ansible to fetch the ip address from a file kept on host server and ping to those ip servers to check wether those are alive or not
body: <p>I need to write ansible playbook, to fetch the ip address from the notepad file placed on the host server.I need to write an playbook which will iterate to the notepad file and provide me ip address. Further i will use ping command to check wether those servers are alive or not. Please suggest how can i write the playbook which will iterate to one notepad file placed on the host, pick up the ip address and ping it to check wether that ip is alive or not.</p>
  
  <p>these are the details of notepad file placed on the host server.</p>
  
  <pre><code>12.82.240.174   wnaca3012is #CLLI
  12.82.240.166   ok3ca3022is #CLLI
  12.82.224.62    dsail301is  #CLLI
  12.82.224.70    prail301is  #CLLI
  </code></pre>
  
  <blockquote>
    <p>below the playbook</p>
  </blockquote>
  
  <pre><code>- name: "Fetch the ip of all the servers from hosts.new file"
    command: for i in `awk '{print $1}' hosts.new`
              do echo "$i"
              done
    args:
      chdir: "/home/dp794d/"
    failed_when: "output.rc &gt; 1"
    register: output
  </code></pre>
  
  <blockquote>
    <p>Error are -</p>
  </blockquote>
  
  <pre><code>fatal: [zlp12036]: FAILED! =&gt; {"changed": false, "cmd": "for i in '`awk' '{print $1}' 'hosts.new`' do echo '$i' done", "failed": true, "failed_when_result": true, "msg": "[Errno 2] No such file or directory", "rc": 2}
  </code></pre>
  
  <p>fatal: [zlp12037]: FAILED! => {"changed": false, "cmd": "for i in '<code>awk' '{print $1}' 'hosts.new</code>' do echo '$i' done", "failed": true, "failed_when_result": true, "msg": "[Errno 2] No such file or directory", "rc": 2}</p>