mirror of
https://gitea.0xace.cc/ansible-galaxy/keepalived.git
synced 2024-11-24 15:56:39 +00:00
fix template override
This commit is contained in:
parent
19476a0d84
commit
a9cc4a4f84
@ -1,3 +1,58 @@
|
|||||||
keepalived_config_override: []
|
keepalived_version: ""
|
||||||
keepalived_default_config: []
|
keepalived_default_config: {}
|
||||||
|
|
||||||
|
# Example with default template
|
||||||
|
#keepalived_config:
|
||||||
|
# global_defs:
|
||||||
|
# router_id: t1-dev-rabbitmq
|
||||||
|
# vrrp_track_process:
|
||||||
|
# haproxy:
|
||||||
|
# process: haproxy
|
||||||
|
# quorum: 1
|
||||||
|
# delay: 2
|
||||||
|
# vrrp_instance:
|
||||||
|
# VRRP_1:
|
||||||
|
# state: MASTER
|
||||||
|
# virtual_router_id: 50
|
||||||
|
# priority: "{{ ansible_default_ipv4.address.split('.')[-1][-2:] }}"
|
||||||
|
# interface: "{{ ansible_default_ipv4.interface }}"
|
||||||
|
# unicast_src_ip: "{{ ansible_default_ipv4.address }}"
|
||||||
|
# unicast_peer:
|
||||||
|
# - 10.89.10.71
|
||||||
|
# - 10.89.10.72
|
||||||
|
# - 10.89.10.73
|
||||||
|
# virtual_ipaddress:
|
||||||
|
# - "10.89.10.112/32 dev {{ ansible_default_ipv4.interface }}"
|
||||||
|
# track_process:
|
||||||
|
# - haproxy
|
||||||
|
|
||||||
|
# Example with config template override
|
||||||
|
#keepalived_config_override: |
|
||||||
|
# global_defs {
|
||||||
|
# router_id {{ patroni_cluster_name | default('default') }}
|
||||||
|
# }
|
||||||
|
# vrrp_track_process haproxy {
|
||||||
|
# process haproxy
|
||||||
|
# quorum 1
|
||||||
|
# delay 2
|
||||||
|
# }
|
||||||
|
# vrrp_instance VRRP_1 {
|
||||||
|
# state MASTER
|
||||||
|
# virtual_router_id {{ keepalived_vip.split('.')[-1][-3:] }}
|
||||||
|
# priority {{ ansible_enp3s0.ipv4.address.split('.')[-1][-3:] | default(ansible_default_ipv4.address.split('.')[-1][-3:]) }}
|
||||||
|
# interface {{ ansible_enp3s0.device | default(ansible_default_ipv4.interface) }}
|
||||||
|
# unicast_src_ip {{ ansible_enp3s0.ipv4.address | default(ansible_default_ipv4.address) }}
|
||||||
|
# unicast_peer {
|
||||||
|
# {% for peer in groups.patroni %}
|
||||||
|
# {{ hostvars[peer].ansible_enp3s0.ipv4.address if (hostvars[peer].ansible_enp3s0.ipv4.address != ansible_enp3s0.ipv4.address and hostvars[peer].ansible_enp3s0.ipv4.address != ansible_enp4s0.ipv4.address) }}
|
||||||
|
# {% endfor %}
|
||||||
|
# }
|
||||||
|
# virtual_ipaddress {
|
||||||
|
# {{ keepalived_vip }}/32 dev {{ keepalived_vip_dev }}
|
||||||
|
# }
|
||||||
|
# track_process {
|
||||||
|
# haproxy
|
||||||
|
# }
|
||||||
|
# }
|
||||||
|
|
||||||
keepalived_script_user: root
|
keepalived_script_user: root
|
||||||
|
@ -13,11 +13,11 @@
|
|||||||
register: keepalived_setup
|
register: keepalived_setup
|
||||||
|
|
||||||
- name: Template keepalived.conf
|
- name: Template keepalived.conf
|
||||||
when: keepalived_config_override is not defined
|
when: keepalived_config_override is not defined or keepalived_config_override | length < 0
|
||||||
block:
|
block:
|
||||||
- name: Merge config for keepalived
|
- name: Merge config for keepalived
|
||||||
set_fact:
|
set_fact:
|
||||||
keepalived_config: "{{ keepalived_default_config | combine(keepalived_config, recursive=true) }}"
|
keepalived_combined_config: "{{ keepalived_default_config | default({}) | combine(keepalived_config| default({}), recursive=true) }}"
|
||||||
|
|
||||||
- name: Add keepalived config
|
- name: Add keepalived config
|
||||||
template:
|
template:
|
||||||
@ -32,7 +32,9 @@
|
|||||||
dest: "/etc/keepalived/keepalived.conf"
|
dest: "/etc/keepalived/keepalived.conf"
|
||||||
notify:
|
notify:
|
||||||
- Restart keepalived
|
- Restart keepalived
|
||||||
when: keepalived_config_override is defined
|
when:
|
||||||
|
- keepalived_config_override is defined
|
||||||
|
- keepalived_config_override | length > 0
|
||||||
|
|
||||||
- name: Create dir for scripts
|
- name: Create dir for scripts
|
||||||
file:
|
file:
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
global_defs {
|
global_defs {
|
||||||
{% if keepalived_config.vrrp_script is defined %}
|
{% if keepalived_combined_config.vrrp_script is defined %}
|
||||||
enable_script_security
|
enable_script_security
|
||||||
script_user {{ keepalived_script_user }}
|
script_user {{ keepalived_script_user }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% for key, value in keepalived_config.global_defs.items() %}
|
{% for key, value in keepalived_combined_config.global_defs.items() %}
|
||||||
{% if value | type_debug != 'list' %}
|
{% if value | type_debug != 'list' %}
|
||||||
{{key}} {{value}}
|
{{key}} {{value}}
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -14,10 +14,10 @@ global_defs {
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
}
|
}
|
||||||
|
|
||||||
{% if keepalived_config.vrrp_script is defined %}
|
{% if keepalived_combined_config.vrrp_script is defined %}
|
||||||
{% for vrrp_script in keepalived_config.vrrp_script %}
|
{% for vrrp_script in keepalived_combined_config.vrrp_script %}
|
||||||
vrrp_script {{ vrrp_script }} {
|
vrrp_script {{ vrrp_script }} {
|
||||||
{% for key, value in keepalived_config.vrrp_script[vrrp_script].items() %}
|
{% for key, value in keepalived_combined_config.vrrp_script[vrrp_script].items() %}
|
||||||
{% if value | type_debug != 'list' %}
|
{% if value | type_debug != 'list' %}
|
||||||
{{key}} {{value}}
|
{{key}} {{value}}
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -30,10 +30,10 @@ vrrp_script {{ vrrp_script }} {
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% if keepalived_config.vrrp_track_process is defined %}
|
{% if keepalived_combined_config.vrrp_track_process is defined %}
|
||||||
{% for vrrp_track_process in keepalived_config.vrrp_track_process %}
|
{% for vrrp_track_process in keepalived_combined_config.vrrp_track_process %}
|
||||||
vrrp_track_process {{ vrrp_track_process }} {
|
vrrp_track_process {{ vrrp_track_process }} {
|
||||||
{% for key, value in keepalived_config.vrrp_track_process[vrrp_track_process].items() %}
|
{% for key, value in keepalived_combined_config.vrrp_track_process[vrrp_track_process].items() %}
|
||||||
{% if value | type_debug != 'list' %}
|
{% if value | type_debug != 'list' %}
|
||||||
{{key}} {{value}}
|
{{key}} {{value}}
|
||||||
{% else %}
|
{% else %}
|
||||||
@ -46,9 +46,9 @@ vrrp_track_process {{ vrrp_track_process }} {
|
|||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for vrrp_instance in keepalived_config.vrrp_instance %}
|
{% for vrrp_instance in keepalived_combined_config.vrrp_instance %}
|
||||||
vrrp_instance {{ vrrp_instance }} {
|
vrrp_instance {{ vrrp_instance }} {
|
||||||
{% for key, value in keepalived_config.vrrp_instance[vrrp_instance].items() %}
|
{% for key, value in keepalived_combined_config.vrrp_instance[vrrp_instance].items() %}
|
||||||
{% if value | type_debug != 'list' %}
|
{% if value | type_debug != 'list' %}
|
||||||
{{key}} {{value}}
|
{{key}} {{value}}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
Loading…
Reference in New Issue
Block a user