ansible 使用if判断 生成不同的配置文件(ansible if)
[root@ansible ansible]# cat keepalived.conf.j2
global_defs {
router_id {{ ansible_hostname }}
}
vrrp_instance VI_1 {
{% if ansible_fqdn == "lb01" %} # 如果hostname名称为lb01
state MASTER # 则配置为 MASTER和优先级150
priority 150
{% else %} # 否则生成下面的两条配置
state BACKUP
priority 100
{% endif %}
interface eth0
virtual_router_id 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.3
}
}
欢迎来撩 : 汇总all