feat(install): add host install method, which should mostly work

This commit is contained in:
Bertrand Lanson 2024-02-11 23:17:16 +01:00
parent f8a58c260f
commit 620157d126
6 changed files with 151 additions and 0 deletions

View File

@ -1,2 +1,4 @@
--- ---
# defaults file for deploy_keepalived # defaults file for deploy_keepalived
deploy_keepalived_deploy_method: "host"
deploy_keepalived_version: "2.2.5"

View File

@ -0,0 +1,4 @@
---
# requirements file for molecule
roles:
- name: ednz_cloud.manage_apt_packages

92
tasks/install_host.yml Normal file
View File

@ -0,0 +1,92 @@
---
# task/install_host file for deploy_keepalived
- name: "Get releases for keepalived"
vars:
_keepalived_url_ext: "tags"
ansible.builtin.uri:
url: "{{ deploy_keepalived_github_api }}/{{ _keepalived_url_ext }}?per_page=100"
return_content: true
register: _keepalived_all_releases
- name: "Get release for keepalived:{{ deploy_keepalived_version }}"
ansible.builtin.set_fact:
_keepalived_new_release: "{{ _keepalived_all_releases.json |
selectattr('name', 'eq', 'v'~deploy_keepalived_version if deploy_keepalived_version != 'latest' else _keepalived_all_releases.json |
map(attribute='name') |
first ) |
list |
first
}}"
- name: "Set facts for wanted keepalived version"
ansible.builtin.set_fact:
deploy_keepalived_wanted_version: "{{ _keepalived_new_release.name|regex_replace('v', '') }}"
- name: "Check if keepalived is already installed"
ansible.builtin.stat:
path: "{{ deploy_keepalived_config_dir }}/version"
changed_when: false
check_mode: false
register: _keepalived_is_installed
- name: "Check current keepalived version"
ansible.builtin.command: "cat {{ deploy_keepalived_config_dir }}/version"
changed_when: false
check_mode: false
register: _keepalived_old_release
when: _keepalived_is_installed.stat.exists
- name: "Set facts for current keepalived release"
ansible.builtin.set_fact:
deploy_keepalived_current_version: "{{ _keepalived_old_release.stdout | regex_replace('v', '') }}"
when: _keepalived_old_release.stdout is defined
and (_keepalived_old_release.stdout | length > 0)
- name: "Install keepalived"
when: deploy_keepalived_current_version is not defined
or deploy_keepalived_wanted_version not in deploy_keepalived_current_version
block:
- name: "Downloading sources for keepalived:{{ deploy_keepalived_version }}"
ansible.builtin.get_url:
url: "https://keepalived.org/software/keepalived-{{ deploy_keepalived_wanted_version }}.tar.gz"
dest: "/tmp/keepalived.tar.gz"
owner: root
group: root
mode: "0755"
- name: "Extract keepalived sources in {{ deploy_keepalived_tmp_path }}"
ansible.builtin.unarchive:
src: /tmp/keepalived.tar.gz
dest: "/tmp"
remote_src: true
register: result_of_unarchive
- name: "Run configure command for keepalived:{{ deploy_keepalived_version }}"
ansible.builtin.command:
argv:
- "./configure"
args:
chdir: "{{ deploy_keepalived_tmp_path }}"
- name: "Run make command for keepalived:{{ deploy_keepalived_version }}"
community.general.make:
chdir: "{{ deploy_keepalived_tmp_path }}"
- name: "Run make install command for keepalived:{{ deploy_keepalived_version }}"
community.general.make:
chdir: "{{ deploy_keepalived_tmp_path }}"
target: install
- name: "Remove archive and unpacked directory"
ansible.builtin.file:
path: "{{ item }}"
state: absent
with_items:
- "/tmp/keepalived.tar.gz"
- "{{ deploy_keepalived_tmp_path }}"
- name: "Update version file"
ansible.builtin.copy:
content: "{{ deploy_keepalived_wanted_version }}"
dest: "{{ deploy_keepalived_config_dir }}/version"
mode: "0600"

View File

@ -1,2 +1,7 @@
--- ---
# task/main file for deploy_keepalived # task/main file for deploy_keepalived
- name: "Import prerequisites.yml"
ansible.builtin.include_tasks: prerequisites.yml
- name: "Import install_host.yml"
ansible.builtin.include_tasks: install_host.yml

24
tasks/prerequisites.yml Normal file
View File

@ -0,0 +1,24 @@
---
# task/prerequisites file for deploy_keepalived
- name: "Install compilation dependencies"
ansible.builtin.include_role:
name: ednz_cloud.manage_apt_packages
vars:
manage_apt_packages_list: "{{ deploy_keepalived_required_packages }}"
when: deploy_keepalived_deploy_method == 'host'
- name: "Create directory {{ deploy_keepalived_config_dir }}"
ansible.builtin.file:
path: "{{ deploy_keepalived_config_dir }}"
state: directory
owner: "{{ deploy_keepalived_user }}"
group: "{{ deploy_keepalived_group }}"
mode: "0755"
- name: "Create directory {{ deploy_keepalived_scripts_dir }}"
ansible.builtin.file:
path: "{{ deploy_keepalived_scripts_dir }}"
state: directory
owner: "{{ deploy_keepalived_user }}"
group: "{{ deploy_keepalived_group }}"
mode: "0755"

View File

@ -1,2 +1,26 @@
--- ---
# vars file for deploy_keepalived # vars file for deploy_keepalived
deploy_keepalived_config_dir: /etc/keepalived
deploy_keepalived_scripts_dir: /etc/keepalived/scripts
deploy_keepalived_path: /usr/local/bin/keepalived
deploy_keepalived_github_api: https://api.github.com/repos/acassen/keepalived
deploy_keepalived_github_url: https://github.com/acassen/keepalived
deploy_keepalived_tmp_path: "/tmp/keepalived-{{ deploy_keepalived_version}}"
deploy_keepalived_user: root
deploy_keepalived_group: root
deploy_keepalived_required_packages:
- name: gcc
version: latest
state: present
- name: libssl-dev
version: latest
state: present
- name: libnl-3-dev
version: latest
state: present
- name: libnl-genl-3-dev
version: latest
state: present
- name: libsnmp-dev
version: latest
state: present