TOSIT-IO / tdp-collection-prerequisites

Ansible collection with TDP prerequisites
Apache License 2.0
3 stars 10 forks source link

Do not interfere with firewalld if not installed #31

Closed Nuttymoon closed 2 years ago

Nuttymoon commented 2 years ago

Which issue(s) this PR fixes:

Fixes #29

Additional comments:

To make clear that you license your contribution under the Apache License Version 2.0, January 2004 and that you give permission to TOSIT, you have to acknowledge this by using the following check-box.

Nuttymoon commented 2 years ago

Force pushed to add legacy: authconfig and modern: authselect

rpignolet commented 2 years ago

It would be better if you check only if the package firewalld is installed instead of listing all installed packages but I don't know if this is possible and keep it simple.

gboutry commented 2 years ago

It would be better if you check only if the package firewalld is installed instead of listing all installed packages but I don't know if this is possible and keep it simple.

I think using module package with state: present in check mode should do the trick:

- name: "Check if listed package is installed"
  package:
    name: "{{ item }}"
    state: present
  check_mode: true
  loop: "{{ package_names }}"
  register: package_check
- name: "Print execution results"
  debug:
    msg: "Package is installed"
  when: package_check is succeeded

Source: https://techviewleo.com/ansible-check-if-software-package-is-installed/

rpignolet commented 2 years ago

If the package is not installed, it will display changed which is bad.

gboutry commented 2 years ago

If the package is not installed, it will display changed which is bad.

We just need to use state: absent, and check if the check succeeded or if it changed no ?

Nuttymoon commented 2 years ago

I find it way harder to understand the logic based on the changed status of:

- name: Check if firewalld is installed
  yum:
    name: firewalld
    state: absent
  check_mode: yes
  register: yum_firewalld

than just checking if firewalld is in the list of installed packages.