Install iptables-persistent with Ansible

Well, this will be a really quick and straight-forward post about Ansible. 😀

You can save changes made of the iptables rules either directly from the command line or with a playbook. (Check my post on how to do that: “How we manage IPtables – now and then”.)

In order for the saved rules to be loaded automatically on boot we need: iptables-persistent package to be installed.

We can do that, pretty simple with an Ansible playbook:

 - name: Install IPtables-persistent
      apt:
        name:
          - iptables-persistent
        update_cache: yes
        state: present

With the task above, we can be sure that the iptables-persistent package, will be installed. You can check the Ansible documentation on what other choices you have with the parameter: state. One of the others parameters of the apt module is :

 update_cache: yes

which is equivalent of

 apt-get update

This can also be run as a separate task.

 

That was it. 🙂

All of the examples are configured on Cloud Virtual Machine, provided by: CloudBalkan

Leave a Reply

Your email address will not be published. Required fields are marked *