<p>As per the <a href="https://docs.ansible.com/ansible/latest/collections/ansible/posix/firewalld_module.html" rel="noreferrer">documentation</a> the firewalld module can only be used to add / remove / update rules from the firewalld ruleset. To reload the service use the <code>service</code> module like this (as per <a href="https://docs.ansible.com/ansible/latest/collections/ansible/builtin/service_module.html" rel="noreferrer">documentation</a>):</p>
<pre><code>- name: Always reload firewalld
  ansible.builtin.service:
    name: firewalld
    state: reloaded
</code></pre>

CC BY-SA 4.0
2023-09-22T09:55:34.803Z
2023-09-22T09:55:34.803Z
YoshiMbele
<p>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?</p>
<p>Here is my Ansible code:</p>
<pre><code>- name: Add port to firewalld
  firewalld:
    port: &quot;{{ item }}&quot;
    permanent: yes
    state: enabled
  when: ansible_distribution == 'CentOS' or ansible_distribution == 'Red Hat Enterprise Linux'
  loop:
    - 8080/tcp
    - 8000/tcp
    - 8090/tcp
    - 8040/tcp
</code></pre>

CC BY-SA 4.0
2023-09-22T09:17:38.257Z
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?
Bruce Becker
CC BY-SA 4.0
2023-09-22T09:28:06.973Z
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
CC BY-SA 4.0
2023-09-22T13:23:58.333Z
You probably want to trigger a handler for this then (notify: <handler name>)
Bruce Becker
<ansible>
How to reload the Firewalld service using Ansible?
Ali
# How to reload the Firewalld service using Ansible?

(Asked by: username_0 on 2023-09-22)

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

**Tags:** ansible

> **Comments:**
> **username_1**: 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?  
> **username_0**: 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?  
> **username_1**: You probably want to trigger a handler for this then (notify: <handler name>)  

---

## 1 answers

### Answer by username_2 on 2023-09-22. Score: 6 | Accepted answer

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


---

