2

I have added some rules to firewalld on CentOS via Ansible. But I need to reload the firewalld daemon for the service to work properly and permanently. Is there a way to do this in Ansible?

Here is my Ansible code:

- name: Add port to firewalld
  firewalld:
    port: "{{ item }}"
    permanent: yes
    state: enabled
  when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
  loop:
    - 8080/tcp
    - 8000/tcp
    - 8090/tcp
    - 8040/tcp
3
  • if it's managed by systemd or some other init service,shouldn't invoking a service task satisfy this? Can you tell us whether the code you're using actually works or if not how it fails? Commented Sep 22, 2023 at 9:17
  • Actually, I need to reload firewalld after this task. I think one way is to use the service module in the next step, but is there any way to do this with the firewalld module itself?
    – Ali
    Commented Sep 22, 2023 at 9:28
  • You probably want to trigger a handler for this then (notify: <handler name>) Commented Sep 22, 2023 at 13:23

1 Answer 1

6

As per the documentation the firewalld module can only be used to add / remove / update rules from the firewalld ruleset. To reload the service use the service module like this (as per documentation):

- name: Always reload firewalld
  ansible.builtin.service:
    name: firewalld
    state: reloaded

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.