Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex Ansible replace命令_Regex_Ansible - Fatal编程技术网

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\\$\""