2021-12-14 10:26:42 +00:00
---
2022-05-11 09:33:52 +00:00
- name : Check packages to be installed
block :
2022-03-11 14:08:53 +00:00
- name : "Check if packages are already installed"
2022-10-05 12:55:42 +00:00
ansible.builtin.command : "dpkg -s {{ packages_list | join(' ') }}"
2022-03-11 14:08:53 +00:00
args :
warn : no
2022-10-05 12:55:42 +00:00
register : dpkg_info
changed_when : dpkg_info.failed
2021-12-14 10:26:42 +00:00
2022-03-11 14:08:53 +00:00
rescue :
2022-10-05 12:55:42 +00:00
- name : "Add missing packages to the apt install list"
2022-03-11 14:08:53 +00:00
ansible.builtin.set_fact :
2022-10-05 12:55:42 +00:00
packages_to_install : "{{ packages_to_install | default([]) + dpkg_info.stdout_lines | map('regex_findall', 'package (.+) is not installed and no information is available$') | flatten }}"
2022-03-11 14:08:53 +00:00
when : rpm_info.failed
2021-12-14 10:26:42 +00:00
2022-10-05 12:55:42 +00:00
- name : Install packages
2021-12-14 10:26:42 +00:00
become : yes
2022-10-05 12:55:42 +00:00
ansible.builtin.apt :
2021-12-14 10:26:42 +00:00
name : "{{ packages_to_install }}"
state : present
2022-10-05 12:55:42 +00:00
when : packages_to_install | default([]) | length > 0