Featured resource
2025 Tech Upskilling Playbook
Tech Upskilling Playbook

Build future-ready tech teams and hit key business milestones with seven proven plays from industry leaders.

Check it out
  • Lab
    • Libraries: If you want this lab, consider one of these libraries.
    • Cloud
Google Cloud Platform icon
Labs

Using Ansible Firewall Rules

Being able to use Ansible to create and change firewall rules is a valuable skill. On top of that, it is now an objective of the *Red Hat Certified Ansible Specialist* exam. In this lab we will create playbooks using the firewalld module, and use them to perform firewall related tasks. Note: Ansible has been set up and configured for use which will save you time when doing this hands-on lab. *This course is not approved or sponsored by Red Hat.*

Google Cloud Platform icon
Lab platform
Lab Info
Level
Intermediate
Last updated
Sep 04, 2025
Duration
45m

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
Table of Contents
  1. Challenge

    Sign on to the Ansible Control Node Server as cloud_user and change to the `ansible` user. Test to ensure that Ansible has been set up for you.
    1. Sign in to the server called Ansible Control Node using the cloud_user, and then change to the ansible user via the su - ansible command.

    2. Test that Ansible is working via an ad-hoc command. We can use the following:

      ansible all -m ping
      
  2. Challenge

    Ensure that `firewalld` is not installed on the Ansible nodes, `node1` and `node2`
    1. Check that firewalld is not installed on the nodes:
    ssh node1
    sudo systemctl status firewalld
    
    1. Use exit to move onto the next node check:
    ssh node2
    sudo systemctl status firewalld
    
  3. Challenge

    Using an Ansible playbook, install the Apache Web Server, `httpd` and also `elinks` onto the Ansible nodes and start the Apache Web Server.
    1. Create the playbook:
    vim setup-server.yml
    
    1. The playbook file could appear like so for the installations, plus enabling and starting the Apache Web Server:
    ---
    - hosts: all
      user: ansible
      become: yes
      gather_facts: no
      tasks:
        - name: install elinks
          action: yum name=elinks state=installed
        - name: install httpd
          action: yum name=httpd state=installed
        - name: Enable Apache on system reboot
          service: name=httpd enabled=yes
        - name: Start service httpd, if not started
          service:
            name: httpd
            state: started
    
  4. Challenge

    Ensure the webserver is working and test that apache on the nodes can be accessed.
    1. Using the elinks command. We will verify that we can see the Apache HTTP Server test page on the 2 Ansible nodes with the following commands:
    elinks http://node1
    elinks http://node2
    
  5. Challenge

    Using the playbook, install `firewalld` on the Ansible nodes. Ensure the `firewalld` is running. Test the Apache test pages are not available.
    1. Make changes to the playbook for installing firewalld:
    ---
    - hosts: all
      user: ansible
      become: yes
      gather_facts: no
      tasks:
        - name: install elinks
          action: yum name=elinks state=installed
        - name: install httpd
          action: yum name=httpd state=installed
        - name: Enable Apache on system reboot
          service: name=httpd enabled=yes
        - name: Start service httpd, if not started
          service:
            name: httpd
            state: started
        - name: install firewalld
          action: yum name=firewalld state=installed
        - name: Enable firewalld on system reboot
          service: name=firewalld enabled=yes
        - name: Start service firewalld, if not started
          service:
            name: firewalld
            state: started
    
    1. Save and exit.
    2. Run the playbook with the changes applied:
    vim setup-server.yml
    ansible-playbook setup-server.yml
    
    1. Verify that we are unable to access the test pages on node1 and node2 with the following commands:
    elinks http://node1
    elinks http://node2
    

    Note: We will be unable to access the test pages because the firewall will be blocking them.

  6. Challenge

    Change the Ansible playbook to add the firewall rule to allow port 80.
    1. Make changes to the playbook for installing firewalld:
    ---
    - hosts: all
      user: ansible
      become: yes
      gather_facts: no
      tasks:
        - name: install elinks
          action: yum name=elinks state=installed
        - name: install httpd
          action: yum name=httpd state=installed
        - name: Enable Apache on system reboot
          service: name=httpd enabled=yes
        - name: Start service httpd, if not started
          service:
            name: httpd
            state: started
        - name: install firewalld
          action: yum name=firewalld state=installed
        - name: Enable firewalld on system reboot
          service: name=firewalld enabled=yes
        - firewalld:
            service: http
              permanent: yes
              state: enabled
          - name: Restart service firewalld
            service:
            name: firewalld
            state: restarted
    
    1. Save and exit.
    2. Run the playbook with the changes applied:
    vim setup-server.yml
    ansible-playbook setup-server.yml
    
    1. Verify that we are unable to access the test pages on node1 and node2 with the following commands:
    elinks http://node1
    elinks http://node2
    

    Note: We will be unable to access the test pages because the firewall will be blocking them.

  7. Challenge

    Test that you can access the test pages on the web servers on the 2 Ansible nodes.
    1. Run the playbook:
    vim setup-server.yml
    ansible-playbook setup-server.yml
    
    1. Using the elinks command again:
     elinks http://node1
     elinks http://node2
    
About the author

Pluralsight Skills gives leaders confidence they have the skills needed to execute technology strategy. Technology teams can benchmark expertise across roles, speed up release cycles and build reliable, secure products. By leveraging our expert content, skill assessments and one-of-a-kind analytics, keep up with the pace of change, put the right people on the right projects and boost productivity. It's the most effective path to developing tech skills at scale.

Real skill practice before real-world application

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Learn by doing

Engage hands-on with the tools and technologies you’re learning. You pick the skill, we provide the credentials and environment.

Follow your guide

All labs have detailed instructions and objectives, guiding you through the learning process and ensuring you understand every step.

Turn time into mastery

On average, you retain 75% more of your learning if you take time to practice. Hands-on labs set you up for success to make those skills stick.

Get started with Pluralsight