On 19.03.2019 20:09, Saranya N wrote:
> I'm having a text file with lots of strings like below.
>
> Cat test.txt
> String1
> String2
> .
> .
> .
> Etc
>
> I literally have 2k of strings on that file.
>
> I want to convert to yank like below.
>
> _ _ _
>
> Listofstrings:
> - string1
> - string2
>
> ...etc
>
>
> I can achieve this via shell script but is there an ansible way of doing it
> using lineinfile or anything else?
>
> I know I can achieve via jinja2 tempalte as well but I don't know how to
> loop over the strings in the text file in j2 template.
You can create a variable with the list like so
- set_fact:
listofstrings: '{{ listofstrings | default([]) + [item] }}'
with_lines: cat test.txt
and then you can do all sort of thing with the variable listofstrings in
Ansible.
--
Kai Stian Olstad
--
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/ae70bfbe-7a63-28e0-53e9-fb7fa7a74470%40olstad.com.
For more options, visit https://groups.google.com/d/optout.