Since the very first lesson you have written modules with a three-part name: ansible.builtin.ping, ansible.builtin.apt, ansible.builtin.copy… and in the previous lesson a module showed up that wasn't part of ansible.builtin: ansible.posix.sysctl. That full name is called an FQCN (Fully Qualified Collection Name), and its first part tells you which collection the module comes from. Collections are how all Ansible content is distributed: modules, plugins, roles and more. In this lesson you will understand what a collection is, how ansible.builtin differs from the collections included in the ansible package, why you should always write the FQCN, how to see which collections you have, how to install one on a one-off basis and where they're stored. To finish, you will manage Aurora's time zone with community.general and query PostgreSQL on db1 with community.postgresql, wrapping up Module 2.

Contents

  1. What a collection is
  2. Anatomy of an FQCN
  3. ansible-core, ansible.builtin and the ansible package
  4. Why you should always write the FQCN
  5. Viewing installed collections
  6. Installing a collection on a one-off basis
  7. Where they're stored: collections_path
  8. Documentation for collection modules
  9. Hands-on: collections in action on Aurora
  10. Wrapping up the module: back to the starting point

  1. What a collection is

A collection is a package of Ansible content in a standard format that can include:

Content Example
Modules community.postgresql.postgresql_db
Plugins (inventory, connection, filters, callbacks, lookups…) community.general.json_query (filter)
Roles Ready-to-reuse roles
Playbooks Playbooks you can invoke by their full name
Documentation and tests README, examples, tests

Up to version 2.9, every module shipped inside Ansible itself: thousands of modules in a single project, with a slow release cycle. Since Ansible 2.10, the project has been split: the engine (ansible-core) on one side, and the modules grouped into independent collections, each maintained by its community or vendor and published at its own pace on Ansible Galaxy (which you will study in Module 6).

graph TD
    A["ansible-core<br/>(engine + ansible.builtin)"]
    B["'ansible' package<br/>(ansible-core + ~90 collections)"]
    C["Ansible Galaxy<br/>(thousands of collections and roles)"]
    B --> A
    B --> D["community.general"]
    B --> E["community.postgresql"]
    B --> F["ansible.posix"]
    B --> G["amazon.aws, kubernetes.core..."]
    C -.->|ansible-galaxy collection install| H["Collections installed<br/>in collections_path"]

  1. Anatomy of an FQCN

community . postgresql . postgresql_db
    │           │              │
namespace   collection   module / plugin / role
Part What it is Examples
Namespace Organization or author that publishes it ansible, community, amazon, cisco, kubernetes
Collection Name of the collection within the namespace builtin, posix, general, postgresql, aws
Resource Module, plugin or role apt, sysctl, timezone, postgresql_db

Some examples you already know or will get to know:

FQCN What it does
ansible.builtin.apt Packages on Debian/Ubuntu (included in ansible-core)
ansible.posix.authorized_key A user's authorized SSH keys
ansible.posix.sysctl Kernel parameters
community.general.timezone System time zone
community.general.ufw Ubuntu's UFW firewall
community.postgresql.postgresql_db PostgreSQL databases
community.docker.docker_container Docker containers (Module 8)

The ansible.* namespaces are maintained by the Ansible project / Red Hat itself; the community.* ones, by the community. Being "community" doesn't mean being low quality: community.general and community.postgresql are widely used, mature collections, but they don't come with Red Hat's commercial support.

  1. ansible-core, ansible.builtin and the ansible package

In lesson 1.2 you saw that there are two packages. Now you can understand the difference in terms of collections:

ansible-core The ansible package (the one you installed)
Contains The engine and the ansible.builtin collection (about 70 modules) ansible-core plus a selection of about 90 collections
Example version 2.17, 2.18, 2.19… 10, 11, 12…
When to use it Minimal environments, or where you install only the collections you need For learning and for most projects: "batteries included"

ansible.builtin is special: it's always available, can't be uninstalled or upgraded separately, and evolves along with ansible-core.

Check how many collections your installation comes with:

ansible-galaxy collection list | grep -cE '^[a-z0-9_]+\.[a-z0-9_]+ '

  1. Why you should always write the FQCN

Ansible lets you write just apt or copy (the short name). So why do we insist on ansible.builtin.apt?

4.1 Ambiguity

Several modules can have the same short name in different collections. What's more, when you write a short name, Ansible looks it up in ansible.legacy, which includes ansible.builtin and also any modules in local directories such as your project's library/. A local module called copy.py would "shadow" the official one without you noticing. With the FQCN there's no room for doubt: ansible.builtin.copy is always the official one.

4.2 Readability and maintenance

When you read community.postgresql.postgresql_db you immediately know:

  • That it isn't part of ansible-core, but of a collection.
  • Which collection you need to have installed (vital when the project runs on another machine, on a CI server or in AWX).
  • Where to look for documentation and whom to report a bug to.

4.3 Historical redirects

Many modules that used to be "part of Ansible" now live in collections. For compatibility, Ansible keeps redirects from the old names (docker_container → community.docker.docker_container), but they're a layer of magic that may disappear and that triggers deprecation warnings.

4.4 The tools require it

ansible-lint, the code quality tool you will study in Module 9, flags short names as errors (the fqcn[action-core] rule for those in ansible.builtin and fqcn[action] for the rest). It's the convention across the whole community.

Short name FQCN Problem with the short name
copy ansible.builtin.copy A local module could shadow it
sysctl ansible.posix.sysctl Works through a redirect; doesn't say which collection is needed
timezone community.general.timezone Same
postgresql_db community.postgresql.postgresql_db Same

Aurora convention: in aurora-infra we always write the FQCN, including for ansible.builtin. There's a collections: keyword in playbooks to "shorten" names, but we won't use it: it reintroduces the very ambiguity we want to avoid.

  1. Viewing installed collections

ansible-galaxy collection list
# /home/student/.local/share/pipx/venvs/ansible/lib/python3.12/site-packages/ansible_collections
Collection                               Version
---------------------------------------- -------
amazon.aws                               10.1.1
ansible.netcommon                        8.1.0
ansible.posix                            2.1.0
...
community.general                        11.2.1
community.postgresql                     4.1.0
...

(Paths and versions will depend on your installation.) Notice:

  • The header line starting with #: the path where those collections live. With the pipx installation from lesson 1.2, the collections in the ansible package live inside the virtual environment.
  • There may be several headers: one for each path where Ansible finds collections.

To look up a specific collection:

ansible-galaxy collection list community.postgresql

If it appears in several paths, you will see several versions: Ansible will use the one in the first search path (section 7).

  1. Installing a collection on a one-off basis

Sometimes you need a collection that doesn't come with the ansible package, or a newer version than the one it ships. You install it with ansible-galaxy:

ansible-galaxy collection install community.postgresql
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Downloading https://galaxy.ansible.com/api/v3/plugin/ansible/content/published/collections/artifacts/community-postgresql-X.Y.Z.tar.gz to ...
Installing 'community.postgresql:X.Y.Z' to '/home/student/.ansible/collections/ansible_collections/community/postgresql'
community.postgresql:X.Y.Z was installed successfully

What happened:

  1. ansible-galaxy queried Ansible Galaxy and downloaded the latest version published.
  2. It installed it in ~/.ansible/collections/ansible_collections/community/postgresql, the first path in collections_path.
  3. Since that path takes precedence, from now on Ansible uses this copy rather than the one included in the ansible package.

Useful variants:

# A specific version or a range
ansible-galaxy collection install 'community.postgresql:>=3.4.0,<5.0.0'

# Upgrade to the latest available version
ansible-galaxy collection install community.postgresql --upgrade

# Install to a different path
ansible-galaxy collection install community.postgresql -p ./collections

Installing by hand isn't reproducible. If you install collections with one-off commands, your colleague (or the CI server) may have different versions and get different results. The professional approach is to declare them in a requirements.yml file versioned in the project: you will do that in the "Managing Dependencies with requirements.yml" lesson in Module 6. For now, Aurora uses the collections included in the ansible package, so this installation was just a demonstration. If you want to undo it: rm -rf ~/.ansible/collections/ansible_collections/community/postgresql.

  1. Where they're stored: collections_path

Ansible looks for collections in the paths of the collections_path option (in the [defaults] section of ansible.cfg, or the ANSIBLE_COLLECTIONS_PATH environment variable). Its default value is:

~/.ansible/collections:/usr/share/ansible/collections

In addition, it always looks in:

  • The ansible_collections directory of the Python environment where Ansible is installed (the collections in the ansible package).
  • A collections/ directory next to the playbook being run.

Check it with ansible-config:

ansible-config dump | grep COLLECTIONS_PATHS
COLLECTIONS_PATHS(default) = ['/home/student/.ansible/collections', '/usr/share/ansible/collections']
Path Who uses it Advantage Drawback
~/.ansible/collections Your user, across all your projects Easy installation Shared between projects: upgrading for one affects them all
/usr/share/ansible/collections Every user on the system Centralized Requires root
A directory inside the project (./collections) Only that project Complete isolation You have to manage it (and decide whether to version it)

We won't change collections_path in Aurora's ansible.cfg just yet: we will decide where to install the project's collections when we manage dependencies with requirements.yml in Module 6.

  1. Documentation for collection modules

ansible-doc works the same way with any installed collection:

# List a collection's modules
ansible-doc -l community.postgresql

# A module's documentation
ansible-doc community.postgresql.postgresql_info

With collection modules, pay special attention to the REQUIREMENTS section: many need Python libraries on the managed host (or on the control node, depending on the module). For example, the community.postgresql modules require psycopg2 on the server where they run:

ansible-doc community.postgresql.postgresql_info | grep -A 3 REQUIREMENTS

This is one of the most common mistakes when using collections: the module exists on the control node, but fails on the server with a message along the lines of Failed to import the required Python library (psycopg2).

  1. Hands-on: collections in action on Aurora

9.1 Time zone with community.general

In lesson 2.2 you defined aurora_timezone: Europe/Madrid for every server. Apply it:

ansible aurora -m ansible.builtin.command -a 'timedatectl show -p Timezone --value'
ansible aurora -m community.general.timezone -a 'name={{ aurora_timezone }}' -b
  • The first command shows the current time zone (Etc/UTC on the Vagrant box).
  • The second uses the timezone module from community.general with the inventory variable. First run: CHANGED; second: SUCCESS. It's an idempotent module.

9.2 Querying PostgreSQL on db1 with community.postgresql

The community.postgresql modules need a PostgreSQL server and the psycopg2 library. Install them on db1 (along with acl, which lets Ansible become the postgres user without permission problems on its temporary files):

ansible dbservers -m ansible.builtin.apt \
  -a 'name=postgresql,python3-psycopg2,acl state=present update_cache=true cache_valid_time=3600' -b

Now query the server with postgresql_info. The modules connect as the PostgreSQL user postgres, so they have to run as the postgres system user (peer authentication):

ansible dbservers -m community.postgresql.postgresql_info \
  -a 'filter=version,databases' -b --become-user postgres
db1 | SUCCESS => {
    "changed": false,
    "databases": {
        "postgres": { ... },
        "template0": { ... },
        "template1": { ... }
    },
    "version": {
        "major": 16,
        "minor": ...,
        "full": "16.x",
        ...
    }
}
  • -b --become-user postgres: Ansible connects as vagrant and becomes postgres with sudo.
  • filter=version,databases: only those sections of information.
  • The major version, 16, matches the postgresql_version variable you defined in group_vars/dbservers.yml. Your inventory described reality accurately!

Finally, simulate creating the store's database using its inventory variable:

ansible dbservers -m community.postgresql.postgresql_db \
  -a 'name={{ aurora_db_name }} state=present' -b --become-user postgres --check

Result: CHANGED (in simulation). The aurora database hasn't been created: you will do that for real, and reproducibly, with playbooks and the postgresql role.

  1. Wrapping up the module: back to the starting point

Throughout this module you have made lots of changes with ad hoc commands: htop installed, the deploy user, /etc/motd, the {{ aurora_web_root }} directory, the /etc/hosts block, the time zone, PostgreSQL on db1… None of that is in the aurora-infra repository: if a server were recreated tomorrow, it would all be lost. That's exactly the "manual configuration" problem you saw in lesson 1.1.

That's why the course convention is to restore the machines to their clean state before starting Module 3. From then on, everything Aurora Store needs will be built with versioned code:

cd ~/aurora-infra/lab
vagrant snapshot restore clean
cd ~/aurora-infra
ansible all -m ansible.builtin.ping -o

vagrant snapshot restore clean returns all three machines to the snapshot you saved in lesson 1.3 (with SSH access already set up). The repository isn't affected: the inventory, the variables and ansible.cfg are still there, because they're code.

Save the project's state if you have pending changes:

git status
git add -A
git commit -m "End of Module 2: Aurora inventory, variables and configuration"

Common Mistakes and Tips

  • couldn't resolve module/action 'community.postgresql.postgresql_db': the collection isn't installed (or is in a path Ansible doesn't search). Check with ansible-galaxy collection list community.postgresql.
  • Failed to import the required Python library (psycopg2): the dependency is missing on the managed host. Check REQUIREMENTS in ansible-doc and install the package (python3-psycopg2).
  • Permission errors when using --become-user with a non-root user (messages about "Failed to set permissions on the temporary files"): the acl package is missing on the server.
  • Two versions of the same collection: one in ~/.ansible/collections and another in the ansible package. The one in ~/.ansible/collections wins; if something started behaving differently after a manual installation, suspect this.
  • Upgrading the ansible package and having modules change: when you upgrade ansible (from 11 to 12, for example), its collections are upgraded too. Read the release notes before doing it on a project in production.
  • Writing short names "because they work": they work today; the FQCN always works and makes it clear what you need.
  • Tip: when you find an example online that uses short names, convert it to FQCN before using it; ansible-doc <short_name> shows you the real FQCN in its header.

Exercises

Exercise 1: Identifying collections

State the collection (namespace and name) of these modules and whether they're in ansible-core: ansible.builtin.user, ansible.posix.firewalld, community.general.ufw, community.mysql.mysql_user, amazon.aws.ec2_instance. Check with ansible-doc.

Exercise 2: From short name to FQCN

A colleague hands you these commands with short names. Find out each module's FQCN (use ansible-doc) and rewrite them:

ansible webservers -m ufw -a 'rule=allow port=80 proto=tcp' -b --check
ansible all -m sysctl -a 'name=vm.swappiness value=10' -b --check
ansible all -m apt -a 'name=htop' -b --check

Exercise 3: Exploring a collection

List the community.postgresql modules whose name contains user and, using ansible-doc, find out which postgresql_user parameter specifies the database the module connects to and what its default value is.

Solutions

Exercise 1.

Module Namespace Collection In ansible-core?
ansible.builtin.user ansible builtin Yes
ansible.posix.firewalld ansible posix No (ansible package)
community.general.ufw community general No
community.mysql.mysql_user community mysql No
amazon.aws.ec2_instance amazon aws No

Only those in ansible.builtin come with ansible-core; the rest come with the ansible package or by installing them from Galaxy.

Exercise 2.

ansible-doc ufw | head -1      # > MODULE community.general.ufw (...)
ansible-doc sysctl | head -1   # > MODULE ansible.posix.sysctl (...)

ansible webservers -m community.general.ufw -a 'rule=allow port=80 proto=tcp' -b --check
ansible all -m ansible.posix.sysctl -a 'name=vm.swappiness value=10' -b --check
ansible all -m ansible.builtin.apt -a 'name=htop' -b --check

All of them use --check, so they don't change anything.

Exercise 3.

ansible-doc -l community.postgresql | grep user
ansible-doc community.postgresql.postgresql_user | grep -A 6 '^- login_db'

Among others, postgresql_user and postgresql_user_obj_stat_info appear. The parameter is login_db. Its default value is an empty string (''): if you don't specify anything, the connection uses the default database of the user it connects as (with the postgres user, the postgres database). The documentation also warns that its alias db is deprecated and will be removed in version 5.0.0 of the collection: yet another reason to always read ansible-doc. Check the ansible-doc output for your version: aliases and descriptions may vary slightly between versions of the collection.

Conclusion

You have completed Module 2. In this final lesson you have discovered that all Ansible content is distributed in collections, and you have learned to read an FQCN (namespace.collection.module), the difference between ansible.builtin and the collections in the ansible package, and why aurora-infra always uses the full name. You know how to list, install and locate collections (ansible-galaxy collection list/install, collections_path), look up their documentation and requirements, and you have used them on Aurora with community.general.timezone and community.postgresql.postgresql_info. Looking back over the whole module, Aurora Store now has a YAML inventory with the aurora group, variables organized in group_vars/ and host_vars/, its own ansible.cfg and an administrator who has mastered ad hoc commands and modules. But ad hoc commands leave no trace: that's why you have returned the servers to their clean state. In Module 3: Playbooks you will start with the Introduction to Playbooks lesson, where you will discover how to turn all those one-off actions into versioned, readable, repeatable code files, the real way to automate Aurora Store's infrastructure.

Ansible Course: From Beginner to Advanced

Module 1: Introduction to Ansible

Module 2: Ansible Fundamentals

Module 3: Playbooks

Module 4: Roles

Module 5: Advanced Playbook Techniques

Module 6: Ansible Galaxy

Module 7: Ansible Tower, AWX and Automation Platform

Module 8: Ansible for DevOps

Module 9: Ansible Best Practices

Module 10: Advanced Ansible Topics

Module 11: Final Project

© Copyright 2026. All rights reserved