191 lines
7.7 KiB
YAML
191 lines
7.7 KiB
YAML
---
|
|
- name: Verify
|
|
hosts: all
|
|
gather_facts: true
|
|
become: true
|
|
tasks:
|
|
- name: "Test: keepalived_script user and group"
|
|
block:
|
|
- name: "Getent user keepalived_script"
|
|
ansible.builtin.getent:
|
|
database: passwd
|
|
key: keepalived_script
|
|
register: keepalived_script_user
|
|
|
|
- name: "Getent group keepalived_script"
|
|
ansible.builtin.getent:
|
|
database: group
|
|
key: keepalived_script
|
|
register: keepalived_script_group
|
|
|
|
- name: "Verify keepalived_script user and group"
|
|
ansible.builtin.assert:
|
|
that:
|
|
- not keepalived_script_user.failed
|
|
- not keepalived_script_group.failed
|
|
- "'keepalived_script' in keepalived_script_user.ansible_facts.getent_passwd.keys()"
|
|
- "'/home/keepalived_script' in keepalived_script_user.ansible_facts.getent_passwd['keepalived_script']"
|
|
- "'/bin/false' in keepalived_script_user.ansible_facts.getent_passwd['keepalived_script']"
|
|
- "'keepalived_script' in keepalived_script_group.ansible_facts.getent_group.keys()"
|
|
|
|
- name: "Test: directory /etc/keepalived"
|
|
block:
|
|
- name: "Stat directory /etc/keepalived"
|
|
ansible.builtin.stat:
|
|
path: "/etc/keepalived"
|
|
register: stat_etc_keepalived
|
|
|
|
- name: "Stat file /etc/keepalived/keepalived.env"
|
|
ansible.builtin.stat:
|
|
path: "/etc/keepalived/keepalived.env"
|
|
register: stat_etc_keepalived_keepalived_env
|
|
|
|
- name: "Stat file /etc/keepalived/keepalived.conf"
|
|
ansible.builtin.stat:
|
|
path: "/etc/keepalived/keepalived.conf"
|
|
register: stat_etc_keepalived_keepalived_conf
|
|
|
|
- name: "Slurp file /etc/keepalived/keepalived.conf"
|
|
ansible.builtin.slurp:
|
|
src: "/etc/keepalived/keepalived.conf"
|
|
register: slurp_etc_keepalived_keepalived_conf
|
|
|
|
- name: "Verify directory /etc/keepalived"
|
|
vars:
|
|
keepalived_expected_cfg_file: |
|
|
# Ansible managed: Do NOT edit this file manually!
|
|
global_defs {
|
|
script_user keepalived_script
|
|
enable_script_security
|
|
}
|
|
|
|
vrrp_instance instance {
|
|
interface eth0
|
|
|
|
state BACKUP
|
|
virtual_router_id 50
|
|
priority 100
|
|
advert_int 1
|
|
|
|
nopreempt
|
|
|
|
unicast_src_ip {{ ansible_default_ipv4.address }}
|
|
unicast_peer {
|
|
192.168.1.13
|
|
192.168.1.14
|
|
192.168.1.15
|
|
}
|
|
|
|
authentication {
|
|
auth_type PASS
|
|
auth_pass password
|
|
}
|
|
|
|
virtual_ipaddress {
|
|
192.168.1.100/32
|
|
}
|
|
|
|
notify /etc/keepalived/scripts.d/notify.sh
|
|
}
|
|
ansible.builtin.assert:
|
|
that:
|
|
- stat_etc_keepalived.stat.exists
|
|
- stat_etc_keepalived.stat.isdir
|
|
- stat_etc_keepalived.stat.pw_name == 'root'
|
|
- stat_etc_keepalived.stat.gr_name == 'root'
|
|
- stat_etc_keepalived.stat.mode == '0755'
|
|
- stat_etc_keepalived_keepalived_env.stat.exists
|
|
- stat_etc_keepalived_keepalived_env.stat.isreg
|
|
- stat_etc_keepalived_keepalived_env.stat.pw_name == 'root'
|
|
- stat_etc_keepalived_keepalived_env.stat.gr_name == 'root'
|
|
- stat_etc_keepalived_keepalived_env.stat.mode == '0600'
|
|
- stat_etc_keepalived_keepalived_conf.stat.exists
|
|
- stat_etc_keepalived_keepalived_conf.stat.isreg
|
|
- stat_etc_keepalived_keepalived_conf.stat.pw_name == 'root'
|
|
- stat_etc_keepalived_keepalived_conf.stat.gr_name == 'root'
|
|
- stat_etc_keepalived_keepalived_conf.stat.mode == '0600'
|
|
- (slurp_etc_keepalived_keepalived_conf.content|b64decode) == keepalived_expected_cfg_file
|
|
|
|
- name: "Test: service keepalived"
|
|
block:
|
|
- name: "Get service keepalived"
|
|
ansible.builtin.service_facts:
|
|
|
|
- name: "Stat file /etc/systemd/system/keepalived.service"
|
|
ansible.builtin.stat:
|
|
path: "/etc/systemd/system/keepalived.service"
|
|
register: stat_etc_systemd_system_keepalived_service
|
|
|
|
- name: "Slurp file /etc/systemd/system/keepalived.service"
|
|
ansible.builtin.slurp:
|
|
src: "/etc/systemd/system/keepalived.service"
|
|
register: slurp_etc_systemd_system_keepalived_service
|
|
|
|
- name: "Verify service keepalived"
|
|
vars:
|
|
keepalived_expected_service_file: |
|
|
# Ansible managed: Do NOT edit this file manually!
|
|
[Unit]
|
|
Description=Keepalive Daemon (LVS and VRRP)
|
|
After=network-online.target
|
|
Wants=network-online.target
|
|
ConditionFileNotEmpty=/etc/keepalived/keepalived.conf
|
|
|
|
[Service]
|
|
# Type=notify
|
|
EnvironmentFile=-/etc/keepalived/keepalived.env
|
|
ExecStart=/usr/local/sbin/keepalived -f /etc/keepalived/keepalived.conf --dont-fork $DAEMON_ARGS
|
|
ExecReload=/bin/kill -HUP $MAINPID
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
ansible.builtin.assert:
|
|
that:
|
|
- stat_etc_systemd_system_keepalived_service.stat.exists
|
|
- stat_etc_systemd_system_keepalived_service.stat.isreg
|
|
- stat_etc_systemd_system_keepalived_service.stat.pw_name == 'root'
|
|
- stat_etc_systemd_system_keepalived_service.stat.gr_name == 'root'
|
|
- stat_etc_systemd_system_keepalived_service.stat.mode == '0644'
|
|
- (slurp_etc_systemd_system_keepalived_service.content|b64decode) == keepalived_expected_service_file
|
|
- ansible_facts.services['keepalived.service'] is defined
|
|
- ansible_facts.services['keepalived.service']['source'] == 'systemd'
|
|
- ansible_facts.services['keepalived.service']['state'] == 'running'
|
|
- ansible_facts.services['keepalived.service']['status'] == 'enabled'
|
|
|
|
- name: "Test: file /usr/local/sbin/keepalived"
|
|
block:
|
|
- name: "Stat file /usr/local/sbin/keepalived"
|
|
ansible.builtin.stat:
|
|
path: "/usr/local/sbin/keepalived"
|
|
register: stat_usr_local_sbin_keepalived
|
|
|
|
- name: "Command keepalived --version"
|
|
ansible.builtin.command: "keepalived --version"
|
|
changed_when: false
|
|
register: keepalived_version
|
|
|
|
- name: "Verify file /usr/local/sbin/keepalived"
|
|
ansible.builtin.assert:
|
|
that:
|
|
- keepalived_version.stderr | regex_search('^Keepalived v2\\.2\\.7')
|
|
- stat_usr_local_sbin_keepalived.stat.exists
|
|
- stat_usr_local_sbin_keepalived.stat.isreg
|
|
- stat_usr_local_sbin_keepalived.stat.pw_name == 'root'
|
|
- stat_usr_local_sbin_keepalived.stat.gr_name == 'root'
|
|
- stat_usr_local_sbin_keepalived.stat.mode == '0755'
|
|
|
|
- name: "Test: interfaces"
|
|
block:
|
|
- name: "Debug"
|
|
ansible.builtin.debug:
|
|
msg: "{{ ansible_eth0 }}"
|
|
|
|
- name: "Verify VIP interface"
|
|
ansible.builtin.assert:
|
|
that:
|
|
- ansible_eth0.active
|
|
- ansible_eth0.ipv4_secondaries[0].address == '192.168.1.100'
|
|
- ansible_eth0.ipv4_secondaries[0].netmask == '255.255.255.255'
|
|
- ansible_eth0.ipv4_secondaries[0].broadcast == ''
|
|
- ansible_eth0.ipv4_secondaries[0].network == '192.168.1.100'
|
|
- ansible_eth0.ipv4_secondaries[0].prefix == '32' |