JINJA2 模板 – keepalived
Ansible 部署 keepalived的时候,想要使用JIANJA2模板来实现。
建议直接使用角色来部署:
ansible-galaxy search mrlesmithjr.keepalived
以下是角色中模板的内容:
`{{ ansible_managed|comment }}
{% if keepalived_config|bool %}
{% if keepalived_router_info is defined %}
{% for item in keepalived_router_info %}
{% if item.check_script is defined %}
{% for chk in item.check_script %}
vrrp_script {{ chk.name }} {
script “{{ chk.script }}”
interval {{ chk.interval }}
weight {{ chk.weight }}
}
{% endfor %}
{% endif %}
vrrp_instance {{ item.name }} {
interface {{ item.vip_int }}
{% if inventory_hostname == item.master_node %}
state MASTER
priority {{ item.router_pri_master }}
{% elif inventory_hostname != item.master_node %}
state BACKUP
priority {{ item.router_pri_backup }}
{% endif %}
virtual_router_id {{ item.router_id }}
virtual_ipaddress {
{% for ip in item.vip_addresses %}
{{ ip }}
{% endfor %}
}
{% if item.check_script is defined %}
{% for chk in item.check_script %}
track_script {
{{ chk.name }}
}
{% endfor %}
{% endif %}
{%- if item.nopreempt is defined and item.nopreempt %}
nopreempt
{% endif -%}
{% if item.use_unicast is defined and item.use_unicast %}
unicast_src_ip {{ unicast_src_ip }}
{% for peer in unicast_peers %}
unicast_peer {
{{ peer }}
{% endfor -%}
}
{% endif %}
{% if item.auth_pass is defined %}
authentication {
auth_type PASS
auth_pass {{ item.auth_pass }}
}
{% endif %}
}
{% endfor %}
{% endif %}
`