简体   繁体   中英

Find pattern and replace Ansible

I have a file test.xml This contain content like bellow

<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". My ansible code like this but it doesn't work.

    tasks:
      - name: Ansible replace string example
        replace:
          path: test.xml
          regexp: '"${AUDIT_LEVEL:-OFF}"'
          replace: '"something"'

Please help me. Thank.

you can use 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM