ansible - Ansible 替换单引号正则表达式
问题描述
我在ansible中有以下尝试:
---
- name: Replace string nulls with php nulls in config
ansible.builtin.replace:
path: "{{ app_root_path }}/config/autoload.local.php"
regexp: "\'''null\'''"
replace: 'null'
backup: yes
要实现这个正则表达式:
为了改变:
'host' => 'null',
'user' => 'null',
'password' => 'null',
至:
'host' => null,
'user' => null,
'password' => null,
我试过了:
-
regexp: "\''null\''"
-
regexp: "\'null\'"
-
regexp: "''null''"
这些都没有,到目前为止我发现的任何其他东西都没有奏效。
在 YAML 范围内实现这一点的正确方法是什么?
解决方案
您必须将反斜杠加倍,而不是引号。
在 YAML 中,文本标量可以用引号括起来,从而启用转义序列,例如
\n
表示新行、\t
表示制表符和\\
表示反斜杠。
来源:https ://yaml.org/spec/history/2001-08-01.html#sec-concept
任务:
- name: Replace string nulls with php nulls in config
ansible.builtin.replace:
path: "{{ app_root_path }}/config/autoload.local.php"
regexp: "\\'null\\'"
replace: 'null'
backup: yes
会给:
'host' => null,
'user' => null,
'password' => null,
推荐阅读
- c# - 无法在 ASP .NET Core 中可视化 chartJS 数据
- php - (CRUD) 如何从 html 行中知道要定位哪些数据库记录
- firebase - 在前端生成文档 ID - 这是一种不好的做法吗?有哪些潜在的安全漏洞?
- node.js - 对 GCP VM.s 的安全 Socket.IO 访问
- python - python3 venv中自动安装pysvn
- python - 重复段的索引值列表
- ios - 我们能否仅在键盘上方显示建议 OTP 并在 Swift/IOS 中隐藏键盘部分
- python - 如何将列表框项目的名称转换为 Python 中的标签
- python - 无法通过cmd执行包含python代码的word文档
- google-sheets - 在一个单元格中添加数据验证和公式