Thanks . It worked as expected 

On Tuesday, June 20, 2023 at 1:46:19 AM UTC+5:30 Dick Visser wrote:

> On Mon, 19 Jun 2023 at 21:37, Veera <[email protected]> wrote:
>
>> Yes.. It's basically another yaml file. 
>>
>> I'm asking because string manipulation of otherwise structured data will 
> become messy quickly - as you have found out.
> If you must keep all the comments then you'll have to use logic to handle 
> that.
> Whenever someone edits the file, or by some software update, your logic 
> might break.
> I would either template the entire thing out, based on a config that you 
> have in your ansible code.
> Or, use a combination of slurp and write out the structure. This will 
> remove any comments, but one could argue that that is not required anyway.
> For example:
>
>   vars:
>     filename:* /etc/myagent/myfile*
>     config_opts:
>       logging.files:
>         path: /var/log/newfile
>
>   tasks:
>     - slurp:
>         src: "{{ filename }}"
>       register: foo
>
>     - set_fact:
>         foo: "{{ foo.content | b64decode | from_yaml | 
> combine(config_opts) }}"
>
>     - copy:
>         content: "{{ foo | to_nice_yaml }}"
>         dest: "{{ filename }}"
>
>

-- 
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/88283545-d526-4cc5-8106-3abb1c2dd51cn%40googlegroups.com.

Reply via email to