add keepalived role

This commit is contained in:
Ryan Cavicchioni 2022-08-30 07:47:54 -05:00
parent 4541bab1bc
commit 72254bd72e
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
4 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,14 @@
---
keepalived_package_name: keepalived
keepalived_package_state: present
keepalived_service_name: keepalived
keepalived_service_state: started
keepalived_service_enabled: true
keepalived_etc_path: /etc/keepalived
keepalived_config_path: "{{ keepalived_etc_path }}/keepalived.conf"
keepalived_config_owner: root
keepalived_config_group: root
keepalived_config_mode: "0600"

View File

@ -0,0 +1,12 @@
---
- name: reload keepalived
service:
name: "{{ keepalived_service_name }}"
state: reloaded
when: keepalived_service_enabled
- name: restart keepalived
service:
name: "{{ keepalived_service_name }}"
state: restarted
when: keepalived_service_enabled

View File

@ -0,0 +1,20 @@
---
- name: install
package:
name: "{{ keepalived_package_name }}"
state: "{{ keepalived_package_state }}"
- name: configure
template:
src: keepalived.conf.j2
dest: "{{ keepalived_config_path }}"
owner: "{{ keepalived_config_owner }}"
group: "{{ keepalived_config_group }}"
mode: "{{ keepalived_config_mode }}"
notify: reload keepalived
- name: service
service:
name: "{{ keepalived_service_name }}"
state: "{{ keepalived_service_state }}"
enabled: "{{ keepalived_service_enabled }}"

View File

@ -0,0 +1,78 @@
{{ ansible_managed | comment }}
{% if keepalived_global_defs is defined %}
global_defs {
{% for k in keepalived_global_defs %}
{{ k }} {{ v }}
{% endfor %}
}
{% endif %}
{% if keepalived_vrrp_scripts is defined %}
{% for name, conf in keepalived_vrrp_scripts.items() %}
vrrp_script {{ name }} {
{% if conf.script is defined %}
script "{{ conf.script }}"
{% endif %}
{% if conf.interval is defined %}
interval {{ conf.interval | default(1) }}
{% endif %}
{% if conf.weight is defined %}
weight {{ conf.weight }}
{% endif %}
}
{% endfor %}
{% endif %}
{% if keepalived_vrrp_instances is defined %}
{% for name, conf in keepalived_vrrp_instances.items() %}
vrrp_instance {{ name }} {
{% if conf.state is defined %}
state {{ conf.state | default("MASTER") }}
{% endif %}
{% if conf.interface is defined %}
interface {{ conf.interface | default("eth0") }}
{% endif %}
{% if conf.virtual_router_id is defined %}
virtual_router_id {{ conf.virtual_router_id }}
{% endif %}
{% if conf.priority is defined %}
priority {{ conf.priority }}
{% endif %}
{% if conf.advert_int is defined %}
advert_int {{ conf.advert_int }}
{% endif %}
{% if conf.authentication is defined %}
authentication {
{% if conf.authentication.auth_type is defined %}
auth_type {{ conf.authentication.auth_type }}
{% endif %}
{% if conf.authentication.auth_pass is defined %}
auth_pass {{ conf.authentication.auth_pass }}
{% endif %}
}
{% if conf.unicast_peer is defined %}
unicast_peer {
{% for x in conf.unicast_peer %}
{{ x }}
{% endfor %}
}
{% endif %}
{% if conf.virtual_ipaddress is defined %}
virtual_ipaddress {
{% for x in conf.virtual_ipaddress %}
{{ x }}
{% endfor %}
}
{% endif %}
{% if conf.track_script is defined %}
track_script {
{% for x in conf.track_script %}
{{ x }}
{% endfor %}
}
{% endif %}
{% endif %}
}
{% endfor %}
{% endif %}