Regex Ansible replace命令
我想在Regex Ansible replace命令,regex,ansible,Regex,Ansible,我想在/home/oracle/.bash\u profile中用export PS1=“\[$highred\][${xx\u sid}@\h\W]\[$normalr\]\$”替换export PS1=“$highred[${xx\u sid}@\h\W]\[$normalr\]\$” Playbook运行良好,没有任何错误,但没有进行任何更改。Ansible版本2.5.2 以下是剧本: --- - name : 'vj' hosts : 'all'
/home/oracle/.bash\u profile
中用export PS1=“\[$highred\][${xx\u sid}@\h\W]\[$normalr\]\$”
替换export PS1=“$highred[${xx\u sid}@\h\W]\[$normalr\]\$”
Playbook运行良好,没有任何错误,但没有进行任何更改。Ansible版本2.5.2
以下是剧本:
---
- name : 'vj'
hosts : 'all'
gather_facts : 'false'
tasks :
- name : 'replace line'
replace :
path : '/home/oracle/.bash_profile'
regexp : "export PS1=\"$highred[${xx_sid}@\\h \\W]$normalr$\""
replace : "export PS1=\"\\[$highred\\][${xx_sid}@\\h \\W]\\[$normalr\\]\\$ \""
backup : yes
以下是调试模式输出:
"changed": false,
"invocation": {
"module_args": {
"after": null,
"attributes": null,
"backup": true,
"before": null,
"content": null,
"delimiter": null,
"directory_mode": null,
"encoding": "utf-8",
"follow": false,
"force": null,
"group": null,
"mode": null,
"owner": null,
"path": "/home/oracle/.bash_profile",
"regexp": "export PS1=\"$highred[${xx_sid}@\\h \\W]$normalr$\"",
"remote_src": null,
"replace": "export PS1=\"\\[$highred\\][${xx_sid}@\\h \\W]\\[$normalr\\]\\$ \"",
"selevel": null,
"serole": null,
"setype": null,
"seuser": null,
"src": null,
"unsafe_writes": null,
"validate": null
}
},
"msg": ""
}
META: ran handlers
META: ran handlers
感谢专家的任何输入。如果您获得
ok
状态,则表示未找到regexp
参数中指定的正则表达式
因为正则表达式语法使用了诸如$
,[
,\
之类的字符,所以找不到它
要匹配所需的字符串,应指定:
regexp: export PS1="\$highred\[\${xx_sid}@\\h \\W\]\$normalr\$"
顺便说一句,不需要引用整个字符串。如果这样做,那么它会变得更复杂:
regexp: "export PS1=\"\\$highred\\[\\${xx_sid}@\\\\h \\\\W\\]\\$normalr\\$\""
如果获得
ok
状态,则表示未找到regexp
参数中指定的正则表达式
因为正则表达式语法使用了诸如$
,[
,\
之类的字符,所以找不到它
要匹配所需的字符串,应指定:
regexp: export PS1="\$highred\[\${xx_sid}@\\h \\W\]\$normalr\$"
顺便说一句,不需要引用整个字符串。如果这样做,那么它会变得更复杂:
regexp: "export PS1=\"\\$highred\\[\\${xx_sid}@\\\\h \\\\W\\]\\$normalr\\$\""