Line in file

15 views
Skip to first unread message

Sivaraman P

unread,
May 11, 2020, 8:17:28 AM5/11/20
to Ansible Project
Hi All,

I am using Line in file nodule to write a list output in ansible to a file in the target machine.

Below is the code i have used.

hosts: localhost
tasks:
- lineinfile:
create: yes
regexp: "NONEXISTENTLINE"
dest: /projects/testing/check.txt
line : "{{item}}"
state: present
with_items:
- "{{something}}"

And that something is a list and its value is given below,

["WOAprofile1",
"WOAprofile2",
"WOAprofile3"]

When I am using the above line in file prints each value of the list in separate line.
But I need the output in the file as below,
WOAprofile1, WOAprofile2, WOAprofile3

Note: the number of lines in the variable "something" will be differ from server to server.


Stefan Hornburg (Racke)

unread,
May 11, 2020, 8:31:56 AM5/11/20
to ansible...@googlegroups.com
Change the line module parameter as below and drop the loop (with_items)

line: "{{ something | join(', ') }}

Regards
Racke

--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Sivaraman P

unread,
May 11, 2020, 8:54:20 AM5/11/20
to Ansible Project
Thank you for your assistance.
Reply all
Reply to author
Forward
0 new messages