Collections#
Collections are the way that re-usable content is shared/delivered (plugins, roles, etc). The Free source for getting and sharing collections is Galaxy and the Paid for version is Automation Hub. The notes here are specifically focused on collections as used within AWX/Tower and will not cover local environments. Note, somewhere in ansible 2.9 the transition was made to support collections, and fully integrated in 2.10, so make sure your local ansible is 2.10+ to test locally
- Intro video From redhat on the introduction and why.
- Basic User Guide How to use collections
- Developer Guide How to create collections
- Execution Environments (EE) AWX/Tower is run in kubernetes and EE are the pods that get spun up to run the playbooks. %99 of the time the default EE is fine. In rare special cases an alternative EE can be created, however this must be managed (tech debt) so should be avoided. For this reason, many of the notes on using collections are not applicable as you do not have direct access.
Using Collections#
Using collections is very straight forward.
Declare collections to be used#
- Create a
requirements.yml
file in acollections
folder at the root of the repo with your ansible playbooks. File details ./collections/requirements.yml
- Add the list of collections
Text OnlyExample:
collections: - name: namespace_name.collection_name
Text Onlycollections: - name: community.general - name: umn_devex.devex_awxuser version: 1.0.2
- ‼ Due to consistant connection issues between Tower and Galaxy, Devex has provided many commonly used collection in the
Devex-ee
Execution environmont(EE). By using this EE you do NOT need to specify them in the./collections/requirements.yml
. However it may be worth adding them, but commenting them out so its documented. - Here is a list of collections that are provided (note: you need to be onboarded into GHEC to see this UMN internal repo)
- It uses the latest version of each collection and is updated weekly.
Call roles in playbook#
When including a rule, make sure to use the FNC (fully namespaced collection) namespace_name.collection_name.role
In the example playbook, 'add_awx_user' is a role inside the 'umn_devex.devex_awxuser' collection:
---
- name: Deploy awx_user and Public Key to servers
hosts: all
...
tasks:
- name: add awx user
include_role:
name: umn_devex.devex_awxuser.add_awx_user
Creating Collections#
While not strictly necessary for collections in general, it is for our use case.
Prerequisites:
- You have a Galaxy account. They are free and leverage your Github.com account.
There are two ways to get started. First is to use this template repo to get started, see the READ.md for details. The second options is to create it manually. The template repo contains a useful GitHub Action file you may want to grab even if you create the collection manually.
Manual: Make sure you have the latest version of ansible installed (2.10+ ideal)
- initialize your collection
bash> ansible-galaxy collection init namespace_name.collection_name
- example:
bash> ansible-galaxy collection init tjsobeck.example
- Create meta/runtime.yml and add
requires_ansible: ">=2.10,<2.15"
# adjust ansible versions as needed - Update the galaxy.yml file
- set
namespace:
to the namespace of your galaxy account - set
name:
to the name of this collection - Fill out the rest of the values as need, but the two above are critical.
- set
- Build the collection
bash> ansible-galaxy collection build <path_to_collection>
- This will create a tar.gz file
- Publish the collection to ansible galaxy
- Make sure you have your galaxy api key
bash> ansible-galaxy collection publish --api-key <api_key> <path_to_tar.gz>