是否可以使用 Ansible 合并(通过自动解决冲突)2 个配置文件?
例如,
// c1.conf
A=20
B="Hello"
D=24
// c2.conf
X=30
A=20
B="Hello2"
C=31
E=33
//output.conf
X=30
A=20
B="Hello" # In case of update, give priority to c1.conf
C=31 # In case of add/delete, give priority to c2.conf
E=33
声明文件列表
files:
- /tmp/c2.conf
- /tmp/c1.conf
并且吃掉它们
- slurp:
src: "{{ item }}"
loop: "{{ files }}"
register: out
然后,声明
result: "{{ out.results | map(attribute='content')
| map('b64decode')
| map('community.general.jc', 'ini')
| combine }}"
给予
result:
A: '20'
B: Hello
C: '31'
D: '24'
E: '33'
X: '30'