首页 > 解决方案 > 如何用ansible playbook替换具有多个特殊字符的行

问题描述

尝试替换具有多个特殊字符的行,这些特殊字符被 ansible 解释为转义字符。

尝试使用“\”和“。” 对于每个角色,并尝试使用!不安全。

- name: Update file
  replace:
    path: /some/file
    regexp: "*[0-9a-zA-Z._-]* )" #<<=== This is line to be replaced
    replace: "*[0-9a-z._-]* )"   #<<== With this
    backup: yes

收到如下错误:

raise error, v # invalid expression\r\nsre_constants.error: nothing to repeat\r\n", "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error", "rc": 1}

标签: ansibleescaping

解决方案


试过这个,它工作:

regexp: '\*\[0-9a-zA-Z\._-\]\* \)'
replace: '*[0-9a-z._-]* )'

推荐阅读