Below is the playbook using "for command".
Playbook:
- name: "Fetch the ip of all the servers from hosts.new file"
shell: for i in `awk '{print $1}' hosts.new`
do echo "$i"
done
args:
chdir: "/home/dp794d/"
failed_when: "output.rc > 1"
register: output
- debug: msg="{{ output.stdout }}"
Actual output :
PLAY [myserver]
****************************************************************
TASK [setup]
*******************************************************************
ok: [zlp12037]
TASK [Fetch the ip of all the servers from hosts.new file]
*********************
changed: [zlp12037]
TASK [set_fact]
****************************************************************
ok: [zlp12037]
TASK [debug]
*******************************************************************
ok: [zlp12037] => {
"output.stdout": ""
Expected output :
12.82.240.174
12.82.240.166
12.82.224.62
12.82.224.70
--
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 post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/d723c08a-32c5-417e-9433-d3865885409c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.