Version locking Ansible Collections

November 1, 2022 – Samuli Seppänen
When you version lock your project's Ansible Collections you make all the parts with together perfect, not just so-and-so
When you version lock your project's Ansible Collections you all the parts fit together perfectly, not just so-and-so (https://www.pexels.com/photo/abstract-art-circle-clockwork-414579/)

What are Ansible Collections?

Ansible is an infrastructure as code tool used for configuration management, network device management, orchestration and other tasks. Ansible Collections are a way to distribute Ansible content such as roles, playbooks and modules. They can be downloaded from Ansible Galaxy, Git repositories or local directories. Basically collections are a more modern packaging format compared to standalone roles which they are in the process of replacing. Version-locking Ansible Collections allows you to run the exact same Ansible code every time.

Version locking Ansible Collections

When you use collections it makes a lot of sense to version-lock them, even though that is not really emphasized in the official documentation. If you don't version-lock dependencies such as collections or roles, you have no guarantees that your code will behave the same each and every time. When your Ansible is bootstrapped by someone he or she could get completely different dependency versions than somebody else. This, in turn, will eventually cause problems when your own playbooks or roles are incompatible with the collections they depend on.

Version locking Ansible collections on the project level ensures that everybody uses the exact same Ansible code, including your local code and its dependencies . Version locking also allows controlling the changes going into project dependencies.

Configuring project-specific collections in Ansible

The first step is to create an Ansible configuration file, ansible.cfg, to the root of your project:

[defaults]
collections_paths = ./collections

This tells Ansible to look for collections in the current directory under collections subdirectory. The next step is to create a collections/requirements.yml file which tells which dependencies your project needs. While requirements.yml can be placed anywhere, the above location is the only one that is compatible with Ansible Tower. Here's a minimal example for version locking Ansible Collections:

---
collections:
- name: https://github.com/Puppet-Finland/ansible-collections-puppeteers-keycloak.git
  type: git
  version: 1.0.1

For details on the requirements.yml syntax please refer to the official documentation.

Note that if any of the collections you list has collection dependencies of their own, those will also be installed automatically. This means there's a fair chance of a "dependency hell" as your requirements.yml file grows and the requirements of different collections become impossible to satisfy at the same time.

To install the collections run this command:

ansible-galaxy collection install -r collections/requirements.yml

You should also add ansible_collections to .gitignore, like this:

ansible_collections

That way you don't accidentally version your external dependencies.

More about Ansible quality assurance from Puppeteers

Want to talk to an expert?

If you want to reach us, just send us a message or book a free call!
Categories

Tags

#aad #Access #acl #alertmanager #ansible #ansible module development #Apache #API #augeas #authentication #authorization #automation #automatization #aws #azure #backup #bash #bitbucket #buildbot #cache #centos #cloud #cloud-init #cloudflare #cloudfront #cluster #connectionsJpa #control repo #custom fact #database #debian #devops #digital sovereignty #DNS #docker #domain mode #duplo #ejabberd #email #encryption #erb #europe #eyaml #fabric #facter #facts #fargate #fedora #file #finnish #foreman #freeipa #git #github #gitlab #gnome #google #grafana #hammer #hiera #IAM #import #infinispan #Infrastructure as Code #ipmi #irc #jboss #jdk #jenkins #JMESPath #kanban #keycloak #librarian-puppet #librenms #linkedin #Linux #Location #loop #marketing #mautic #Mellon #mfa #monitoring #mysql #nagios #network-manager #oauth #oauth2 #office365 #open source #openvpn #oxygen #packer #paranormal #pdk #people #php #pkcs7 #pomodoro #Powershell #preseed #presentation #profiles #prometheus #provisioning #puppet #puppet-bolt #puppet-litmus #puppetboard #puppetdb #Puppetfile #puppetserver #puppet types and providers #pxeboot #qemu #quality #r10k #recruitment #redirect #Restrict #Reverse Proxy #roles #rspec #ruby #SAML #sem #shell #showsql #snmp #snmpd #software developement #spam #ssh #sso #standardization #systemd #systemd-resolved #teams #terraform #ubuntu #user-data #vagrant #vanity awards #variable #vim #virtualbox #visualstudio #webdevelopment #wildfly #Windows #wireguard #wordpress #workflow #x11 #xmpp #zimbra
We are
 Puppeteers
menucross-circle