0 / 13 lessons — 0%
Lesson 11 / 13

Ansible Galaxy — sharing & reusing roles

Someone has already written and battle-tested a role for "install and configure PostgreSQL" or "harden this Ubuntu box." Ansible Galaxy is the public hub for exactly that — install a community role instead of writing your own from scratch.

# search, then install a role from Galaxy ansible-galaxy search postgres ansible-galaxy install geerlingguy.postgresql # now usable in any playbook, same as your own roles - hosts: dbservers roles: - geerlingguy.postgresql

For real projects, pin exact versions in a requirements.yml file instead of installing roles ad hoc — so a fresh checkout of the repo gets the exact same roles everyone else is running.

# requirements.yml roles: - name: geerlingguy.postgresql version: "3.4.0" collections: - name: community.docker version: ">=3.0.0"
ansible-galaxy install -r requirements.yml ansible-galaxy collection install -r requirements.yml

Beyond roles, Galaxy also distributes collections — bundles of modules and plugins for a specific platform, like community.docker or amazon.aws, which is how Ansible gains new modules without Ansible itself needing a new release.

Try it yourselfRun ansible-galaxy search nginx and skim the results. Before writing a role for anything common, a quick search is usually faster than starting from a blank tasks/main.yml.