Creating Ansible roles

Let's now create an Ansible role from scratch. This role is a Samba file server setup on either of the big families of Linux. It serves a folder that is accessible via a shared user.

First, let's create our role folder using the ansible-galaxy command line. Before running the command, we need to change the Terminal workspace to the location in which we would like to store our Ansible roles:

cd ~/Roles/ansible-galaxy init samba.lab.edu

We should see the following output:

- samba.lab.edu was created successfully

We then create a folder with the name of the role, with the following structure of subfolders and files:

samba.lab.edu└── README.md├── defaults│ └── main.yml├── files│ ├── handlers│ └── main.yml├── meta│ └── main.yml ...

Get Ansible Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.