From a20ac163569860a9d316b279d927a5bbd5684b10 Mon Sep 17 00:00:00 2001 From: dsoumis Date: Tue, 10 Oct 2023 13:21:33 +0300 Subject: [PATCH] Update fastpackage.yml --- roles/jws/tasks/fastpackage.yml | 32 ++++++++++++++--------------- roles/jws/tasks/java_install.yml | 3 ++- roles/jws/tasks/main.yml | 10 ++++----- roles/jws/tasks/systemd/selinux.yml | 3 ++- roles/jws/tasks/systemd/systemd.yml | 9 ++++---- 5 files changed, 27 insertions(+), 30 deletions(-) diff --git a/roles/jws/tasks/fastpackage.yml b/roles/jws/tasks/fastpackage.yml index 9dac8b11..a642b850 100644 --- a/roles/jws/tasks/fastpackage.yml +++ b/roles/jws/tasks/fastpackage.yml @@ -1,19 +1,17 @@ --- -- name: Check arguments - ansible.builtin.assert: - that: - - package_name is defined - quiet: true +- name: "Check if \"{{ packages_list | join(', ') }}\" packages are already installed" # noqa command-instead-of-module this runs faster + ansible.builtin.command: "rpm -q {{ packages_list | join(' ') }}" + register: rpm_info + changed_when: False + failed_when: False -- name: "Install package" - block: - - name: "Test if package {{ package_name }} is already installed" - ansible.builtin.command: rpm -q {{ package_name }} - register: rpm_info - changed_when: rpm_info.failed - rescue: - - name: "Install package {{ package_name }} using yum if missing" - ansible.builtin.yum: - name: "{{ package_name }}" - state: installed - when: rpm_info.failed +- name: "Add missing packages to the yum install list" + ansible.builtin.set_fact: + packages_to_install: "{{ packages_to_install | default([]) + rpm_info.stdout_lines | map('regex_findall', 'package (.+) is not installed$') | default([]) | flatten }}" + +- name: "Install packages: {{ packages_to_install }}" + become: True + ansible.builtin.yum: + name: "{{ packages_to_install }}" + state: present + when: packages_to_install | default([]) | length > 0 diff --git a/roles/jws/tasks/java_install.yml b/roles/jws/tasks/java_install.yml index 05487a19..dc89618a 100644 --- a/roles/jws/tasks/java_install.yml +++ b/roles/jws/tasks/java_install.yml @@ -11,7 +11,8 @@ - name: "Install {{ jws_java_packages_el }}" ansible.builtin.include_tasks: fastpackage.yml vars: - package_name: "{{ jws_java_packages_el }}" + packages_list: + - "{{ jws_java_packages_el }}" - name: Determine JAVA_HOME for selected JVM RPM ansible.builtin.set_fact: diff --git a/roles/jws/tasks/main.yml b/roles/jws/tasks/main.yml index ef67fc65..948ba3c5 100644 --- a/roles/jws/tasks/main.yml +++ b/roles/jws/tasks/main.yml @@ -36,16 +36,14 @@ - name: "Install required dependencies" ansible.builtin.include_tasks: fastpackage.yml vars: - package_name: "{{ item }}" - loop: "{{ jws_dependencies_list }}" + packages_list: "{{ jws_dependencies_list }}" - name: "Install required dependencies for natives" ansible.builtin.include_tasks: fastpackage.yml vars: - package_name: "{{ item }}" - loop: - - openssl - - apr + packages_list: + - openssl + - apr when: jws_native - name: "Ensure tomcatjss rpm is not installed" diff --git a/roles/jws/tasks/systemd/selinux.yml b/roles/jws/tasks/systemd/selinux.yml index 85febb29..bc211fda 100644 --- a/roles/jws/tasks/systemd/selinux.yml +++ b/roles/jws/tasks/systemd/selinux.yml @@ -20,7 +20,8 @@ - name: Install selinux-policy-devel ansible.builtin.include_tasks: ../fastpackage.yml vars: - package_name: selinux-policy-devel + packages_list: + - selinux-policy-devel - name: Check if archive contains a selinux policy ansible.builtin.stat: diff --git a/roles/jws/tasks/systemd/systemd.yml b/roles/jws/tasks/systemd/systemd.yml index bf753039..113d52d2 100644 --- a/roles/jws/tasks/systemd/systemd.yml +++ b/roles/jws/tasks/systemd/systemd.yml @@ -11,11 +11,10 @@ - name: "Ensure requirements for systemd" ansible.builtin.include_tasks: ../fastpackage.yml - loop_control: - loop_var: package_name - loop: - - systemd - - procps-ng + vars: + packages_list: + - systemd + - procps-ng - name: "Set required default for jws_service_conf if not provided." ansible.builtin.set_fact: