ansible - 使用ansible替换xml文件中的一行
问题描述
请在这里为我提供指导。
我想在一个配置文件中注释一行,并且需要使用 ansible 取消注释另一行。
我的文件内容如下。
`<include location="conf/basicUserRegistry.xml"/>`
this i want to comment
`<!--include location="conf/ldapUserRegistry.xml"/-->`
this line i want to uncomment
我尝试使用下面的剧本,即使它没有更改对文件的任何更改,它也没有显示任何错误。
- name: enable LDAP
hosts: localhost
tasks:
- name: disbale basic user-registry
lineinfile:
path: /opt/IBM/605CLM/JazzTeamServer/server/liberty/servers/clm/server.xml
regexp: '^\s*<include location="conf/basicUserRegistry.xml">.*$'
line: '<!--include location="conf/basicUserRegistry.xml"-->;'
backrefs: yes
become: true
- name: enable LDAP USER_REGISTRY
hosts: localhost
tasks:
lineinfile:
dest: /opt/IBM/605CLM/JazzTeamServer/server/liberty/servers/clm/server.xml
regexp: '^(.*)<!--include location="conf/ldapUserRegistry.xml"-->(.*)$'
line: '<include location="conf/ldapUserRegistry.xml">;'
backrefs: yes
输出:
播放 [启用 LDAP] ********************************************* ****************************************************** *******************************************
任务[收集事实] ************************************************ ****************************************************** ****************************************** 好的:[本地主机]
任务 [禁用基本用户注册表] ****************************************** ****************************************************** ****************************** 好的:[本地主机]
播放回顾 ************************************************ ****************************************************** ************************************************ 本地主机:确定=2 更改=0 无法访问=0 失败=0
解决方案
可以说解决这个问题的更清洁的方法是使用Ansiblexml
模块。
示例(假设您的示例显示了完整的文件):
tasks:
- xml:
file: server.xml
xpath: /include
attribute: location
value: conf/ldapUserRegistry.xml
推荐阅读
- ruby-on-rails - Heroku Ruby Application Error(Missing helper file helpers?)
- reactjs - 如何使我的 JWT 令牌浏览器特定于防止被盗令牌的访问?
- ansible - 与主机的共享连接在以非特权用户身份运行 Ansible 剧本时关闭?
- php - 为邮件正文 PHP 输入新行
- python - 返回类型必须是字符串、字典、元组、响应实例或 WSGI 可调用,但它是 TypeError
- java - 在 WSO2 身份服务器中创建工作流时出错 (wso2is-km-5.9.0)
- java - 从一个 ActionEvent 多次调用方法
- jestjs - 如何在 JEST 测试中保留所有测试套件访问的单个变量(访问令牌)?
- java - 如何使用与 Coldfusion 加密相同的 Android AES 加密
- android - 如何使用 Flutter 根据从数据库中获取的值自动更新文本?