I am using the loop in ansible by “with_lines”, in which i am fetching the ip address of all the servers, on which i need to run the command. I need to fetch theid_rsa.pub files details from the server and store them into the file on my localhost. I need to append the output of all the id_rsa.pub keys, so that i will have the list of all those files on single place.
Currently I am able to fetch the value of id_rsa.pub file but i am not able to display the same using “debug”.
If i use r.results[0].stdout, then it gives the id_rsa.pub value for the first ip, but i need this to be in loop. I am stucked up in that point.
I tried below this, but it do not works, i am not sure how to use “item” with debug mode
- How can the debug thing can be in the loop
- How can i append the result of the debug using the loop in the below mentioned file.
Any quick help will be really appreciated, thanks in advance.
-
hosts: localhost
tasks: -
name: “fetch id_rsa.pub files data”
shell: ssh dp794d@{{ item }} “cat /home/dp794d/.ssh/id_rsa.pub”
register: r
with_lines: cat “/home/capio/ansible/pmossWipm/day1/logs/testIP.txt” -
debug: msg=“r.results[{{item}}].stdout”
with_lines: cat “/home/capio/ansible/pmossWipm/day1/logs/testIP.txt” -
name: “Append the output of username to LLC_LIST File”
lineinfile:
dest: /home/capio/file
line: “{{ r.results[{{item}}].stdout }}”