0%

0/1 Lessons

Course Introduction

• 16min

0 / 3 lessons complete

IT Lab Setup

• 20min

0 / 3 lessons complete

Installing Ansible

• 35min

0 / 3 lessons complete

Managing your Ansible Inventory

• 2hr 7min

0 / 8 lessons complete

Ansible Basics

• 1hr 43min

0 / 9 lessons complete

Ansible Roles

• 1hr 46min

0 / 8 lessons complete

Ansible Galaxy

• 1hr 33min

0 / 6 lessons complete

Ansible Facts, Variables, Passwords and Templates

• 1hr 51min

0 / 9 lessons complete

Advanced Ansible Playbook Creation

• 1hr 41min

0 / 8 lessons complete

Course Conclusion

• 11min

0 / 1 lessons complete

Creating Your First Ansible Role

Instructions

Q&A (0)

Notes (0)

Resources (0)

Saving Progress...

Resources

There are no resources for this lesson.

Notes can be saved and accessed anywhere in the course. They also double as bookmarks so you can quickly review important lesson material.

Create note

In this lesson, we will create your first Ansible Role named common. This role will be responsible for updating the server. Unlike using ansible-galaxy, which we'll explore later, you'll learn to create this role manually to better understand its structure.

Creating the Ansible Role Directory Structure

When setting up a role, it's standard practice to create a specific directory structure which Ansible expects and uses to locate files and tasks to execute. Ansible will look for these folders in the directory where you run the ansible-playbook command. This is why it's important to run the playbook command in the same directory where you files are located.

Be sure to cd into the directory where you have your ansible config and inventory defined before continuing, which in this course is ~/code

Let's start by creating the directory structure for our common role. Open your terminal and execute the following commands:

mkdir -p roles/common/{tasks,handlers,templates,files,vars,defaults,meta}

For this example, most of these folders will remain empty, but it's important for you to create them so you know that they exist and you can practice using them later.

If you want to view our newly created directories in a pretty format, you can install the tree utility like so:

sudo apt install tree

This will allow us to run the tree command in our home directory and see our newly created role folders:

paulh@ansible-controller:~/code$ tree 
.
├── ansible.cfg
├── ansible.cfg.example
├── first_playbook.yml
├── inventory
└── roles
    └── common
        ├── defaults
        ├── files
        ├── handlers
        ├── meta
        ├── tasks
        ├── templates
        └── vars

9 directories, 4 files

Make sure your output looks the same as mine as it will be important in future lectures.

Recall each folder's purpose within a role

Try to recall the purpose of each of these folders:

See if you can identify them, what they do, and what types of files should be located in each. Also, note that these are not ALL of the folders that can exist within a role, but these are definitely the most common.

Conclusion

That is all we need to do to setup our Ansible Role... see you in the next lesson!

Server Academy Members Only

Sorry, this lesson is only available to Server Academy Full Access members. Become a Full-Access Member now and you’ll get instant access to all of our courses.

0 0 votes
Lesson Rating
Subscribe
Notify of
profile avatar
0 Comments
Inline Feedbacks
View all comments