我正在尝试编写一个角色来配置一个 keepalived 集群。我希望根据目标框的 IP 将唯一信息传递到模板中。
在这种情况下:服务器 A 是 192.168.1.140,服务器 B 是 192.182.1.141,VIP 是 192.168.1.142
字典看起来像这样:
---
192.168.1.140:
peer: 192.168.1.141
priority: 110
vip: 192.168.1.142
192.1.168.1.141
peer:192.168.1.140
priority: 100
vip: 192.168.1.142
我希望任务看起来像这样:
---
- name: keepalived template
template:
src: keepalived.j2
dest: /etc/keepalived/keepalived.conf
owner: root
group: root
mode: 0644
with_dict: '{{ ansible_default_ipv4.address }}'
模板看起来像这样:
}
vrrp_instance VI_1 {
interface eth0
priority {{ item.value.priority }}
...
unicast_scr {{ ansible_default_ipv4.address }}
unicast_peer {
{{ item.value.peer }}
}
virtual_ipaddresses {
{{ item.value.vip }} }
}
任何见解将不胜感激约翰