Reputation: 1
I want replace export PS1="$highred[${xx_sid}@\h \W]$normalr$"
with export PS1="\[$highred\][${xx_sid}@\h \W]\[$normalr\]\$ "
in /home/oracle/.bash_profile
.
Playbook is running fine without any error but its not doing any changes. Ansible version 2.5.2.
Below is playbook:
---
- 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
Here is debug mode output:
"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
Appreciate any inputs from experts.
Upvotes: 0
Views: 537
Reputation: 68439
If you get an ok
status, it means the regular expression specified in regexp
argument was not found.
And it was not found because regular expression syntax makes use of characters like $
, [
, \
.
To match the string you want, you should specify:
regexp: export PS1="\$highred\[\${xx_sid}@\\h \\W\]\$normalr\$"
BTW, there is no need to quote the whole string. If you do, then it gets more complicated:
regexp: "export PS1=\"\\$highred\\[\\${xx_sid}@\\\\h \\\\W\\]\\$normalr\\$\""
Upvotes: 2