[英]Find pattern and replace Ansible
I have a file test.xml This contain content like bellow我有一个文件 test.xml 这包含如下内容
<logger name="audit-log" level="${AUDIT_LEVEL:-OFF}" additivity="false">
<appender-ref ref="AUDIT-LOG-ASYNC"/>
I wanna use ansible to replace level="${AUDIT_LEVEL:-OFF}" ==> level="something".我想用 ansible 来替换 level="${AUDIT_LEVEL:-OFF}" ==> level="something"。 My ansible code like this but it doesn't work.
我的 ansible 代码是这样的,但它不起作用。
tasks:
- name: Ansible replace string example
replace:
path: test.xml
regexp: '"${AUDIT_LEVEL:-OFF}"'
replace: '"something"'
Please help me.请帮我。 Thank.
感谢。
you can use lineinfile你可以使用lineinfile
for example:例如:
- name: set APP_URL
lineinfile: dest=/file_path regexp='level="${AUDIT_LEVEL:-OFF}"' line=level=something
I suggest defining the values to be changed first as a variable and then using it in the lineinfile
field.我建议首先将要更改的值定义为变量,然后在
lineinfile
字段中使用它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.