Printing items in a file using lineinfile/blockinfile

45 views
Skip to first unread message

Akshay Kumar

unread,
Feb 8, 2021, 9:53:38 AM2/8/21
to Ansible Project
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]

vinoth kumar

unread,
Feb 8, 2021, 12:30:36 PM2/8/21
to ansible...@googlegroups.com

You shoul provide the output of testing . Is it variable or register . Give us some more info

//v
--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/ecc3dfa5-b963-4cc4-9976-acc28196f4fbn%40googlegroups.com.

Akshay Kumar

unread,
Feb 8, 2021, 3:16:41 PM2/8/21
to Ansible Project
Hi Vinod,

Its a  list variable containing SQL statement outputs for 2-3 statements .
Thanks.
Reply all
Reply to author
Forward
0 new messages