-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
27 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters