Basics

The standard layout for a project is usually split into roles that define functionality slices with the rest of the configurations basically just supporting those roles. The basic file structure of Ansible projects looks something like this (though more complex setups are often needed):

.
├── group_vars
│ └── all
├── hosts
├── named-role-1-server.yml
└── roles
├── named-role-1
│ ├── tasks
│ │ └── main.yml
│ ├── files
│ │ └── ...
│ ├── templates
│ │ └── ...
│ └── vars
│ └── main.yml
...

 

Let us break down the basic structure of this filesystem tree and see how each piece is used in the bigger picture:

  • group_vars/all: This file is used to define variables that are used for all of your playbooks. These can be used in playbooks and templates with variable expansions ("{{ variable_name }}").
  • hosts/: This file or a directory lists hosts and groups that you want to manage and any specific connectivity details like protocol, username, SSH key, and so on. In documentation, this file is often called the inventory file.
  • roles/: This holds a list of role definitions that can be applied in a hierarchical and layered way to a target machine. Usually, it is further subdivided into tasks/, files/, vars/, and other layout-sensitive structures within each role:
    • <role_name>/tasks/main.yml: A YAML file that lists the main steps to execute as part of the role.
    • <role_name>/files/...: Here you would add static files that would be copied to target a machine that do not require any pre-processing.
    • <role_name>/templates/...: In this directory, you would add template files for role-related tasks. These usually contain templates that will be copied to the target machine with variable substitutions.
    • <role_name>/vars/main.yml: Just like the parent directory implies, this YAML file holds role-specific variable definitions.
  • playbooks/: In this directory, you would add all top-level ancillary playbooks that do not fit well in role definitions.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.131.62