Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions roles/keepalived/handlers/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
name: "keepalived"
state: "restarted"
daemon_reload: true
when: "not initial_dry_run"
when: "not __initial_dry_run"

- name: "Reload Keepalived"
become: true
ansible.builtin.service:
name: "keepalived"
state: "reloaded"
daemon_reload: true
when: "not initial_dry_run"
when: "not __initial_dry_run"

...
50 changes: 26 additions & 24 deletions roles/keepalived/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,56 +32,58 @@
- name: "Check whether Keepalived binary is installed."
ansible.builtin.stat:
path: "{{ keepalived_executable_path }}"
register: "keepalived_installed"
register: "__keepalived_binary"

- name: "Determine if this is an initial dry-run"
ansible.builtin.set_fact:
initial_dry_run: "{{ ansible_check_mode and not keepalived_installed.stat.exists }}"
__initial_dry_run: "{{ ansible_check_mode and not __keepalived_binary.stat.exists }}"

- name: "Get Keepalived version."
ansible.builtin.command:
cmd: "{{ keepalived_executable_path }} --version"
register: "keepalived_version_installed"
when: "keepalived_installed.stat.exists"
register: "__keepalived_version_installed"
when: "__keepalived_binary.stat.exists"
changed_when: false
check_mode: false

- name: "Put value of installed version into an Ansible fact."
ansible.builtin.set_fact:
installed_keepalived_version: "{{ keepalived_version_installed.stderr | regex_search('^Keepalived v(\\d+\\.\\d+\\.\\d+)', '\\1') | first }}"
when: "keepalived_installed.stat.exists"
__installed_keepalived_version: "{{ __keepalived_version_installed.stderr | regex_search('^Keepalived v(\\d+\\.\\d+\\.\\d+)', '\\1') | first }}"
when: "__keepalived_binary.stat.exists"

- name: "Output version strings of installed and to be installed Keepalived."
ansible.builtin.debug:
msg: "Installed version: {{ installed_keepalived_version }}, version to be installed: {{ keepalived_version }}."
when: "installed_keepalived_version is defined"
msg: "Installed version: {{ __installed_keepalived_version }}, version to be installed: {{ keepalived_version }}."
when: "__installed_keepalived_version is defined"

- name: "Check if both version strings are equal."
ansible.builtin.set_fact:
is_keepalived_version_equal: "{{ installed_keepalived_version is version(keepalived_version, operator='==', strict=True) }}"
when: "keepalived_installed.stat.exists"
__is_keepalived_version_equal: "{{ __installed_keepalived_version is version(keepalived_version, operator='==', strict=True) }}"
when: "__keepalived_binary.stat.exists"

- name: "Continue with installing Keepalived if Keepalived is not already installed or versions are not equal."
when: "not keepalived_installed.stat.exists or not is_keepalived_version_equal"
when: >-
not __keepalived_binary.stat.exists or
not __is_keepalived_version_equal
block:

- name: "Create temporary Keepalived build directory."
become: true
ansible.builtin.tempfile:
state: "directory"
prefix: "keepalived-{{ keepalived_version }}_"
register: "tempdir"
register: "__tempdir"
check_mode: false

- name: "Store temporary build directory path"
ansible.builtin.set_fact:
keepalived_build_dir: "{{ tempdir.path }}"
__keepalived_build_dir: "{{ __tempdir.path }}"

- name: "Download and extract keepalived archive."
become: true
ansible.builtin.unarchive:
src: "{{ keepalived_download_url }}"
dest: "{{ keepalived_build_dir }}"
dest: "{{ __keepalived_build_dir }}"
remote_src: true
extra_opts:
- "--strip-components=1"
Expand All @@ -93,27 +95,27 @@
become: true
ansible.builtin.command: "./configure"
args:
chdir: "{{ keepalived_build_dir }}"
chdir: "{{ __keepalived_build_dir }}"
changed_when: true

- name: "Build Keepalived from source."
become: true
community.general.make:
chdir: "{{ keepalived_build_dir }}"
when: "not initial_dry_run"
chdir: "{{ __keepalived_build_dir }}"
when: "not __initial_dry_run"

- name: "Install Keepalived binaries."
become: true
community.general.make:
chdir: "{{ keepalived_build_dir }}"
chdir: "{{ __keepalived_build_dir }}"
target: "install"
notify: "Restart Keepalived"
when: "not initial_dry_run"
when: "not __initial_dry_run"

- name: "Copy Keepalived sysconfig file"
become: true
ansible.builtin.copy:
src: "{{ keepalived_build_dir }}/keepalived/etc/sysconfig/keepalived"
src: "{{ __keepalived_build_dir }}/keepalived/etc/sysconfig/keepalived"
dest: "{{ keepalived_sysconfig_file_path }}"
owner: "root"
group: "root"
Expand All @@ -124,7 +126,7 @@
- name: "Remove temporary build directory"
become: true
ansible.builtin.file:
path: "{{ keepalived_build_dir }}"
path: "{{ __keepalived_build_dir }}"
state: "absent"
check_mode: false

Expand All @@ -142,8 +144,8 @@
become: true
ansible.builtin.command:
cmd: "{{ keepalived_executable_path | quote }} --config-test --use-file {{ keepalived_conf_file_path | quote }}"
register: "config_check"
changed_when: "config_check.rc != 0"
register: "__config_check"
changed_when: "__config_check.rc != 0"

- name: "Create Keepalived Service Unit File."
ansible.builtin.template:
Expand All @@ -161,6 +163,6 @@
state: "started"
enabled: true
daemon_reload: true
when: "not initial_dry_run"
when: "not __initial_dry_run"

...