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/CAF8BbLZiZB_x3SZmMXEdR_oYJva7KqYA6AX%2BizjT7piUPguYHw%40mail.gmail.com.