From 620157d126672c885c3d55dd17208610ac2c434b Mon Sep 17 00:00:00 2001 From: Bertrand Lanson Date: Sun, 11 Feb 2024 23:17:16 +0100 Subject: [PATCH] feat(install): add host install method, which should mostly work --- defaults/main.yml | 2 + molecule/default/requirements.yml | 4 ++ tasks/install_host.yml | 92 +++++++++++++++++++++++++++++++ tasks/main.yml | 5 ++ tasks/prerequisites.yml | 24 ++++++++ vars/main.yml | 24 ++++++++ 6 files changed, 151 insertions(+) create mode 100644 molecule/default/requirements.yml create mode 100644 tasks/install_host.yml create mode 100644 tasks/prerequisites.yml diff --git a/defaults/main.yml b/defaults/main.yml index 8fb6d20..c88cb2b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,2 +1,4 @@ --- # defaults file for deploy_keepalived +deploy_keepalived_deploy_method: "host" +deploy_keepalived_version: "2.2.5" diff --git a/molecule/default/requirements.yml b/molecule/default/requirements.yml new file mode 100644 index 0000000..329e789 --- /dev/null +++ b/molecule/default/requirements.yml @@ -0,0 +1,4 @@ +--- +# requirements file for molecule +roles: + - name: ednz_cloud.manage_apt_packages diff --git a/tasks/install_host.yml b/tasks/install_host.yml new file mode 100644 index 0000000..e444e3b --- /dev/null +++ b/tasks/install_host.yml @@ -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" diff --git a/tasks/main.yml b/tasks/main.yml index b6b72a9..eb6b305 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -1,2 +1,7 @@ --- # 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 diff --git a/tasks/prerequisites.yml b/tasks/prerequisites.yml new file mode 100644 index 0000000..6a6d2e8 --- /dev/null +++ b/tasks/prerequisites.yml @@ -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" diff --git a/vars/main.yml b/vars/main.yml index 4f8e01e..57fce6c 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -1,2 +1,26 @@ --- # 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