Thanks all ..
I am able to get the desired output with templates ..
On Tuesday, August 1, 2023 at 11:04:35 AM UTC+5:30 Felix Fontein wrote:
> Hi,
>
> > Yes. Or if you feel like ignoring the warnings^* about using
> > variables in copy's "content":
> >
> > - name: Write to the file
> > ansible.builtin.copy:
> > content: |
> > {% for server in servers %}
> > {{ server }}
> > {% endfor %}
> > dest: "{{my_inv}}"
> >
> > ^* I do it quite often, looking for cases where the promised
> > unexpected surprises happen, but I haven't found them yet. It'll
> > probably happen some day when it least convenient. :)
>
> I got bitten by this somewhen in the past when the input for `content`
> turned out to be valid JSON. Ansible parsed it and converted it to the
> Python representation of the dictionary, which wasn't valid JSON
> anymore (`"` converted to `'`).
>
> But that's something rather special, for many simple templates such as
> yours it's no problem at all (and I also use `content` for that).
>
> Cheers,
> Felix
>
>
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/24cfe05d-7c60-4909-9dca-a016aba18723n%40googlegroups.com.