Answers: <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>
  
Answers: CC BY-SA 4.0
Answers: 2023-09-22T09:55:34.803Z
Answers: 2023-09-22T09:55:34.803Z
Answers: YoshiMbele
Body: <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>
  
Comments: CC BY-SA 4.0
Comments: 2023-09-22T09:17:38.257Z
Comments: 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?
Comments: Bruce Becker
Comments: CC BY-SA 4.0
Comments: 2023-09-22T09:28:06.973Z
Comments: 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?
Comments: Ali
Comments: CC BY-SA 4.0
Comments: 2023-09-22T13:23:58.333Z
Comments: You probably want to trigger a handler for this then (notify: <handler name>)
Comments: Bruce Becker
Tags: <ansible>
Title: How to reload the Firewalld service using Ansible?
UserDisplayName: Ali
ThreadText: # 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](https://docs.ansible.com/ansible/latest/collections/ansible/posix/firewalld_module.html) 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](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/service_module.html)):
  
  ```
  - name: Always reload firewalld
    ansible.builtin.service:
      name: firewalld
      state: reloaded
  
  ```
  
  
  ---
  
  