Hi All,
I am currently working on a playbook where in i need to write the output of SQL statement into a file .
I have 4 SQL statement and 4 hosts thus want the output in such a way that:
1st host
SQL1 output
SQL2 Output
SQL3 output
SQL4 Output
2nd host … and so on
Currently i am using this code:
- name: trying something new
lineinfile:
line: “{{ item }}”
path: “{{ VlclFile }}”
insertafter: EOF
loop: “{{ testing }}”
delegate_to: localhost
which gives output in the format as i want for eg:
xxx:xxVC1:user: control_file_record_keep_time integer 365
yyy:yyy:user: control_file_record_keep_time integer 365
but the output comes in a random order and thus statement 1 output for host 1 is followed by statement 1 for host 2 and not statement 2 of host 1.
Anyone can help me with this .
Other block of code which i tried is as followed:
#- name: Add output of task for getting content to the local
local_action:
module: blockinfile
path: “{{ VlclFile }}”
marker: “”
state: present
block: “{{ hostvars[item][‘testing’]}}”
insertafter: EOF
run_once: True
with_items:
- “{{ play_hosts }}”
but in this its giving me output in the form of a list and not items per se eg:
host1
[a: value 1,b:value2]
host2
[a: value 1,b:value2]