Level 1
0 / 100 XP

Initializing a Firewall Role with Ansible Galaxy

In this lesson, we're going to learn how to use Ansible Galaxy to initialize a role for setting up a basic firewall using iptables on Ubuntu Server. By the end of this lesson, you'll be able to create an Ansible role to configure iptables rules, enhancing the security of your managed nodes.

In this example, we will create an ansible role that will create a logging rule to log all inbound traffic to our managed nodes.

What is iptables?

Before configuring iptables, let's take a moment to understand its role. iptables is a robust and flexible tool for network packet filtering in Linux. It serves as the foundation for setting up firewalls on a system.

Essentially, iptables allows you to define rules for how incoming, outgoing, and forwarding network traffic should be handled. In this lesson, our focus is primarily on setting up logging rules. These rules are vital for monitoring and analyzing incoming traffic, which is an integral part of maintaining and enhancing system security.

Iptables is covered in dept in our Linux Fundamentals course, so if you want to learn more I recommend you complete that course (it's listed as a prerequisite to this course).

Initializing the Role with Ansible Galaxy

First, navigate to your roles directory:

cd ~/code/roles

Now let's initialize a new role for iptables using Ansible Galaxy, run:

ansible-galaxy role init iptables_setup

This command creates a new directory in our roles folder called iptables_setup with a standard structure. This structure includes directories for tasks, handlers, templates, files, vars, defaults, and more. If I tree the new directory I will see a new folder with the iptables_setup directory:

Text
paulh@ansible-controller:~/code/roles$ tree iptables_setup/ iptables_setup/ ├── defaults │ └── main.yml ├── files ├── handlers │ └── main.yml ├── meta │ └── main.yml ├── README.md…