ansible-role-firewall icon indicating copy to clipboard operation
ansible-role-firewall copied to clipboard

RHEL7 / CentOS7 disable firewalld

Open gerhard-tinned opened this issue 6 years ago • 3 comments

In the currenmt version of this role, iptables is installed, enabled and started. In RHEL7 and CentOS7, the alternative firewall daemon "firewalld" is used by default. This daemon has to be stopped and most important disabled.

I therefore added the following task to the "persist-redhat.yml" file. This task would be best to be executed right before iptables service is started.

- name: Ensure firewalld service is disabled and stopped
  systemd:
    name: firewalld
    state: stopped
    enabled: no
    masked: yes
  register: firewalld_result
  failed_when: "firewalld_result is failed and 'Could not find the requested service' not in firewalld_result.msg"
  when: ansible_os_family == 'RedHat' and ansible_distribution_major_version >= '7'

This task ensures that the firewalld is not only stopped but also disabled and masked. Masking avoids accidental start ofg this service even manually. The when should prevent the role from failing if the firewalld service is not installed on the system.

I have seen that you prefere the one-line version of the tasks, I hope this is still helpful for you. I have tested this on CentOS 7.5 and it should workj without modification as well on RHEL 7.5.

If you prefere a pull request, please let me know.

gerhard-tinned avatar May 22 '18 06:05 gerhard-tinned

Thank you very much for the contribution! Will have a look at it this week.

mikegleasonjr avatar May 22 '18 12:05 mikegleasonjr

On my servers I deal with this problem by uninstalling firewalld - I cannot find any reason to have installed firewalld when I use iptables-services and this ansible role.

- name: remove firewalld
  package:
    name: firewalld
    state: absent

wojciech-kopras avatar Dec 06 '18 13:12 wojciech-kopras

Thanks for the reminder guys!

mikegleasonjr avatar Dec 06 '18 14:12 mikegleasonjr