2022-04-07 12:07:08 +00:00
|
|
|
---
|
2022-05-11 09:33:52 +00:00
|
|
|
- name: Check packages to be installed
|
|
|
|
block:
|
2022-04-07 12:07:08 +00:00
|
|
|
- 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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2022-05-17 16:59:10 +00:00
|
|
|
- name: "Install packages: {{ packages_to_install | join(',') }}"
|
2022-04-07 12:07:08 +00:00
|
|
|
become: yes
|
|
|
|
ansible.builtin.yum:
|
|
|
|
name: "{{ packages_to_install }}"
|
|
|
|
state: present
|
|
|
|
when: packages_to_install | default([]) | length > 0
|