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