我正在使用ansible查找和替换模块的组合来更改某些xml文件中的字符串。任务运行正常,但字符串未被替换。
任务如下所示:
- name: Find common module config files
find:
paths: "/etc/app/common/"
patterns: "*.xml"
register: commonConfigs
- name: Set compress to false in common modules
become: yes
replace:
path: "{{item.path}}"
regexp: "<compress>true"
replace: "<compress>false"
with_items: "{{ commonConfigs.files }}"我认为regexp可能是问题所在,所以我尝试了/<compress>true/g,但这也无济于事。如果我把这里的一些术语搞混了,我对ansible来说是很新的,所以道歉。谢谢你的帮助
编辑:
下面是xml的哪些部分
<appConfig>
<ui>
<compress>true</compress>
</ui>
<appConfig>发布于 2020-09-25 16:05:28
在没有xml文件示例的情况下,我的猜测是,由于缩进,当前搜索的字符串实际上不会从行的开头开始。
此外,您还应该将行的末尾简化,并将其写回,以确保不丢失任何内容:
regexp: "(\s+<compress>)true(.*)"
replace: "\1false\2"同时,当有一个可以精确地用于replace的xml module时,我不会依赖于xml module进行这样的更改。
https://stackoverflow.com/questions/64067029
复制相似问题