用Ansible从文件中的Ansible STDOUT_LINES删除符号
A 文件 acounts.list 中有一行
['# name [email protected]', 'zimbraIsDelegatedAdminAccount: TRUE']
我想删除 ['# name
、所有 '
和 ']
结果会是什么[email protected], zimbraIsDeleeratedAdminAccount: TRUE
我尝试创建任务来删除第一个 ['# name
- lineinfile:
dest: /home/acounts.list
state: absent
regexp: "^\[\'\#\sname\s"
...但我得到了错误。您能帮忙解决吗?谢谢。
A have the line in file acounts.list
['# name [email protected]', 'zimbraIsDelegatedAdminAccount: TRUE']
I would like to remove ['# name
, all '
and ']
What would the result be [email protected], zimbraIsDelegatedAdminAccount: TRUE
I tried to create task to remove first ['# name
- lineinfile:
dest: /home/acounts.list
state: absent
regexp: "^\[\'\#\sname\s"
... but i got error. Could you please help with solution? Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用替换代替:
你也可以写:
regexp: '[''\[\]]|# *name *'
['\\[\\]]
表示替换所有'
或[
或]
(或 == []),因此 [ 和 ] 是特殊字符,您必须通过 < 进行保护code>\ 和
"
你必须保护\
也由另一个\
(当被 ' 包围时不需要)|
表示or
,另一个表达式是 < code># *name **
表示零个或多个空格use replace instead:
you could write too:
regexp: '[''\[\]]|# *name *'
['\\[\\]]
means replace all'
or[
or]
(or == [])so as [ and ] are special char, you ahve to protect by
\
with"
you have to protect\
too by another\
(not needed when surrounded by ')|
meansor
and the other expression is# *name *
*
means zero or more space