feat(config): add custom template option
All checks were successful
test / Linting (push) Successful in 12s
test / Molecule tests (default, debian11) (push) Successful in 3m8s
test / Molecule tests (default, debian12) (push) Successful in 3m23s
test / Molecule tests (default, ubuntu2204) (push) Successful in 3m36s
test / Molecule tests (with_custom_conf, debian12) (push) Successful in 3m41s
test / Molecule tests (default, ubuntu2004) (push) Successful in 3m45s
test / Molecule tests (with_custom_conf, debian11) (push) Successful in 3m46s
test / Molecule tests (with_custom_conf, ubuntu2004) (push) Successful in 4m2s
test / Molecule tests (with_custom_conf, ubuntu2204) (push) Successful in 2m47s

This commit is contained in:
Bertrand Lanson 2024-03-11 19:29:02 +01:00
parent f01bf3e8cf
commit 9bd6da5a67
10 changed files with 132 additions and 1 deletions

View File

@ -100,6 +100,15 @@ deploy_keepalived_extra_container_volumes: []
Extra volumes to mount to the container if using the `docker` deploy method.
By default, `/etc/keepalived` (host) will be mounted to `/etc/keepalived` (container)
```yaml
deploy_keepalived_use_custom_config: false # by default, set to false
```
This variable lets you switch to using a custom keepalived.conf template file. By default, this is false, and the role will use the default keepalived.conf template.
```yaml
deploy_keepalived_custom_config_src: # by default, unset
```
If `deploy_keepalived_use_custom_config: true`, this sets the path for the custom keepalived.conf template to use. This can either be a static file, or a jinja2 template. It will be copied to `/etc/keepalived/keepalived.conf` on the target machine.
Dependencies

View File

@ -20,3 +20,6 @@ deploy_keepalived_notify_script: notify.sh
deploy_keepalived_custom_scripts_src:
deploy_keepalived_extra_container_volumes: []
deploy_keepalived_use_custom_config: false
deploy_keepalived_custom_config_src:

View File

@ -23,3 +23,6 @@ deploy_keepalived_notify_script: notify.sh
deploy_keepalived_custom_scripts_src:
deploy_keepalived_extra_container_volumes: []
deploy_keepalived_use_custom_config: true
deploy_keepalived_custom_config_src: /tmp/keepalived.conf.j2

View File

@ -0,0 +1,55 @@
---
- name: Prepare
hosts: all
become: true
tasks:
- name: "Generate custom keepalived.conf template" # noqa: run-once[task]
delegate_to: localhost
run_once: true
block:
- name: "Generate custom keepalived.conf template"
ansible.builtin.copy:
content: |
{% raw -%}
# {{ ansible_managed }}
# THIS IS A CUSTOM CONF
global_defs {
script_user keepalived_script
enable_script_security
}
vrrp_instance {{ deploy_keepalived_vrrp_instance_name }} {
interface {{ deploy_keepalived_interface }}
state {{ deploy_keepalived_state }}
virtual_router_id {{ deploy_keepalived_router_id }}
priority {{ deploy_keepalived_priority }}
advert_int {{ deploy_keepalived_advert_interval }}
nopreempt
{% if deploy_keepalived_unicast_peers %}
unicast_src_ip {{ deploy_keepalived_unicast_source }}
unicast_peer {
{% for peer in deploy_keepalived_unicast_peers %}
{{ peer }}
{% endfor %}
}
{% endif %}
authentication {
auth_type PASS
auth_pass {{ deploy_keepalived_auth_passwd }}
}
virtual_ipaddress {
{% for vip in deploy_keepalived_virtual_ips %}
{{ vip }}
{% endfor %}
}
notify {{ deploy_keepalived_scripts_dir }}/{{ deploy_keepalived_notify_script }}
}
{%- endraw %}
dest: /tmp/keepalived.conf.j2
mode: '0644'

View File

@ -54,6 +54,7 @@
vars:
keepalived_expected_cfg_file: |
# Ansible managed: Do NOT edit this file manually!
# THIS IS A CUSTOM CONF
global_defs {
script_user keepalived_script
enable_script_security

View File

@ -22,3 +22,6 @@ deploy_keepalived_notify_script: notify.sh
deploy_keepalived_custom_scripts_src:
deploy_keepalived_extra_container_volumes: []
deploy_keepalived_use_custom_config: true
deploy_keepalived_custom_config_src: /tmp/keepalived.conf.j2

View File

@ -0,0 +1,55 @@
---
- name: Prepare
hosts: all
become: true
tasks:
- name: "Generate custom keepalived.conf template" # noqa: run-once[task]
delegate_to: localhost
run_once: true
block:
- name: "Generate custom keepalived.conf template"
ansible.builtin.copy:
content: |
{% raw -%}
# {{ ansible_managed }}
# THIS IS A CUSTOM CONF
global_defs {
script_user keepalived_script
enable_script_security
}
vrrp_instance {{ deploy_keepalived_vrrp_instance_name }} {
interface {{ deploy_keepalived_interface }}
state {{ deploy_keepalived_state }}
virtual_router_id {{ deploy_keepalived_router_id }}
priority {{ deploy_keepalived_priority }}
advert_int {{ deploy_keepalived_advert_interval }}
nopreempt
{% if deploy_keepalived_unicast_peers %}
unicast_src_ip {{ deploy_keepalived_unicast_source }}
unicast_peer {
{% for peer in deploy_keepalived_unicast_peers %}
{{ peer }}
{% endfor %}
}
{% endif %}
authentication {
auth_type PASS
auth_pass {{ deploy_keepalived_auth_passwd }}
}
virtual_ipaddress {
{% for vip in deploy_keepalived_virtual_ips %}
{{ vip }}
{% endfor %}
}
notify {{ deploy_keepalived_scripts_dir }}/{{ deploy_keepalived_notify_script }}
}
{%- endraw %}
dest: /tmp/keepalived.conf.j2
mode: '0644'

View File

@ -3,4 +3,5 @@
roles:
- name: ednz_cloud.manage_repositories
- name: ednz_cloud.manage_apt_packages
- name: ednz_cloud.docker_systemd_service
- name: ednz_cloud.install_docker

View File

@ -30,6 +30,7 @@
vars:
keepalived_expected_cfg_file: |
# Ansible managed: Do NOT edit this file manually!
# THIS IS A CUSTOM CONF
global_defs {
script_user keepalived_script
enable_script_security

View File

@ -13,7 +13,7 @@
- name: "Copy keepalived.conf template"
ansible.builtin.template:
src: keepalived.conf.j2
src: "{{ deploy_keepalived_custom_config_src if deploy_keepalived_use_custom_config else 'keepalived.conf.j2' }}"
dest: "{{ deploy_keepalived_config_dir }}/keepalived.conf"
owner: "{{ deploy_keepalived_user }}"
group: "{{ deploy_keepalived_group }}"