Answers: <p>Based on:</p>
  
  <blockquote>
  <pre><code># Allow OpenSSH. (Note that as ufw manages its own state, simply removing
  # a rule=allow task can leave those ports exposed. Either use delete=yes
  # or a separate state=reset task)
  </code></pre>
  </blockquote>
  
  <p>The following snippet was added to the top of the file:</p>
  
  <pre><code>---
  - name: Reset UFW
    ufw:
      state: reset
  </code></pre>
  
  <p>Once ansible was run:</p>
  
  <pre><code>TASK [rolename : Reset UFW]
  </code></pre>
  
  <p>the undefined ports were removed</p>
  
Answers: CC BY-SA 3.0
Answers: 2017-06-01T17:05:48.723Z
Answers: 2017-06-01T17:05:48.723Z
Answers: 030
Body: <p>The <a href="http://docs.ansible.com/ansible/ufw_module.html" rel="nofollow noreferrer">UFW module document</a> has been read, but it is unclear how to let ansible remove ports that are not defined anymore.</p>
  
  <p>It works to add new ports, but now 5 ports have been removed and I do not want to login to each of the more than 50 servers.</p>
  
  <p>It is possible to write some custom exec, but I would like to use the Ansible's UFW module's functionality. Does it support such a scenario?</p>
  
Tags: <ansible>
Title: How to ensure that removed allowed ports will be removed using Ansible's UFW module?
UserDisplayName: 030
ThreadText: # How to ensure that removed allowed ports will be removed using Ansible's UFW module?
  
  (Asked by: username_0 on 2017-06-01)
  
  The [UFW module document](http://docs.ansible.com/ansible/ufw_module.html) has been read, but it is unclear how to let ansible remove ports that are not defined anymore.
  
  It works to add new ports, but now 5 ports have been removed and I do not want to login to each of the more than 50 servers.
  
  It is possible to write some custom exec, but I would like to use the Ansible's UFW module's functionality. Does it support such a scenario?
  
  **Tags:** ansible
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2017-06-01. Score: 4 | Accepted answer
  
  Based on:
  
  > ```
  > # Allow OpenSSH. (Note that as ufw manages its own state, simply removing
  > # a rule=allow task can leave those ports exposed. Either use delete=yes
  > # or a separate state=reset task)
  >
  > ```
  
  The following snippet was added to the top of the file:
  
  ```
  ---
  - name: Reset UFW
    ufw:
      state: reset
  
  ```
  
  Once ansible was run:
  
  ```
  TASK [rolename : Reset UFW]
  
  ```
  
  the undefined ports were removed
  
  
  ---
  
  