Basic keepalived Ansible-Playbook

This commit is contained in:
janic
2021-12-17 16:07:30 +01:00
parent 8408c3f9ca
commit d4b61bf31e
12 changed files with 205 additions and 3 deletions

View File

@@ -0,0 +1,12 @@
---
- name: Update Apt-Cache
apt:
update_cache: yes
cache_valid_time: 3600
when: ansible_os_family == 'Debian'
- name: Install keepalived
package:
name: keepalived
state: latest

View File

@@ -0,0 +1,19 @@
---
- name: Configure keepalived
template:
src: "keepalived.conf.j2"
dest: /etc/keepalived/keepalived.conf
register: template
- name: Restart keepalive Server
service:
name: keepalived
state: restarted
when: template.changed
- name: Running keepalive Server
service:
name: keepalived
state: started
enabled: yes

View File

@@ -0,0 +1,24 @@
vrrp_track_process track_process {
process "{{ keepalived_process_tracker }}"
weight 100
}
vrrp_instance rpis_vip {
state BACKUP
interface {{ keepalived_nic }}
virtual_router_id 1{{ ansible_hostname[-2] }}
priority 10
advert_int 1
authentication {
auth_type PASS
auth_pass {{ keepalived_auth_pass }}
}
virtual_ipaddress {
{{ keepalived_vip }}
}
track_process {
track_process
}
}

View File

@@ -0,0 +1,19 @@
---
- name: Configure keepalived
template:
src: "keepalived.conf.j2"
dest: /etc/keepalived/keepalived.conf
register: template
- name: Restart keepalive Server
service:
name: keepalived
state: restarted
when: template.changed
- name: Running keepalive Server
service:
name: keepalived
state: started
enabled: yes

View File

@@ -0,0 +1,24 @@
vrrp_track_process track_process {
process "{{ keepalived_process_tracker }}"
weight 100
}
vrrp_instance rpis_vip {
state MASTER
interface {{ keepalived_nic }}
virtual_router_id 1{{ ansible_hostname[-2] }}
priority 11
advert_int 1
authentication {
auth_type PASS
auth_pass {{ keepalived_auth_pass }}
}
virtual_ipaddress {
{{ keepalived_vip }}
}
track_process {
track_process
}
}

View File

@@ -0,0 +1,5 @@
---
- name: Set SELinux to disabled state
selinux:
state: disabled
when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux']

View File

@@ -0,0 +1,26 @@
---
- name: Disable services
systemd:
name: "{{ item }}"
state: stopped
enable: no
failed_when: false
with_items:
- keepalived
- name: Install keepalived
package:
name: keepalived
state: absent
- name: Remove files
file:
name: "{{ item }}"
state: absent
with_items:
- "/etc/keepalived/keepalived.conf"
- "/etc/keepalived"
- name: daemon_reload
systemd:
daemon_reload: yes