From f60a97f69d98a7609280b2c74e3c37c24a4676ad Mon Sep 17 00:00:00 2001 From: molecule Date: Thu, 9 May 2024 18:49:28 +0200 Subject: [PATCH] add update --- roles/setup/tasks/check_installed_version.yml | 12 +++++ roles/setup/tasks/main.yml | 47 ++++++++----------- roles/setup/tasks/preflight.yml | 6 ++- roles/setup/tasks/python_packages.yml | 1 + roles/setup/tasks/setup-Debian.yml | 2 +- roles/setup/tasks/setup-RedHat.yml | 2 +- 6 files changed, 40 insertions(+), 30 deletions(-) create mode 100644 roles/setup/tasks/check_installed_version.yml diff --git a/roles/setup/tasks/check_installed_version.yml b/roles/setup/tasks/check_installed_version.yml new file mode 100644 index 0000000..fb6e646 --- /dev/null +++ b/roles/setup/tasks/check_installed_version.yml @@ -0,0 +1,12 @@ +- name: Check if receptor is installed correctly + ansible.builtin.command: "receptor --version" + changed_when: false + register: receptor_version + ignore_errors: true + +- name: Assert receptor installation + ansible.builtin.assert: + that: + - receptor_version.rc == 0 + fail_msg: "Receptor not installed correctly. Please check the installation or reinstall it with local_receptor: true" + success_msg: "Receptor installed correctly" \ No newline at end of file diff --git a/roles/setup/tasks/main.yml b/roles/setup/tasks/main.yml index 348f108..2d0ef1c 100644 --- a/roles/setup/tasks/main.yml +++ b/roles/setup/tasks/main.yml @@ -1,6 +1,6 @@ --- - name: Run preflight - ansible.builtin.include_tasks: preflight.yml + ansible.builtin.include_tasks: preflight.yml # Variable configuration. - name: Include variables @@ -15,7 +15,7 @@ ansible.builtin.set_fact: additional_python_packages: "{{ additional_python_packages + ['receptorctl'] }}" when: - - receptor_install_method in ['release', 'local'] + - receptor_install_method in ['release', 'local'] or "'update' in receptor_install_method" - "'receptorctl' not in additional_python_packages" - name: Install python packages @@ -24,38 +24,31 @@ - name: Receptor install local ansible.builtin.include_tasks: setup-local.yml - when: receptor_install_method == 'local' + when: receptor_install_method in ['local', 'update-local'] - name: Receptor install release ansible.builtin.include_tasks: setup-release.yml - when: receptor_install_method == 'release' + when: receptor_install_method == ['release', 'update-release'] -- name: Check if receptor was installed correctly - ansible.builtin.command: "receptor --version" - changed_when: false - register: receptor_version - ignore_errors: true +- name: Receptor check installation + ansible.builtin.include_tasks: check_installed_version.yml -- name: Assert receptor installation - ansible.builtin.assert: - that: - - receptor_version.rc == 0 - fail_msg: "Receptor not installed correctly. Please check the installation or reinstall it with local_receptor: true" - success_msg: "Receptor installed correctly" +- name: Configuration tasks during fisrt installation + when: not ('update' in receptor_install_method) + block: + - name: Configure receptor socket + ansible.builtin.include_tasks: configure.yml -- name: Configure receptor socket - ansible.builtin.include_tasks: configure.yml + - name: TLS files + ansible.builtin.include_tasks: tls.yml + when: receptor_tls -- name: TLS files - ansible.builtin.include_tasks: tls.yml - when: receptor_tls + - name: Work signing + ansible.builtin.include_tasks: worksign.yml + when: receptor_sign or receptor_verify -- name: Work signing - ansible.builtin.include_tasks: worksign.yml - when: receptor_sign or receptor_verify - -- name: Generate receptor config - ansible.builtin.include_tasks: generate_config.yml + - name: Generate receptor config + ansible.builtin.include_tasks: generate_config.yml - name: Setup systemd ansible.builtin.include_tasks: setup-service.yml @@ -64,7 +57,7 @@ - name: Start Receptor service ansible.builtin.systemd: name: "{{ receptor_service_name }}" - state: started + state: "{{ 'restarted' if 'update' in receptor_install_method else 'started' }}" daemon_reload: true enabled: true register: _started diff --git a/roles/setup/tasks/preflight.yml b/roles/setup/tasks/preflight.yml index 24e10a1..11bf4e5 100644 --- a/roles/setup/tasks/preflight.yml +++ b/roles/setup/tasks/preflight.yml @@ -2,4 +2,8 @@ - name: Check local binary file is set ansible.builtin.assert: that: receptor_local_bin_file | length - when: receptor_install_method == 'local' + when: ['local', 'update-local'] + +- name: Receptor check installation + ansible.builtin.include_tasks: check_installed_version.yml + when: "'update' in receptor_install_method" diff --git a/roles/setup/tasks/python_packages.yml b/roles/setup/tasks/python_packages.yml index a3fc6dd..eb52e55 100644 --- a/roles/setup/tasks/python_packages.yml +++ b/roles/setup/tasks/python_packages.yml @@ -18,6 +18,7 @@ - name: Install additional python packages ansible.builtin.pip: name: "{{ additional_python_packages | default([]) }}" + state: "{{ 'latest' if 'update' in receptor_install_method else 'present' }}" executable: "{{ pip_executable }}" - name: Symlink receptorctl to /usr/bin diff --git a/roles/setup/tasks/setup-Debian.yml b/roles/setup/tasks/setup-Debian.yml index fd39986..25b72a0 100644 --- a/roles/setup/tasks/setup-Debian.yml +++ b/roles/setup/tasks/setup-Debian.yml @@ -2,4 +2,4 @@ - name: Install dependencies specific to the node type ansible.builtin.apt: name: "{{ additional_system_packages | default([]) }}" - state: present + state: "{{ 'latest' if 'update' in receptor_install_method else 'present' }}" diff --git a/roles/setup/tasks/setup-RedHat.yml b/roles/setup/tasks/setup-RedHat.yml index 441ed55..ac49a9b 100644 --- a/roles/setup/tasks/setup-RedHat.yml +++ b/roles/setup/tasks/setup-RedHat.yml @@ -2,7 +2,7 @@ - name: Install receptor packages ansible.builtin.dnf: name: "{{ receptor_packages }}" - state: present + state: "{{ 'latest' if 'update' in receptor_install_method else 'present' }}" when: - receptor_install_method == 'package' - receptor_packages