add keepalived role
This commit is contained in:
parent
4541bab1bc
commit
72254bd72e
14
roles/keepalived/defaults/main.yaml
Normal file
14
roles/keepalived/defaults/main.yaml
Normal 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"
|
12
roles/keepalived/handlers/main.yaml
Normal file
12
roles/keepalived/handlers/main.yaml
Normal 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
|
20
roles/keepalived/tasks/main.yaml
Normal file
20
roles/keepalived/tasks/main.yaml
Normal 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 }}"
|
78
roles/keepalived/templates/keepalived.conf.j2
Normal file
78
roles/keepalived/templates/keepalived.conf.j2
Normal 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 %}
|
Loading…
Reference in New Issue
Block a user