In the previous lesson you designed the plan for turning Aurora Store's playbooks into roles. Now the work begins, and you'll start with the simplest of the three: common.yml, the configuration every server receives. You'll learn to prepare the project for roles with the roles_path option, to generate a role skeleton with ansible-galaxy role init, to migrate the tasks step by step without breaking anything, to tell apart the two kinds of role variables (defaults and vars) and to name them with the role's prefix so they're reusable. The most important thing in this lesson is the method: every step is verified by running site.yml and checking that the result is changed=0, because a well-done refactoring doesn't change the servers.
Contents
- Where Ansible looks for roles:
roles/androles_path - Generating the skeleton with
ansible-galaxy role init - Keeping only what's needed
- Step 1: moving the tasks from
common.ymlinto the role - Step 2: applying the role from
common.yml - Step 3: checking that nothing changes
defaultsandvars: the two kinds of role variables- A role's variables are visible across the whole play
- Step 4: variables with the role's prefix
- Step 5: the inventory feeds the role
- Verifying again and saving the work
- Where Ansible looks for roles:
roles/ and roles_path
roles/ and roles_pathWhen a play says roles: [common], Ansible looks for a common directory in this order:
- A
roles/directory next to the playbook being run. Since Aurora's playbooks are at the root of the repository (a Module 3 decision),~/aurora-infra/roles/will work without configuring anything. - The paths in the
roles_pathoption ofansible.cfg(or theANSIBLE_ROLES_PATHenvironment variable). Its default value is~/.ansible/roles:/usr/share/ansible/roles:/etc/ansible/roles. - The playbook's own directory.
If roles/ next to the playbook already works, why configure roles_path? For three reasons:
- Other tools don't run a playbook:
ansible-doc -t role, which you'll use in Lesson 4.6, only finds roles throughroles_path. - Playbooks in subdirectories: if one day you move the playbooks to a
playbooks/directory (you'll consider it in Lesson 9.1), theroles/"next to the playbook" would no longer be the one at the root. - Explicit is better than implicit: anyone reading
ansible.cfgwill know where the project's roles are.
Open ~/aurora-infra/ansible.cfg and add, in the [defaults] section, after inventory = inventory:
Just like inventory, the path is relative to the directory of ansible.cfg. Notice that this value replaces the default list: Ansible will no longer look in ~/.ansible/roles. That's what we want for now, because all of Aurora's roles will be in the repository; you'll decide where to keep the third-party roles you install with ansible-galaxy in Lesson 6.3.
Create the directory and check the configuration:
- Generating the skeleton with
ansible-galaxy role init
ansible-galaxy role initYou could create the role's directories by hand with mkdir, but ansible-galaxy includes a generator that creates the complete standard structure:
role initcreates a new role from a skeleton.--init-path rolessays where to create it; without that option, it would be created in the current directory.commonis the role's name. Use lowercase letters, numbers and underscores (aurora_app), never hyphens (aurora-app): the name must be a valid identifier so it can be used later in collections and on Galaxy.
Look at what it has generated:
roles/common
├── README.md
├── defaults
│ └── main.yml
├── files
├── handlers
│ └── main.yml
├── meta
│ └── main.yml
├── tasks
│ └── main.yml
├── templates
├── tests
│ ├── inventory
│ └── test.yml
└── vars
└── main.ymlA quick overview (each directory is studied in depth in Lesson 4.3):
| Item | What it's for |
|---|---|
tasks/main.yml |
The role's tasks: what runs when it's applied |
defaults/main.yml |
Variables with a default value, meant to be changed by the role's user |
vars/main.yml |
The role's internal variables, which shouldn't be changed from outside |
handlers/main.yml |
The role's handlers (Lesson 5.1) |
files/ |
Files the role copies as they are to the servers |
templates/ |
Jinja2 templates (Lesson 5.2) |
meta/main.yml |
Metadata (author, license, platforms) and dependencies |
tests/ |
A minimal test inventory and playbook |
README.md |
The role's documentation |
The generated main.yml files only contain --- and a comment (depending on the version, also a first line #SPDX-License-Identifier: MIT-0). meta/main.yml and README.md come with a template that you'll fill in.
- Keeping only what's needed
An empty directory does no harm, but a role with ten folders of which it uses three forces you to open them all to discover they contain nothing. In Aurora, each role will have only the directories it uses. For common:
tasks/,defaults/andmeta/: essential.vars/: you'll use it in step 4 for an internal constant.README.md: you'll complete it in Lesson 4.6.files/,templates/,handlers/andtests/:commondoesn't need them for now. Role testing will be done with Molecule (Lesson 9.5), not withtests/.
And leave roles/common/meta/main.yml with some minimal metadata (replace its entire content):
---
galaxy_info:
author: Alex Admin
description: Base server configuration (packages, time zone, users, motd and local facts)
company: Aurora Store
license: proprietary
min_ansible_version: "2.17"
platforms:
- name: Ubuntu
versions:
- noble
dependencies: []galaxy_info describes the role (you'll make use of it when sharing roles in Lesson 6.4) and dependencies lists other roles that must run first (Lesson 4.6). Lesson 4.3 explains each field.
- Step 1: moving the tasks from
common.yml into the role
common.yml into the roleThe first migration is literal: copy the tasks as they are, without improving anything yet. If you change many things at once and something fails, you won't know what it was. Replace the content of roles/common/tasks/main.yml with the tasks from common.yml:
---
- name: Install the common packages (Debian family)
ansible.builtin.apt:
name: "{{ aurora_common_packages }}"
state: present
update_cache: true
cache_valid_time: 3600
when: ansible_facts['os_family'] == 'Debian'
- name: Install the common packages (Red Hat family)
ansible.builtin.dnf:
name: "{{ aurora_common_packages }}"
state: present
when: ansible_facts['os_family'] == 'RedHat'
- name: Set the time zone
community.general.timezone:
name: "{{ aurora_timezone }}"
- name: Manage the Aurora team users
ansible.builtin.user:
name: "{{ item.name }}"
comment: "{{ item.comment }}"
shell: /bin/bash
state: "{{ item.state | default('present') }}"
loop: "{{ aurora_team_users }}"
loop_control:
label: "{{ item.name }}"
- name: Grant administrator privileges to the team admins
ansible.builtin.user:
name: "{{ item.name }}"
groups: sudo
append: true
loop: "{{ aurora_team_users }}"
loop_control:
label: "{{ item.name }}"
when:
- item.admin | default(false)
- item.state | default('present') == 'present'
- name: Configure the welcome message (motd)
ansible.builtin.copy:
dest: /etc/motd
owner: root
group: root
mode: "0644"
content: |
==========================================================
Aurora Store - {{ inventory_hostname }} ({{ aurora_env }})
Access restricted to authorized personnel.
Incidents: {{ aurora_admin_email }}
==========================================================
- name: Create the local facts directory
ansible.builtin.file:
path: /etc/ansible/facts.d
state: directory
owner: root
group: root
mode: "0755"
- name: Publish the Aurora Store local facts
ansible.builtin.copy:
dest: /etc/ansible/facts.d/aurora.fact
owner: root
group: root
mode: "0644"
content: |
[general]
env={{ aurora_env }}
domain={{ aurora_domain }}
groups={{ group_names | join(',') }}
managed_by=aurora-infra
register: aurora_local_facts
- name: Re-read the local facts if they have changed
ansible.builtin.setup:
filter: ansible_local
when: aurora_local_facts.changedNotice how the format differs from the playbook:
- A role's task file is directly a list of tasks. There's no play
- name:, nohosts:and notasks:: those decisions belong to the playbook. - That's why the tasks start at column 0 (in the playbook they were indented four spaces under
tasks:). If you copy and paste, remove that indentation uniformly. - There's no
become: trueeither: it's inherited from the play that applies the role, as you'll see shortly.
- Step 2: applying the role from
common.yml
common.ymlNow common.yml no longer needs its tasks. Replace its content with:
---
- name: Common configuration for Aurora Store servers
hosts: aurora
become: true
roles:
- commonThat's all: the play decides where (hosts: aurora) and with what privileges (become: true); the role provides the how. Play keywords, such as become, apply to all the role's tasks.
- Step 3: checking that nothing changes
First, the syntax and the task list:
playbook: common.yml
play #1 (aurora): Common configuration for Aurora Store servers TAGS: []
tasks:
common : Install the common packages (Debian family) TAGS: []
common : Install the common packages (Red Hat family) TAGS: []
common : Set the time zone TAGS: []
common : Manage the Aurora team users TAGS: []
common : Grant administrator privileges to the team admins TAGS: []
common : Configure the welcome message (motd) TAGS: []
common : Create the local facts directory TAGS: []
common : Publish the Aurora Store local facts TAGS: []
common : Re-read the local facts if they have changed TAGS: []Each task appears with the common : prefix, which tells you which role it comes from. Now the real test: since the servers have already been configured since Module 3, the run must not change anything.
PLAY [Common configuration for Aurora Store servers] ***************************
TASK [Gathering Facts] *********************************************************
ok: [web1]
ok: [web2]
ok: [db1]
TASK [common : Install the common packages (Debian family)] ********************
ok: [web1]
ok: [db1]
ok: [web2]
...
PLAY RECAP *********************************************************************
db1 : ok=... changed=0 unreachable=0 failed=0 ...
web1 : ok=... changed=0 unreachable=0 failed=0 ...
web2 : ok=... changed=0 unreachable=0 failed=0 ...changed=0 on all three servers: the role does exactly the same as the playbook. If any task came out changed, repeat with --check --diff --limit web1 to see the exact difference; it's almost always a line of content: that lost or gained spaces when it was moved.
The
aptcache task may come outchangedif more than one hour has passed since the last update (Lesson 3.4). It isn't a refactoring error.
Make a first commit of this stable point:
git add ansible.cfg roles/common common.yml
git commit -m "common role: literal migration of common.yml"
defaults and vars: the two kinds of role variables
defaults and vars: the two kinds of role variablesThe role works, but it isn't reusable: its tasks read Aurora project variables (aurora_timezone, aurora_team_users…) that won't be defined in another project. A role must declare its own variables, and it has two directories for that:
| Aspect | defaults/main.yml |
vars/main.yml |
|---|---|---|
| Purpose | The role's parameters: what the user can (and usually does) change | Internal constants: values the role needs and that shouldn't be changed from outside |
| Precedence | The lowest of all (level 2 in the table from Lesson 3.5) | High (level 12): above the inventory and the play's vars: |
| Overridden by | Almost everything: inventory, the play's vars:, role parameters, -e… |
Only include_vars, set_fact, role parameters and -e |
| Examples | Time zone, package list, port | A fixed path the software expects, the package or service name on a distribution |
| Question to decide | Is it reasonable for someone to want another value? → defaults |
Would changing it break the role? → vars |
The difference in precedence is what matters. A variable in defaults/ is a suggestion: it's used if nobody says otherwise. A variable in vars/ is almost an imposition: it beats the inventory. A classic mistake is putting in vars/ what should go in defaults/ and then not understanding why the inventory value "is ignored" (you'll check this in Exercise 2).
In practice, almost all of a role's variables go in defaults/. vars/ is reserved for a few internal values. common has a perfect example: the local facts directory, /etc/ansible/facts.d. It's the path where the setup module looks for .fact files by default (Lesson 3.5); if someone changed it, the role would write the facts somewhere nobody would read them.
- A role's variables are visible across the whole play
There's a detail of how this works that justifies the naming convention you'll adopt now. When a play applies roles with roles:, the variables in each role's defaults/ and vars/ don't stay inside the role: they're visible to the rest of the play, including the playbook's own tasks and the other roles. For example, if a web role defines a port: 80 variable in its defaults and another db role in the same play defines port: 5432, one of the two will end up reading the other's value.
That's why the Module 3 rule ("a prefix per component") becomes this for roles: all of a role's variables start with the role's name. common_timezone, never timezone. This also applies to variables registered inside the role: common_local_facts instead of aurora_local_facts. The rule has another advantage: when you read the inventory, you immediately know which variable belongs to which role.
- Step 4: variables with the role's prefix
Design the role's parameters from what is currently specific to Aurora. Write roles/common/defaults/main.yml:
---
# Default values for the common role.
# All of them can be overridden from the inventory.
# Basic packages installed on every server.
common_packages:
- curl
- vim
# System time zone.
common_timezone: Etc/UTC
# Users to manage. Each item accepts:
# name (mandatory), comment, admin (true -> sudo group),
# state (present/absent; present by default).
common_users: []
# Server identification, used in the welcome message and in the local facts.
common_organization: Server managed with Ansible
common_env: production
common_domain: localdomain
common_contact: root@localhost
# Local facts: published in <common_facts_dir>/<common_facts_name>.fact
common_facts_name: local
common_managed_by: ansible- The default values are generic and safe: with them, the role works on any server without configuring anything (it installs two packages, leaves the time zone in UTC and doesn't create users).
- Each variable has a comment:
defaults/main.ymlis the role's first piece of documentation. In Lesson 4.6 you'll add a formal specification with validation. common_users: [](an empty list): the loop doesn't run at all, so the role doesn't touch users unless someone asks it to.
And roles/common/vars/main.yml, with the internal constant:
---
# Internal variables of the common role. Do not override.
# Directory where the setup module looks for local facts.
common_facts_dir: /etc/ansible/facts.dNow update roles/common/tasks/main.yml so it only uses the role's variables. It's also a good moment to remove "Aurora" from the task names, because the role is no longer exclusive to the store:
---
- name: Install the common packages (Debian family)
ansible.builtin.apt:
name: "{{ common_packages }}"
state: present
update_cache: true
cache_valid_time: 3600
when: ansible_facts['os_family'] == 'Debian'
- name: Install the common packages (Red Hat family)
ansible.builtin.dnf:
name: "{{ common_packages }}"
state: present
when: ansible_facts['os_family'] == 'RedHat'
- name: Set the time zone
community.general.timezone:
name: "{{ common_timezone }}"
- name: Manage the team users
ansible.builtin.user:
name: "{{ item.name }}"
comment: "{{ item.comment | default(omit) }}"
shell: /bin/bash
state: "{{ item.state | default('present') }}"
loop: "{{ common_users }}"
loop_control:
label: "{{ item.name }}"
- name: Grant administrator privileges to the team admins
ansible.builtin.user:
name: "{{ item.name }}"
groups: sudo
append: true
loop: "{{ common_users }}"
loop_control:
label: "{{ item.name }}"
when:
- item.admin | default(false)
- item.state | default('present') == 'present'
- name: Configure the welcome message (motd)
ansible.builtin.copy:
dest: /etc/motd
owner: root
group: root
mode: "0644"
content: |
==========================================================
{{ common_organization }} - {{ inventory_hostname }} ({{ common_env }})
Access restricted to authorized personnel.
Incidents: {{ common_contact }}
==========================================================
- name: Create the local facts directory
ansible.builtin.file:
path: "{{ common_facts_dir }}"
state: directory
owner: root
group: root
mode: "0755"
- name: Publish the local facts
ansible.builtin.copy:
dest: "{{ common_facts_dir }}/{{ common_facts_name }}.fact"
owner: root
group: root
mode: "0644"
content: |
[general]
env={{ common_env }}
domain={{ common_domain }}
groups={{ group_names | join(',') }}
managed_by={{ common_managed_by }}
register: common_local_facts
- name: Re-read the local facts if they have changed
ansible.builtin.setup:
filter: ansible_local
when: common_local_facts is changedThe changes, one by one:
aurora_common_packages→common_packages,aurora_timezone→common_timezone,aurora_team_users→common_users.- The fixed text "Aurora Store" in the
motdbecomescommon_organization;aurora_envandaurora_admin_emailbecomecommon_envandcommon_contact. - The path and name of the facts file come from
common_facts_dir(internal) andcommon_facts_name(parameter), andmanaged_byfromcommon_managed_by. - The registered variable is now called
common_local_facts, and the condition uses theis changedtest from Lesson 3.7. commentusesdefault(omit): if a user in the list has no comment, the parameter isn't sent to the module (instead of failing because of an undefined variable).omitis a special Ansible value designed precisely for this; filters are studied in depth in Lesson 5.3.
- Step 5: the inventory feeds the role
If you ran it now, the role would use its default values: UTC time zone, no users, a generic motd… and idempotency would break. The last step is missing: the inventory must give the role's variables Aurora's values.
Create inventory/group_vars/all/common.yml:
---
# common role parameters for Aurora Store (all servers).
common_packages:
- htop
- curl
- vim
- tree
common_timezone: Europe/Madrid
common_organization: Aurora Store
common_env: "{{ aurora_env }}"
common_domain: "{{ aurora_domain }}"
common_contact: "{{ aurora_admin_email }}"
common_facts_name: aurora
common_managed_by: aurora-infra- Values used only by this role (packages, time zone) are defined directly.
- The general project data (
aurora_env,aurora_domain,aurora_admin_email) stays inaurora.yml, because other roles will use it too, and the inventory connects it to the role's variables. The role knows nothing about Aurora; the inventory acts as the "wiring". - Since
group_vars/all/is a directory, Ansible loads all its files (Lesson 2.2):aurora.yml,team.ymland nowcommon.yml.
Remove from inventory/group_vars/all/aurora.yml the two variables that have moved to common.yml (aurora_timezone and aurora_common_packages). It ends up like this:
---
aurora_domain: aurora-store.example
aurora_env: lab
aurora_admin_email: [email protected]And in inventory/group_vars/all/team.yml, rename the aurora_team_users variable to common_users (the content doesn't change):
---
# Aurora Store team users (on every server), for the common role.
# admin: true -> member of the sudo group
# state: absent -> the user is removed
common_users:
- name: deploy
comment: Aurora Store deployments
- name: laura
comment: Laura Gómez - Development
admin: true
- name: marc
comment: Marc Soler - Operations
admin: true
- name: jordi
comment: Former contributor
state: absentCheck that the inventory resolves the expected values:
ansible web1 -m ansible.builtin.debug -a 'var=common_env'
ansible web1 -m ansible.builtin.debug -a 'var=common_facts_dir'web1 | SUCCESS => {
"common_env": "lab"
}
web1 | SUCCESS => {
"common_facts_dir": "VARIABLE IS NOT DEFINED!"
}The second answer is correct: common_facts_dir is in the role's vars/main.yml, and a role's variables only exist when a play runs that role. An ad hoc command only sees the inventory.
Before moving on, look for leftovers of the old names across the whole repository:
Nothing should appear (except, perhaps, in the Git history, which grep doesn't read). A variable renamed in one place and forgotten in another is the most frequent mistake in this kind of refactoring.
- Verifying again and saving the work
Simulate first and then run:
TASK [common : Configure the welcome message (motd)] ***************************
ok: [web1]
ok: [web2]
ok: [db1]
TASK [common : Create the local facts directory] *******************************
ok: [web1]
ok: [web2]
ok: [db1]
TASK [common : Publish the local facts] ****************************************
ok: [web1]
ok: [web2]
ok: [db1]
TASK [common : Re-read the local facts if they have changed] *******************
skipping: [web1]
skipping: [web2]
skipping: [db1]
...
PLAY RECAP *********************************************************************
db1 : ok=... changed=0 unreachable=0 failed=0 ...
web1 : ok=... changed=0 unreachable=0 failed=0 ...
web2 : ok=... changed=0 unreachable=0 failed=0 ...changed=0 once again: the motd and the aurora.fact file generated with the new variables are byte-for-byte identical to the previous ones. If --diff showed a difference in the motd, compare the value of each variable with ansible web1 -m ansible.builtin.debug -a 'var=...'.
Save the work:
git add ansible.cfg roles/common common.yml inventory/
git commit -m "common role: prefixed variables, defaults, vars and inventory"Repository structure at the end of the lesson:
aurora-infra/
├── ansible.cfg ← + roles_path = roles
├── site.yml
├── common.yml ← only applies the common role
├── dbservers.yml
├── webservers.yml
├── inventory/
│ ├── hosts.yml
│ ├── group_vars/
│ │ ├── all/
│ │ │ ├── aurora.yml ← only general project data
│ │ │ ├── common.yml ← new: common role parameters
│ │ │ └── team.yml ← common_users
│ │ ├── dbservers.yml
│ │ └── webservers.yml
│ └── host_vars/
│ ├── db1.yml
│ ├── web1.yml
│ └── web2.yml
├── roles/
│ └── common/
│ ├── README.md
│ ├── defaults/main.yml
│ ├── meta/main.yml
│ ├── tasks/main.yml
│ └── vars/main.yml
└── lab/
└── VagrantfileCommon Mistakes and Tips
ERROR! the role 'common' was not found in ...: the directory isn't inroles/next to the playbook or inroles_path, or it has another name (Common,common-role). The message lists every path it searched: read them.- Copying the tasks with the playbook's indentation: a task file that starts with four spaces or that keeps
tasks:causes syntax errors or "not a valid attribute". A role's tasks start at column 0. - Putting a play's
hosts:orbecome:insidetasks/main.yml: a role doesn't decide its hosts.becomecan go on a specific task, but the norm is to inherit it from the play. - Variables in
vars/that the user needs to change: the inventory won't be able to override them. When in doubt,defaults/. - Renaming a variable halfway: the role uses the new name and the inventory keeps the old one; the role applies its default value without raising an error, and the servers change.
--check --diffbefore running and agrepfor the old name prevent it. - Improving and migrating at the same time: first move the code as it is and verify
changed=0; then improve, and verify again. Two small commits are easier to review (and to undo) than one big one. - Tip:
ansible-galaxy role init --role-skeleton <directory>creates roles from your own skeleton. If your team creates many roles, a skeleton with your startingmeta/main.ymlandREADME.mdsaves time and unifies the style.
Exercises
Exercise 1: Removing a package from the list
Remove tree from common_packages in the inventory and run ansible-playbook site.yml --check. How many tasks come out changed? Is tree uninstalled from the servers? Explain why and propose how it would be uninstalled correctly. When you're done, leave the list as it was.
Exercise 2: defaults versus vars
Temporarily add common_timezone: Etc/UTC to roles/common/vars/main.yml and run ansible-playbook common.yml --check --diff --limit web1. Which time zone would the role apply? Why isn't the inventory's Europe/Madrid value respected? Undo the change.
Exercise 3: Where does each variable go?
For a redis role you're going to write, state whether each value should go in defaults/main.yml, in vars/main.yml or in the project inventory, and what name you'd give it:
- The port Redis listens on (6379 by default).
- The path of the configuration file that the Ubuntu package expects (
/etc/redis/redis.conf). - The maximum memory Aurora wants to give Redis on
db1: 256 MB. - The name of the systemd service on Ubuntu (
redis-server).
Solutions
Exercise 1. No task comes out changed, and tree is not uninstalled. state: present only guarantees that the packages in the list are installed; it says nothing about the ones that aren't in it. Removing something from a declarative list isn't the same as deleting it from the server (it's the same principle you saw with users in Lesson 3.6). To uninstall it, you'd have to add an explicit list to the role, for example common_packages_absent: [] in defaults, and a task with state: absent that loops over it; the inventory would set common_packages_absent: [tree].
Exercise 2. With --diff you'll see that the role would change the time zone to Etc/UTC. Variables in vars/main.yml have higher precedence (level 12) than the inventory's group_vars (levels 3 to 7), so the role's value wins. That's exactly why configurable parameters go in defaults/, which has the lowest precedence. Remember to delete the line from vars/main.yml and check again that --check gives changed=0.
Exercise 3.
| Value | Where | Name |
|---|---|---|
| Port | defaults/main.yml (default value 6379, configurable) |
redis_port |
| Configuration file path | vars/main.yml (the package imposes it) |
redis_config_file |
| Aurora's maximum memory | Inventory (host_vars/db1.yml or group_vars/dbservers.yml), overriding a role default |
redis_maxmemory: 256mb |
| Service name | vars/main.yml (it depends on the distribution; in Lesson 4.5 you'll see how to load it according to the system) |
redis_service_name |
Conclusion
You've created your first role. You configured roles_path = roles in ansible.cfg, generated the skeleton with ansible-galaxy role init --init-path roles common, removed the directories you didn't need and migrated common.yml in two verified steps: first a literal copy of the tasks, then the reusable version, with parameters in defaults/main.yml (common_packages, common_timezone, common_users, common_organization, common_env, common_domain, common_contact, common_facts_name, common_managed_by), an internal constant in vars/main.yml (common_facts_dir) and the inventory as the "wiring" between Aurora's data and the role. You've learned that defaults has the lowest precedence and vars one of the highest, that role variables are visible across the whole play (hence the prefix with the role's name) and, above all, that changed=0 is the proof that a refactoring hasn't changed anything. In the next lesson, Role Directory Structure, you'll study each directory of a role in depth, including files/, templates/ and meta/, and you'll create the nginx and postgresql roles from webservers.yml and dbservers.yml.
Ansible Course: From Beginner to Advanced
Module 1: Introduction to Ansible
- What Is Ansible?
- Installing Ansible
- Setting Up the Practice Lab
- Ansible Architecture
- Basic Ansible Commands
Module 2: Ansible Fundamentals
- Inventory Files
- Inventory Variables: group_vars and host_vars
- Configuring Ansible (ansible.cfg)
- Ad Hoc Commands
- Ansible Modules
- Collections and Fully Qualified Names (FQCN)
Module 3: Playbooks
- Introduction to Playbooks
- Essential YAML for Ansible
- Writing Your First Playbook
- Playbook Structure
- Variables and Facts
- Conditionals and Loops
- Registering Results and Debugging Playbooks
Module 4: Roles
- Introduction to Roles
- Creating Roles
- Role Directory Structure
- Using Roles in Playbooks
- Reusing Tasks: include and import
- Role Dependencies and Argument Validation
Module 5: Advanced Playbook Techniques
- Handlers
- Jinja2 Templates
- Filters and Lookups
- Ansible Vault
- Error Handling
- Tags and Selective Execution
- Rolling Deployments and Delegation
- Optimizing Playbooks
Module 6: Ansible Galaxy
- What Is Ansible Galaxy?
- Using Ansible Galaxy
- Managing Dependencies with requirements.yml
- Creating and Sharing Roles
- Creating Your Own Collections
Module 7: Ansible Tower, AWX and Automation Platform
- Introduction to Ansible Tower and AWX
- Installing AWX
- Using AWX: Job Templates and Jobs
- Managing Projects and Inventories
- Credentials, Permissions (RBAC) and Workflows
- Execution Environments and ansible-navigator
Module 8: Ansible for DevOps
- Ansible and Docker
- Ansible and Kubernetes
- CI/CD with Ansible
- Ansible in Cloud Environments
- Ansible and Terraform
Module 9: Ansible Best Practices
- Code Organization
- Security Best Practices
- Performance Tuning
- Code Quality: ansible-lint and yamllint
- Testing Ansible Code with Molecule
Module 10: Advanced Ansible Topics
- Custom Modules
- Dynamic Inventory
- Ansible Plugins
- The Ansible API and ansible-runner
- Event-Driven Ansible
