ansible - 如果文件有不同的值则更新它们,否则忽略
ansible - If files has different values then update them, otherwise ignore
几周来我一直在努力让这个逻辑正确..我想做的是创建一个 ansible playbook,它将我的应用程序安装在远程主机上......我有一点工作......
现在的问题是,就像所有应用程序安装一样,这意味着我需要进行健全性检查并确保我的配置正确。
我正在努力解决的一件事是,如果我有大量文本(比如下面的文本,我需要确保其中的值是正确的
我正在使用 Ansible Replace 和 Lineinfile 模块做其他事情,但我认为将它们用于我正在尝试解决的这个问题是不正确的...有没有其他人做过类似的事情如果你有一个查看文件的剧本,只有当值不正确时才更新它
<Set name="env"><SystemProperty name="address" default="0.0.0.0"/></Set>
<Set name="port"><SystemProperty name="https" default="6328" /></Set>
<Set name="idle">3</Set>
<Set name="soLingerTime"><Property name="http" default="-1568"/></Set>
<Set name="acceptorDelta"><Property name="ssol" default="9524"/></Set>
<Set name="PriorityDelta"><Property name="ssl34" default="9635"/></Set>
<Set name="Size">15874</Set>
优雅的解决方案可能只是用 {{ variables }} 替换值,然后让 ansible 使用 template module. If your files adhere to some kind of standard (the example looks like XML?), can you use the xml 模块写入正确的值?
否则,是的,我也想不出比 lineinfile/replace 更好的主意了..
编辑以添加 xml 示例:
我不是 xpath 专家,但我想像这样的东西会(有点)工作..
- hosts: localhost
tasks:
- name: Sanity Checks
xml:
path: file.xml
xpath: /Set[@name='port']/SystemProperty[@name='https']
attribute: default
value: "1000"
要实现我最想做的事情就是使用模板....获取新文件,根据需要更新....将它们保存在模板中并移动....
几周来我一直在努力让这个逻辑正确..我想做的是创建一个 ansible playbook,它将我的应用程序安装在远程主机上......我有一点工作......
现在的问题是,就像所有应用程序安装一样,这意味着我需要进行健全性检查并确保我的配置正确。
我正在努力解决的一件事是,如果我有大量文本(比如下面的文本,我需要确保其中的值是正确的
我正在使用 Ansible Replace 和 Lineinfile 模块做其他事情,但我认为将它们用于我正在尝试解决的这个问题是不正确的...有没有其他人做过类似的事情如果你有一个查看文件的剧本,只有当值不正确时才更新它
<Set name="env"><SystemProperty name="address" default="0.0.0.0"/></Set>
<Set name="port"><SystemProperty name="https" default="6328" /></Set>
<Set name="idle">3</Set>
<Set name="soLingerTime"><Property name="http" default="-1568"/></Set>
<Set name="acceptorDelta"><Property name="ssol" default="9524"/></Set>
<Set name="PriorityDelta"><Property name="ssl34" default="9635"/></Set>
<Set name="Size">15874</Set>
优雅的解决方案可能只是用 {{ variables }} 替换值,然后让 ansible 使用 template module. If your files adhere to some kind of standard (the example looks like XML?), can you use the xml 模块写入正确的值?
否则,是的,我也想不出比 lineinfile/replace 更好的主意了..
编辑以添加 xml 示例:
我不是 xpath 专家,但我想像这样的东西会(有点)工作..
- hosts: localhost
tasks:
- name: Sanity Checks
xml:
path: file.xml
xpath: /Set[@name='port']/SystemProperty[@name='https']
attribute: default
value: "1000"
要实现我最想做的事情就是使用模板....获取新文件,根据需要更新....将它们保存在模板中并移动....