From bf26c727a84812ca0557e3488f7762b6008a525b Mon Sep 17 00:00:00 2001 From: Guido Grazioli Date: Fri, 11 Mar 2022 15:08:53 +0100 Subject: [PATCH] misc: simply fastpackages logic and reduce play time --- roles/keycloak/tasks/fastpackages/check.yml | 14 ----------- roles/keycloak/tasks/fastpackages/install.yml | 23 +++++++++++-------- roles/keycloak/tasks/install.yml | 6 ++--- roles/keycloak/tasks/start_keycloak.yml | 2 +- 4 files changed, 17 insertions(+), 28 deletions(-) delete mode 100644 roles/keycloak/tasks/fastpackages/check.yml diff --git a/roles/keycloak/tasks/fastpackages/check.yml b/roles/keycloak/tasks/fastpackages/check.yml deleted file mode 100644 index c0679dc..0000000 --- a/roles/keycloak/tasks/fastpackages/check.yml +++ /dev/null @@ -1,14 +0,0 @@ ---- -- block: - - name: "Check if package {{ package_name }} is already installed" - ansible.builtin.command: rpm -q {{ package_name }} - args: - warn: no - register: rpm_info - changed_when: rpm_info.failed - - rescue: - - name: "Add {{ package_name }} to the yum install list if missing" - ansible.builtin.set_fact: - packages_to_install: "{{ packages_to_install + [ package_name ] }}" - when: rpm_info.failed \ No newline at end of file diff --git a/roles/keycloak/tasks/fastpackages/install.yml b/roles/keycloak/tasks/fastpackages/install.yml index 41133f4..29155f9 100644 --- a/roles/keycloak/tasks/fastpackages/install.yml +++ b/roles/keycloak/tasks/fastpackages/install.yml @@ -1,18 +1,21 @@ --- -- name: Set facts - ansible.builtin.set_fact: - update_cache: true - packages_to_install: [] +- block: + - name: "Check if packages are already installed" + ansible.builtin.command: "rpm -q {{ packages_list | join(' ') }}" + args: + warn: no + register: rpm_info + changed_when: rpm_info.failed -- name: "Check packages to be installed" - ansible.builtin.include_tasks: check.yml - loop: "{{ packages_list | flatten }}" - loop_control: - loop_var: package_name + rescue: + - 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$') | flatten }}" + when: rpm_info.failed - name: "Install packages: {{ packages_to_install }}" become: yes ansible.builtin.yum: name: "{{ packages_to_install }}" state: present - when: packages_to_install | length > 0 \ No newline at end of file + when: packages_to_install | default([]) | length > 0 \ No newline at end of file diff --git a/roles/keycloak/tasks/install.yml b/roles/keycloak/tasks/install.yml index 7698719..e8ee292 100644 --- a/roles/keycloak/tasks/install.yml +++ b/roles/keycloak/tasks/install.yml @@ -30,12 +30,12 @@ state: absent when: existing_deploy.stat.exists and keycloak_force_install|bool -- name: check for an existing deployment after possible forced removal +- name: Check for an existing deployment after possible forced removal become: yes ansible.builtin.stat: path: "{{ keycloak_jboss_home }}" -- name: create Keycloak service user/group +- name: Create Keycloak service user/group become: yes ansible.builtin.user: name: "{{ keycloak_service_user }}" @@ -43,7 +43,7 @@ system: yes create_home: no -- name: create Keycloak install location +- name: Create Keycloak install location become: yes ansible.builtin.file: dest: "{{ keycloak_dest }}" diff --git a/roles/keycloak/tasks/start_keycloak.yml b/roles/keycloak/tasks/start_keycloak.yml index b3c34f9..62d4f99 100644 --- a/roles/keycloak/tasks/start_keycloak.yml +++ b/roles/keycloak/tasks/start_keycloak.yml @@ -1,5 +1,5 @@ --- -- name: start keycloak +- name: Start keycloak ansible.builtin.systemd: name: keycloak enabled: yes