mirror of
https://gitea.0xace.cc/ansible-galaxy/keepalived.git
synced 2024-11-25 00:06:41 +00:00
initial commit
This commit is contained in:
commit
f77744dca8
28
README.md
Normal file
28
README.md
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
Setup keepalived service
|
||||||
|
|
||||||
|
Config example:
|
||||||
|
|
||||||
|
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
|
||||||
|
|
3
defaults/main.yml
Normal file
3
defaults/main.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
keepalived_config_override: []
|
||||||
|
keepalived_default_config: []
|
||||||
|
keepalived_script_user: root
|
8
handlers/main.yaml
Normal file
8
handlers/main.yaml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
- name: Restart keepalived
|
||||||
|
throttle: 1
|
||||||
|
systemd:
|
||||||
|
name: keepalived
|
||||||
|
state: restarted
|
||||||
|
daemon_reload: yes
|
||||||
|
when: "not keepalived_setup.changed or not keepalived_enable_and_start.changed"
|
1
meta/main.yml
Normal file
1
meta/main.yml
Normal file
@ -0,0 +1 @@
|
|||||||
|
dependencies: []
|
35
tasks/main.yml
Normal file
35
tasks/main.yml
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
---
|
||||||
|
- name: Install keepalived
|
||||||
|
package:
|
||||||
|
name: keepalived
|
||||||
|
state: present
|
||||||
|
register: keepalived_setup
|
||||||
|
|
||||||
|
- block:
|
||||||
|
- name: Merge config for keepalived
|
||||||
|
set_fact:
|
||||||
|
keepalived_config: "{{ keepalived_default_config | combine(keepalived_config, recursive=true) }}"
|
||||||
|
|
||||||
|
- name: Add keepalived config
|
||||||
|
template:
|
||||||
|
src: "keepalived.conf.j2"
|
||||||
|
dest: "/etc/keepalived/keepalived.conf"
|
||||||
|
notify:
|
||||||
|
- Restart keepalived
|
||||||
|
when: not keepalived_config_override
|
||||||
|
|
||||||
|
- name: Override keepalived config
|
||||||
|
copy:
|
||||||
|
content: "{{ keepalived_config_override }}"
|
||||||
|
dest: "/etc/keepalived/keepalived.conf"
|
||||||
|
notify:
|
||||||
|
- Restart keepalived
|
||||||
|
when: keepalived_config_override
|
||||||
|
|
||||||
|
- name: Enable and start keepalived service
|
||||||
|
systemd:
|
||||||
|
name: keepalived
|
||||||
|
state: started
|
||||||
|
enabled: yes
|
||||||
|
daemon_reload: yes
|
||||||
|
register: keepalived_enable_and_start
|
70
templates/keepalived.conf.j2
Normal file
70
templates/keepalived.conf.j2
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
global_defs {
|
||||||
|
{% if keepalived_config.vrrp_script is defined %}
|
||||||
|
enable_script_security
|
||||||
|
script_user {{ keepalived_script_user }}
|
||||||
|
{% endif %}
|
||||||
|
{% for key, value in keepalived_config.global_defs.items() %}
|
||||||
|
{% if value | type_debug != 'list' %}
|
||||||
|
{{key}} {{value}}
|
||||||
|
{% else %}
|
||||||
|
{% for list_value in value %}
|
||||||
|
{{key}} {{ list_value }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
|
||||||
|
{% if keepalived_config.vrrp_script is defined %}
|
||||||
|
{% for vrrp_script in keepalived_config.vrrp_script %}
|
||||||
|
vrrp_script {{ vrrp_script }} {
|
||||||
|
{% for key, value in keepalived_config.vrrp_script[vrrp_script].items() %}
|
||||||
|
{% if value | type_debug != 'list' %}
|
||||||
|
{{key}} {{value}}
|
||||||
|
{% else %}
|
||||||
|
{% for list_value in value %}
|
||||||
|
{{key}} {{ list_value }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if keepalived_config.vrrp_track_process is defined %}
|
||||||
|
{% for vrrp_track_process in keepalived_config.vrrp_track_process %}
|
||||||
|
vrrp_track_process {{ vrrp_track_process }} {
|
||||||
|
{% for key, value in keepalived_config.vrrp_track_process[vrrp_track_process].items() %}
|
||||||
|
{% if value | type_debug != 'list' %}
|
||||||
|
{{key}} {{value}}
|
||||||
|
{% else %}
|
||||||
|
{% for list_value in value %}
|
||||||
|
{{key}} {{ list_value }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% for vrrp_instance in keepalived_config.vrrp_instance %}
|
||||||
|
vrrp_instance {{ vrrp_instance }} {
|
||||||
|
{% for key, value in keepalived_config.vrrp_instance[vrrp_instance].items() %}
|
||||||
|
{% if value | type_debug != 'list' %}
|
||||||
|
{{key}} {{value}}
|
||||||
|
{% else %}
|
||||||
|
{{ key }} {
|
||||||
|
{% if key == 'unicast_peer' %}
|
||||||
|
{% for list_value in value %}
|
||||||
|
{{ list_value if list_value != ansible_default_ipv4.address }}
|
||||||
|
{% endfor %}
|
||||||
|
{% else %}
|
||||||
|
{% for list_value in value %}
|
||||||
|
{{ list_value }}
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
}
|
||||||
|
{% endif %}
|
||||||
|
{% endfor %}
|
||||||
|
}
|
||||||
|
{% endfor %}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user