ansible - Insert a block of file in a xml -
i want insert block of file xml using ansible.
ex.xml
<t1> ${t1}/k</t1> <v1 c="k.tm"/>
i need insert block of code between (i.e after <t1> ${t1}/k</t1>
) per ex.xml
can on this?
i tried using block in file ended adding block of code @ end of xml.
- name: add block blockinfile: path: ex.xml marker: "test" block: <k1></k1> <k2></k2> insertafter: "^<t1> ${t1}/k</t1>"
the insertafter
parameter regular expression '$' character won't match directly. you'll need escape it.
insertafter: "^<t1> \\${t1}/k</t1>"
a couple of other notes...
if want block inserted you've written newlines, add pipe right after block
. otherwise entire block written same line
block: | <k1></k1> <k2></k2>
the marker
parameter should xml comment. should include {mark}
keyword ansible knows not insert same block if exists in ex.xml.
marker: "<!-- {mark} ansible managed block -->"
Comments
Post a Comment