Basic keepalived Ansible-Playbook
This commit is contained in:
parent
8408c3f9ca
commit
d4b61bf31e
2
LICENSE
2
LICENSE
@ -58,7 +58,7 @@ APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
Copyright 2021 Janic Voser
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
28
README.md
28
README.md
@ -1,3 +1,27 @@
|
||||
# KeepAlived
|
||||
# Setup Keepalived VIP with Ansible
|
||||
|
||||
Manage Keepalived VIPs with Ansible
|
||||
# Usage
|
||||
|
||||
Every thing you need to setup to configure VIP
|
||||
|
||||
## Prerequirements
|
||||
|
||||
### Same Network
|
||||
The Virtual IP is taking advantage of the vrrp, so the Servers need to reach each other.
|
||||
|
||||
### SSH-Key
|
||||
For ansible to work exchange the SSH-Keys from the Ansible Master to the Ansible managed servers.
|
||||
|
||||
## Configuring your Infrastructure
|
||||
Just adjust the file ./inventory/hosts.ini, with your hosts and variables.
|
||||
|
||||
## Installing the Keepalived service
|
||||
When you have configured everything, just run the Ansible-playbook[configure.yaml].
|
||||
```sh
|
||||
ansible-playbook -i [Inventory File] configure.yaml
|
||||
```
|
||||
|
||||
## Removing the Keepalived service
|
||||
When you want to remove the Keepalived service just run the Ansible-playbook[remove.yaml].
|
||||
```sh
|
||||
ansible-playbook -i [Inventory File] remove.yaml
|
||||
|
18
configure.yaml
Normal file
18
configure.yaml
Normal file
@ -0,0 +1,18 @@
|
||||
---
|
||||
|
||||
- hosts: keepalived
|
||||
gather_facts: yes
|
||||
become: yes
|
||||
roles:
|
||||
- role: prereq
|
||||
- role: download
|
||||
|
||||
- hosts: master
|
||||
become: yes
|
||||
roles:
|
||||
- role: keepalived/master
|
||||
|
||||
- hosts: backup
|
||||
become: yes
|
||||
roles:
|
||||
- role: keepalived/backup
|
24
inventory/hosts.ini
Normal file
24
inventory/hosts.ini
Normal file
@ -0,0 +1,24 @@
|
||||
# Groups
|
||||
[keepalived:children]
|
||||
master
|
||||
backup
|
||||
|
||||
[keepalived:vars]
|
||||
ansible_user=saansi-bot
|
||||
keepalived_process_tracker=k3s-server
|
||||
keepalived_nic=eth0
|
||||
keepalived_auth_pass=password
|
||||
keepalived_vip=172.22.0.100/22
|
||||
keepalived_master_hostname=srvk3s01.voser.local
|
||||
|
||||
|
||||
# Hosts
|
||||
[master]
|
||||
172.22.0.101
|
||||
[backup]
|
||||
172.22.0.102
|
||||
172.22.0.103
|
||||
172.22.0.104
|
||||
172.22.0.121
|
||||
172.22.0.122
|
||||
172.22.0.123
|
7
remove.yaml
Normal file
7
remove.yaml
Normal file
@ -0,0 +1,7 @@
|
||||
---
|
||||
|
||||
- hosts: keepalived
|
||||
gather_facts: yes
|
||||
become: yes
|
||||
roles:
|
||||
- role: remove
|
12
roles/download/tasks/main.yaml
Normal file
12
roles/download/tasks/main.yaml
Normal 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
|
19
roles/keepalived/backup/tasks/main.yaml
Normal file
19
roles/keepalived/backup/tasks/main.yaml
Normal 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
|
24
roles/keepalived/backup/templates/keepalived.conf.j2
Normal file
24
roles/keepalived/backup/templates/keepalived.conf.j2
Normal 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
|
||||
}
|
||||
}
|
19
roles/keepalived/master/tasks/main.yaml
Normal file
19
roles/keepalived/master/tasks/main.yaml
Normal 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
|
24
roles/keepalived/master/templates/keepalived.conf.j2
Normal file
24
roles/keepalived/master/templates/keepalived.conf.j2
Normal 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
|
||||
}
|
||||
}
|
5
roles/prereq/tasks/main.yml
Normal file
5
roles/prereq/tasks/main.yml
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
- name: Set SELinux to disabled state
|
||||
selinux:
|
||||
state: disabled
|
||||
when: ansible_distribution in ['CentOS', 'Red Hat Enterprise Linux']
|
26
roles/remove/tasks/main.yaml
Normal file
26
roles/remove/tasks/main.yaml
Normal 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
|
Loading…
Reference in New Issue
Block a user