Understand Core Components of Ansible - Playbooks

30 minutes
  • 2 Learning Objectives

About this Hands-on Lab

Ansible is all about automation and making an administrator’s life easier. So rather than chaining ad hoc commands together, you can set up a Playbook to run multiple commands at once. This hands-on lab will help enhance your understanding of building a playbook.

*This course is not approved or sponsored by Red Hat.*

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Write and Execute the Playbook to Install Software

Your playbook should look something like this:

# Software playbook

- name: Install required software
  hosts: all

   - yum: 
      name: "{{ packages }}"
      state: present
        - httpd 
        - git
        - tcpdump
        - php

   - service: 
      name: httpd
      state: started
      enabled: yes

You can then run the command with ansible-playbook software.yml --become

Write and Execute the Playbook to Add and Configure the Required Users

Your playbook should look something like this:

# Create required users

- name: Create required users
  hosts: all
    - devs
    - security
    - admins

   - group:
      name: web
      state: present

   - user:
      name: "{{ item }}"
      state: present
      groups: web
      append: yes
     with_items: "{{ usernames }}"

Just like with the last playbook, we’ll run it with an ansible-playbook command:

ansible-playbook users.yml --become

Additional Resources

Notice: Ansible is installed as the root user, so please work on all tasks after elevating to the root user.

We're in the midst of a proof of concept project. Now, we've been tasked with writing a playbook that will set our machine up as a web server, with the normal software that our company's web servers typically have running on them. The playbook must install the following software:


Then we need to set up a second playbook that creates the following users:


All of those users should be members of the web group.

What are Hands-on Labs

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.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?