So far Aurora Store has consumed community content: one role for the metrics agent and three collections, all declared in requirements.yml. Now it's time to travel the road in the opposite direction. The nginx role you wrote in Module 4 and improved in Module 5 has nothing store-specific about it: it installs nginx, publishes a static site or a load balancer with upstream, validates the configuration before reloading and manages the firewall if asked to. The team preparing the store's future blog wants to use it, and copying the directory from one repository to another is the perfect recipe for ending up with two diverging versions within a few weeks. In this lesson you'll learn to prepare a role for sharing (complete metadata, README, license, argument specification and semantic versioning with Git tags), to check that it contains no secrets or internal data, to publish it on Ansible Galaxy and to share it internally from a Git repository. You'll put it into practice by extracting the nginx role into its own repository, ansible-role-nginx, which aurora-infra will then consume through requirements.yml.
Contents
- From consumer to provider
- What makes a role shareable?
- Reviewing the candidate: Aurora's
nginxrole - Extracting the role into its own repository
- Cleaning up what isn't generic
- Complete metadata:
meta/main.yml - Documentation: README, license and changelog
- Argument specification: a review
- Checking for secrets and internal data
- Semantic versioning with Git tags
- Publishing the role on Ansible Galaxy
- Sharing the role internally with Git
- Consuming the role from
aurora-infra - The lifecycle of a new version
- From consumer to provider
Sharing a role doesn't necessarily mean publishing it on the Internet. There are three levels, and you should choose deliberately:
| Level | Where the role lives | Who uses it | When |
|---|---|---|---|
| Inside a project | The project's roles/ |
Only that project | Specific roles (like aurora_app) |
| Shared internally | Its own Git repository, consumed with requirements.yml |
Several of the company's projects | Generic roles useful to other teams |
| Published | Public repository + Galaxy | Anyone | Generic roles the company decides to release |
Aurora Store chooses the second level for its nginx role: it will extract it into its own repository on the company's Git server, and both aurora-infra and the future blog project will consume it from there. You'll also see how it would be published on Galaxy, because the role will be prepared so that this option is possible in the future.
- What makes a role shareable?
A role that works in your project isn't necessarily ready for others. This is the checklist; you already meet most of it thanks to the design criteria from Module 4:
| Requirement | Why | Status in the nginx role |
|---|---|---|
| Generic: no names, paths or data from your organization | Other projects have other data | Almost: there's one reference to aurora-infra left (section 5) |
| Everything configurable through prefixed variables, with sensible defaults | The consumer adapts it without touching the code | Yes (nginx_ prefix, Lesson 4.2) |
Doesn't read the inventory (groups, hostvars) |
Other inventories have other groups | Yes (Lesson 4.1) |
| Idempotent and self-contained | It can always be run | Yes |
Argument specification (meta/argument_specs.yml) |
Validates inputs and documents them | Yes (Lessons 4.6 and 5.2) |
Complete README.md |
It's the first thing the consumer reads | Out of date (section 7) |
Complete metadata (meta/main.yml) |
Galaxy and ansible-galaxy use it |
Incomplete for publishing (section 6) |
| License | Without a license, legally nobody can use it | proprietary (section 7) |
| Numbered versions | Consumers pin versions (Lesson 6.3) | None (section 10) |
| Its own repository | A lifecycle independent of the project | No (section 4) |
| Automated tests | They guarantee that a new version doesn't break anything | No; you'll add them with Molecule in Lesson 9.5 |
- Reviewing the candidate: Aurora's
nginx role
nginx roleRecall what roles/nginx/ contains at the end of Module 5:
roles/nginx/
├── README.md
├── defaults/main.yml nginx_port, nginx_site_name, nginx_server_name, nginx_root,
│ nginx_remove_default_site, nginx_firewall_enabled,
│ nginx_worker_connections, nginx_upstream_servers, nginx_upstream_port
├── files/gzip.conf
├── handlers/main.yml Validate the configuration / Apply the reload (listen: Reload nginx)
├── meta/main.yml
├── meta/argument_specs.yml
├── tasks/main.yml assert + import_tasks install, configure, site, service + include firewall
├── tasks/{install,configure,site,service,firewall}.yml
├── templates/nginx.conf.j2
├── templates/site.conf.j2
└── vars/main.yml nginx_package, nginx_service, /etc/nginx paths, nginx_userLook for references to Aurora in the role:
roles/nginx/files/gzip.conf:1:# Managed by Ansible (aurora-infra). Do not edit by hand.
roles/nginx/meta/main.yml:5: company: Aurora Store
roles/nginx/README.md:...:Alex Admin - Aurora Store (internal use).The authorship in meta/main.yml and in the README is legitimate. The real problem is files/gzip.conf: its header says aurora-infra as hard-coded text, so any other project using the role would publish files claiming to be managed by aurora-infra. You'll fix that in section 5.
- Extracting the role into its own repository
You could copy the directory with cp -r, but you'd lose the change history: all the commits that explain why the role is the way it is (the handlers, the templates, the validation…). Git lets you extract a subdirectory with its history using git subtree split:
This command creates a temporary branch in aurora-infra, export-nginx, containing only the commits that touched roles/nginx/, rewritten so that the contents of that directory sit at the root. Now create the new repository and pull that branch into it:
mkdir ~/ansible-role-nginx
cd ~/ansible-role-nginx
git init -b main
git pull ~/aurora-infra export-nginx
git log --oneline | head -5
lsThe ansible-role-nginx repository has the role at its root and its full history. Delete the temporary branch from aurora-infra (you don't need it any more):
About the name: the community convention for role repositories is ansible-role-<name>. Galaxy strips that prefix on import, so the role is simply called nginx. If git subtree weren't available on your system (it's part of Git's standard utilities on Ubuntu and most distributions), copy the directory with cp -r ~/aurora-infra/roles/nginx/. ~/ansible-role-nginx/ and make an initial commit: the role will work the same, just without history.
Important: for now,
aurora-infrastill has its copy inroles/nginx/. You won't delete it until section 13, when the new repository is ready and has a published version.
- Cleaning up what isn't generic
The gzip.conf header should come from each project's configuration, as the nginx.conf.j2 and site.conf.j2 templates already do with {{ ansible_managed }} (Lesson 5.2). Turn the static file into a template:
Edit templates/gzip.conf.j2 so the first line uses the variable:
# {{ ansible_managed }}
# gzip compression for text responses (HTML is already compressed by default).
gzip_vary on;
gzip_proxied any;
gzip_comp_level 5;
gzip_types text/plain text/css application/javascript application/json image/svg+xml;And in tasks/configure.yml, change the task from copy to template:
- name: Publish the gzip compression configuration
ansible.builtin.template:
src: gzip.conf.j2
dest: "{{ nginx_conf_d_dir }}/gzip.conf"
owner: root
group: root
mode: "0644"
notify: Reload nginxNotice an elegant detail: in aurora-infra, ansible_managed is set to Managed by Ansible (aurora-infra). Do not edit by hand. (Lesson 5.2), so the template generates exactly the same file that was already on the servers. The change will be invisible to Aurora (changed=0), and in other projects the header will say whatever each one configures. The files/ directory is now empty; Git doesn't store empty directories, so it simply disappears.
- Complete metadata:
meta/main.yml
meta/main.ymlIn Lesson 4.3 you saw that galaxy_info is informational at run time but essential for sharing: it's what Galaxy displays and what ansible-galaxy role info and the people evaluating the role read (Lesson 6.1). Replace meta/main.yml with:
---
galaxy_info:
role_name: nginx
namespace: aurora_store
author: Alex Admin (Aurora Store)
description: Installs nginx and publishes a static site or a load balancer, with an optional ufw firewall
company: Aurora Store
license: MIT
min_ansible_version: "2.17"
platforms:
- name: Ubuntu
versions:
- noble
galaxy_tags:
- web
- nginx
- loadbalancer
- proxy
dependencies: []Field by field:
| Field | Value | Comment |
|---|---|---|
role_name |
nginx |
The role's name on Galaxy. Without it, Galaxy derives it from the repository by removing ansible-role- |
namespace |
aurora_store |
Desired namespace. Galaxy associates roles with the GitHub account that imports them; if your account has a different name or contains hyphens, Galaxy may use another name (it usually turns - into _). Lowercase letters, numbers and _ only |
author, company |
Authorship | The organization's public details, never personal email addresses you don't want published |
description |
One sentence | The first thing shown in search results; it should say what it does |
license |
MIT |
SPDX identifier of the license (section 7). proprietary prevents use outside the company |
min_ansible_version |
"2.17" |
In quotes, as always (Lesson 6.2, section 10) |
platforms |
Ubuntu noble |
Only what you actually support and test. Declaring "all" without testing it misleads the consumer |
galaxy_tags |
Keywords | Lowercase letters and numbers only (no hyphens or spaces); they help people find the role |
dependencies |
[] |
This role doesn't depend on others. If it depended on a Galaxy role, it would be written with its full name, and ansible-galaxy would install it automatically |
A word of warning about collections: the role uses community.general.ufw, but meta/main.yml has no field for requiring collections. It's documented in the README (section 7), and it's up to the consumer to declare it in their requirements.yml (Aurora already does). This is one of the advantages of collections, which do declare dependencies (Lesson 6.5).
- Documentation: README, license and changelog
README.md
The README from Lesson 4.6 is out of date (it talks about a "temporary" reload that's now a handler and doesn't mention load balancer mode). Replace it with:
# Ansible role: nginx
Installs nginx on Ubuntu and publishes **one site**: either static (serves files
from a directory) or a **load balancer** (distributes traffic across several servers
with `upstream`). Manages `nginx.conf`, enables gzip compression for text
responses, validates the configuration with `nginx -t` before every reload and,
optionally, configures the ufw firewall.
## Requirements
- Ubuntu 24.04 (noble). Other distributions aren't supported.
- ansible-core 2.17 or later.
- The `community.general` collection (`ufw` module), declared in the `requirements.yml`
of the project that uses the role.
- The play must run with `become: true`.
## Variables
The full specification, with types and validation, is in
`meta/argument_specs.yml` (`ansible-doc -t role nginx`).
| Variable | Default | Description |
|----------|---------|-------------|
| `nginx_port` | `80` | Site port |
| `nginx_site_name` | `app` | Name of the site file in `sites-available` |
| `nginx_server_name` | `_` | `server_name` directive |
| `nginx_root` | `/var/www/html` | Root directory of the static site (the role doesn't create it) |
| `nginx_remove_default_site` | `true` | Disable Ubuntu's `default` site |
| `nginx_firewall_enabled` | `false` | Manage ufw (allows SSH and the site port, and enables it) |
| `nginx_worker_connections` | `768` | Simultaneous connections per nginx process |
| `nginx_upstream_servers` | `{}` | Dictionary `{address: weight}`. If not empty, the site is a load balancer |
| `nginx_upstream_port` | `80` | Port of the servers in `nginx_upstream_servers` |
## Dependencies
None.
## Example usage
Static site:
- name: Blog web server
hosts: blog
become: true
roles:
- role: nginx vars: nginx_site_name: blog nginx_server_name: blog.example.com nginx_root: /var/www/blog
- name: Blog load balancer
hosts: loadbalancers
become: true
roles:
- role: nginx vars: nginx_site_name: blog nginx_upstream_servers: 192.0.2.11: 2 192.0.2.12: 1 nginx_firewall_enabled: true
## Handlers The configuration tasks notify `Reload nginx`, which validates with `nginx -t` and, if the configuration is valid, reloads the service. ## Installation From Git, in the project's `requirements.yml`:
roles:
- name: nginx src: git+ssh://[email protected]/ops/ansible-role-nginx.git version: "1.0.0"
Notice that the examples use blog.example.com and 192.0.2.x addresses (a range reserved for documentation), not Aurora's real data: a README is visible to everyone who can read the repository.
Language: write the README (and the task names) in the language your consumers read. For an internal role, the team's working language is reasonable; if the role is ever published on Galaxy for the international community, English is the norm.
LICENSE
Without a license file, nobody outside the company could legally use the role, even if it were public. Aurora chooses MIT, a short and permissive open source license, the most common one for Galaxy roles. Create LICENSE:
MIT License
Copyright (c) 2026 Aurora Store
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.A license text isn't translated or modified: it's copied verbatim, changing only the year and the copyright holder. Choosing a license is a company decision; in a real organization, check it with whoever handles legal matters.
CHANGELOG.md
The changelog is what consumers will read before upgrading (Lesson 6.3, section 12). Create CHANGELOG.md:
# Changelog
Format: one section per version, from newest to oldest.
Semantic versioning: MAJOR.MINOR.PATCH.
## 1.0.0 - 2026-11-26
First release as a standalone role (extracted from the aurora-infra project).
- Static site or load balancer (`nginx_upstream_servers`).
- `nginx.conf` managed with a template and validated with `nginx -t`.
- gzip compression for text responses (now with a template and `ansible_managed`).
- Optional ufw firewall (`nginx_firewall_enabled`).
- Argument validation with `meta/argument_specs.yml`..gitignore
Finally, a minimal .gitignore for the role's repository:
- Argument specification: a review
The role already has meta/argument_specs.yml (Lessons 4.6 and 5.2), with the nine variables, their types and descriptions. For a shared role it's even more valuable than for an internal one:
- It validates what the consumer passes in: an
nginx_port: eightyfails right at the start with a clear message, not halfway through the configuration. - It documents in a structured way:
ansible-doc -t role nginxshows it in any project that has the role installed, without opening any files. - It's the source of truth from which the README table is derived; when you add a variable, update both (and
defaults/main.yml).
Compare it with the community role you evaluated in Lesson 6.1: geerlingguy.node_exporter has no argument_specs, and ansible-doc -t role shows nothing. Your role will be easier to evaluate and to use.
- Checking for secrets and internal data
Before the role leaves aurora-infra, even if only for an internal server, review it on the assumption that anyone who can read the repository will read all of it, history included:
cd ~/ansible-role-nginx
grep -rniE 'password|passwd|secret|token|api_key|vault|BEGIN .*PRIVATE KEY' .
grep -rnE '192\.168\.|10\.[0-9]+\.[0-9]+\.[0-9]+|aurora-store\.example' .
git log -p | grep -niE 'password|secret|token|192\.168\.' | headWhat you're looking for with each command:
- Secrets: passwords, tokens, private keys or Vault files. A generic role should never contain them: secrets are passed in by the consumer, from their Vault (Lesson 5.4).
- Internal data: the company's real IP addresses, domains and server names. Examples should use documentation domains and ranges (
example.com,192.0.2.0/24). - The history:
git subtree splitbrought over all the role's commits. If any of them ever contained a secret, even if it was deleted later, it's still in the history. That isn't the case with thenginxrole (it never contained secrets); if it were, you'd have to change the secret (treat it as compromised) and rewrite the history before sharing anything.
The only expected match is aurora-store.example in the README's "Installation" section, which is the address of the internal Git server and is intentional. There are specialized tools that automate this search with hundreds of patterns (such as gitleaks or trufflehog), highly recommended before publishing any repository.
Warning: never publish roles to a public repository (or to Galaxy) that contain secrets, customer data, internal infrastructure addresses or names, or security configurations specific to your company. If you're unsure about what can be made public, check with the person responsible for security before publishing: once something is on the Internet, it can never be fully withdrawn.
- Semantic versioning with Git tags
Consumers pin versions (Lesson 6.3), so the role needs versions. For a role, a version is a Git tag, and the convention is semantic versioning:
| Change to the role | Type | Example for nginx |
|---|---|---|
| A variable is removed or renamed, a default value changes in a way that alters the servers, a platform is no longer supported | MAJOR (2.0.0) | Renaming nginx_root to nginx_document_root |
| An optional variable or a compatible feature is added | MINOR (1.1.0) | New nginx_gzip_comp_level variable with a default of 5 |
| A bug is fixed without changing the interface | PATCH (1.0.1) | Fixing a bug in the site template |
Commit the changes from sections 5 to 7 and create the tag for the first version:
A .gitignore
A CHANGELOG.md
A LICENSE
M README.md
M meta/main.yml
M tasks/configure.yml
R files/gzip.conf -> templates/gzip.conf.j2git commit -m "Prepare the role for sharing: metadata, README, MIT license, CHANGELOG and gzip with a template"
git tag -a 1.0.0 -m "Version 1.0.0"
git tagDetails of the convention:
- Annotated tags (
-a): they store the author, date and message. They're the recommended kind for versions. - No
vprefix:1.0.0, notv1.0.0. Galaxy interprets tags as versions, and the form without a prefix is the most compatible (it's the one used by, for example,geerlingguy.node_exporter). - A published tag is never moved. If 1.0.0 has a bug, you publish 1.0.1. Moving a tag breaks reproducibility for anyone already using it (Lesson 6.1, section 8).
- Why 1.0.0 and not 0.1.0: 0.x versions mean "under development, anything may change". The role has been in production at Aurora for months; it's stable.
- Publishing the role on Ansible Galaxy
Aurora isn't going to publish the role on Galaxy for now, but it's worth knowing the process, because it's simple and you'll use it if you ever release a role of your own. Standalone roles aren't uploaded to Galaxy: Galaxy imports them from GitHub.
sequenceDiagram
participant A as Author
participant GH as GitHub
participant GX as Galaxy
A->>GH: git push (branch and tag 1.0.0)
A->>GX: ansible-galaxy role import aurora-store ansible-role-nginx
GX->>GH: reads the repository, meta/main.yml and the tags
GX-->>A: role published (version 1.0.0)
The steps:
-
A public repository on GitHub, for example
github.com/aurora-store/ansible-role-nginx, with the role at its root and the tags pushed (git push origin main --tags). -
Log in to Galaxy with that GitHub account (galaxy.ansible.com only supports GitHub login). The first time, the associated namespace is created.
-
Get an API token from Galaxy's user menu (the API token section). Treat it like a password: never in the repository.
-
Import from the terminal:
ansible-galaxy role import --token "$GALAXY_TOKEN" aurora-store ansible-role-nginxThe arguments are the GitHub user or organization and the repository name.
ansible-galaxyasks Galaxy to import the role and shows the result of the import (warnings about incomplete metadata appear here). Useful options:--branch(import another branch),--role-name(force the name) and--no-wait(don't wait for the result). You can also import it from the web interface. -
New versions: create and push a new tag and import again. Many authors automate this with a CI job that runs
ansible-galaxy role importevery time a tag is pushed.
The result would be a role anyone could install with ansible-galaxy role install aurora_store.nginx,1.0.0 (with whatever namespace Galaxy has assigned to the account). If you want to practice the whole process, do it with a test role in your own GitHub account, never with your company's data, and remove it afterwards with ansible-galaxy role delete <user> <repository>.
- Sharing the role internally with Git
Aurora's option is simpler: a repository on the company's Git server. In a real company it would be something like [email protected]:ops/ansible-role-nginx.git (GitLab, Gitea, GitHub Enterprise…). In the lab you'll simulate it with a "bare" Git repository (one without a working directory, which is what servers store) on your own computer:
~/aurora-git/ plays the role of the company's Git server. Push the branch and the tags to it:
cd ~/ansible-role-nginx
git remote add origin ~/aurora-git/ansible-role-nginx.git
git push -u origin main --tags...
To /home/student/aurora-git/ansible-role-nginx.git
* [new branch] main -> main
* [new tag] 1.0.0 -> 1.0.0
branch 'main' set up to track 'origin/main'.--tags is essential: by default, git push doesn't push tags, and without them consumers wouldn't find version 1.0.0.
- Consuming the role from
aurora-infra
aurora-infraNow aurora-infra gets rid of its copy and starts consuming the role like any other dependency. Add the entry at the beginning of the roles list in requirements.yml:
roles:
# Aurora Store's own role, shared from its repository (Lesson 6.4).
# In the lab, the "Git server" is ~/aurora-git (replace "student" with your user).
# In the company: git+ssh://[email protected]/ops/ansible-role-nginx.git
- name: nginx
src: git+file:///home/student/aurora-git/ansible-role-nginx.git
version: "1.0.0"
# Prometheus metrics agent. Evaluated in Lesson 6.1; used in monitoring.yml.
- name: geerlingguy.node_exporter
version: "2.2.0"Details:
name: nginx: the role will be installed asnginx, the same name used byloadbalancers.yml,webservers.ymland theaurora_appdependency (meta/main.yml:role: nginx). No playbook changes.git+file://: Git accepts local paths as URLs. The path must be absolute (URLs don't expand~), which is why/home/studentappears.version: "1.0.0": the tag you've just published.
Delete the local copy of the role and install the dependency:
Starting galaxy role install process
- extracting nginx to /home/student/aurora-infra/galaxy_roles/nginx
- nginx (1.0.0) was installed successfully
- geerlingguy.node_exporter (2.2.0) is already installed, skipping.
Starting galaxy collection install process
Nothing to do. All requested collections are already installed. If you want to reinstall them, consider using `--force`.Check that Ansible finds the role in its new location:
# /home/student/aurora-infra/galaxy_roles
- geerlingguy.node_exporter, 2.2.0
- nginx, 1.0.0
# /home/student/aurora-infra/roles
- aurora_app, (unknown version)
- common, (unknown version)
- postgresql, (unknown version)
> ROLE: *nginx* (/home/student/aurora-infra/galaxy_roles/nginx)
...And the ultimate test: the infrastructure shouldn't notice the change.
Both runs should finish with changed=0 on every server. If gzip.conf showed up as changed, compare the header: it means ansible_managed doesn't match the text the static file had.
Commit the change in aurora-infra:
git add requirements.yml
git commit -m "nginx role extracted to ansible-role-nginx 1.0.0 and consumed through requirements.yml"State of the repositories:
~/aurora-infra/
├── requirements.yml ← + nginx from git (1.0.0)
├── roles/ (common, postgresql, aurora_app)
└── galaxy_roles/ (not versioned: nginx 1.0.0, geerlingguy.node_exporter 2.2.0)
~/ansible-role-nginx/ ← the role's working repository (main branch, tag 1.0.0)
├── .gitignore CHANGELOG.md LICENSE README.md
├── defaults/ handlers/ meta/ tasks/ vars/
└── templates/{nginx.conf.j2, site.conf.j2, gzip.conf.j2}
~/aurora-git/ansible-role-nginx.git ← the company's "Git server" (bare repository)
- The lifecycle of a new version
The role now has a life of its own. Every change follows this cycle:
flowchart LR
A["Change the role in<br/>~/ansible-role-nginx"] --> B["Test it in the lab<br/>(development loop)"]
B --> C["CHANGELOG + commit<br/>+ tag 1.1.0"]
C --> D["git push --tags"]
D --> E["aurora-infra: version 1.1.0<br/>install -r --force"]
E --> F["site.yml in the lab<br/>+ commit"]
The trickiest step is testing before tagging. To avoid having to publish a version every time you try something out, use the ANSIBLE_ROLES_PATH environment variable, which overrides roles_path for a single run, pointing it at your working copy:
mkdir -p ~/roles-dev
ln -s ~/ansible-role-nginx ~/roles-dev/nginx
cd ~/aurora-infra
ANSIBLE_ROLES_PATH=~/roles-dev:galaxy_roles:roles ansible-playbook site.yml --check --diff --limit web1The symbolic link makes the ~/ansible-role-nginx directory look like a role called nginx, and since ~/roles-dev comes first in the list, Ansible uses your working copy instead of the installed version 1.0.0. When the change works, publish it (CHANGELOG, commit, tag, push --tags) and update requirements.yml in aurora-infra, remembering the --force that roles require when changing versions (Lesson 6.3).
Common Mistakes and Tips
- Forgetting
--tagswhen pushing: the remote repository doesn't have the tag and the installation fails with a Git error along the lines ofpathspec '1.0.0' did not match. Push the tags. - Installing the role from Git without
name: it would end up asansible-role-nginxand the playbooks would fail withthe role 'nginx' was not found. - Deleting
roles/nginxbefore the version is published: you're left without the role inaurora-infra. Publish first; then remove the copy. - Editing the role in
galaxy_roles/nginx: it's an installed copy; the next reinstallation will wipe out your changes. You edit it in~/ansible-role-nginxand publish a version. - Moving an already published tag (
git tag -f): whoever has it installed will have different code from whoever installs it tomorrow. Publish a new version. - Optimistic metadata: declaring platforms you don't test or a
min_ansible_versionlower than the real one. Anyone evaluating your role with the criteria from Lesson 6.1 will trust that data. - Tip: write the CHANGELOG in the same commit as the change, not at release time. By the end of the month nobody remembers what changed or whether it was compatible.
Exercises
Exercise 1: Which version is next?
Starting from 1.0.0, state which version you'd publish after each of these changes (applied one after another): (a) a typo is fixed in a comment in nginx.conf.j2, which changes the file generated on the servers; (b) the optional variable nginx_client_max_body_size is added with a default value that reproduces the current behavior; (c) nginx_firewall_enabled now defaults to true.
Exercise 2: Prepare version 1.1.0 without publishing it
On a gzip-level branch of the ~/ansible-role-nginx repository, add the nginx_gzip_comp_level variable (integer, default 5) to defaults/main.yml, meta/argument_specs.yml, the gzip.conf.j2 template and the README, plus an entry in the CHANGELOG. Test it from aurora-infra with the development loop from section 14 in --check mode. Don't create the tag or change requirements.yml: the rest of the course keeps using version 1.0.0. When you're done, switch back to the main branch.
Exercise 3: Review before sharing
A colleague wants to share her backup role. Her defaults/main.yml contains the following. Point out all the problems and propose a corrected version:
---
backup_server: 192.168.56.30
backup_user: aurora_backup
backup_password: Aur0ra-2026!
backup_paths:
- /var/www/aurora
- /etc/auroraSolutions
Exercise 1. (a) 1.0.1: it's a fix with no interface change (the fact that it changes the file on the servers, and therefore triggers a reload, doesn't make it incompatible). (b) 1.1.0: a new, compatible optional variable. (c) 2.0.0: changing a default value in a way that alters the servers of anyone who didn't set the variable (ufw would be enabled where it wasn't before) is a breaking change, even though the interface is the same. It deserves a prominent note in the CHANGELOG.
Exercise 2.
defaults/main.yml: add nginx_gzip_comp_level: 5. meta/argument_specs.yml, inside options:
nginx_gzip_comp_level:
type: int
default: 5
description: gzip compression level (1 = fastest, 9 = most compression).templates/gzip.conf.j2: gzip_comp_level {{ nginx_gzip_comp_level }};. README: a new row in the variables table. CHANGELOG: a ## 1.1.0 - (unreleased) section with "New nginx_gzip_comp_level variable". Optionally, add the range check (1 to 9) to the assert in tasks/main.yml (Lesson 5.5). Test it:
git commit -am "nginx_gzip_comp_level variable"
mkdir -p ~/roles-dev && ln -sfn ~/ansible-role-nginx ~/roles-dev/nginx
cd ~/aurora-infra
ANSIBLE_ROLES_PATH=~/roles-dev:galaxy_roles:roles ansible-playbook site.yml --check --diff --limit web1
ANSIBLE_ROLES_PATH=~/roles-dev:galaxy_roles:roles ansible-playbook site.yml --check --diff --limit web1 -e nginx_gzip_comp_level=6With the default value, changed=0 (the generated file is identical: compatible, which is why it's a MINOR version). With -e nginx_gzip_comp_level=6, the diff shows the changed line in gzip.conf. Switch back with git -C ~/ansible-role-nginx switch main. The branch stays in your working repository, unpublished.
Exercise 3. Problems: (1) a plaintext password in the role: a secret never goes in a shared role; moreover, since it's in the Git history, it has to be changed even if it's deleted; (2) an internal IP as a default value; (3) Aurora's names and paths (aurora_backup, /var/www/aurora, /etc/aurora) in a role that's meant to be generic. Corrected version:
---
# Backup server: required (argument_specs with required: true).
# backup_server:
backup_user: backup
# Password: required, must come from the consuming project's Vault.
# backup_password:
backup_paths: []With backup_server and backup_password marked as required: true in meta/argument_specs.yml (Lesson 4.6), and in Aurora's project the real values in the inventory, with the password in vault.yml (Lesson 5.4).
Conclusion
You've turned an internal role into a shareable one: you went through the list of requirements (generic, configurable, documented, validated, licensed and versioned), extracted the nginx role into its own ansible-role-nginx repository while keeping its history with git subtree split, removed its last reference to aurora-infra (the gzip header, now a template with ansible_managed), completed meta/main.yml (role_name: nginx, namespace: aurora_store, MIT license, Ubuntu noble), the README, the license and the CHANGELOG, checked that it contains no secrets or internal data and published its version 1.0.0 as a Git tag. You know the process for publishing on Galaxy (ansible-galaxy role import with a token) and you've applied the internal alternative: a Git server (simulated in ~/aurora-git/) from which aurora-infra installs the role with requirements.yml, without the infrastructure noticing the change. But standalone roles have their limits: they don't declare the collections they need, each one has its own repository and version, and they can't cleanly include their own modules or plugins. In the next lesson, Creating Your Own Collections, you'll package Aurora's platform roles into a collection, aurora_store.infra, with its own versioning, declared dependencies and room for the Python code you'll write later on.
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
