Understanding the Ansible Project Packaging

Ansible released 3.x in February 2021, which continues the project’s recent announcement that the code base will be splitting. As the project continues the transition, it’s important to understand some of the new terminology and understand how it might affect your environment.

The main difference is the philosophy on installation, i.e., installation separation of core and community packages. Ansible 3.0.0 is a community package that relies on ansible-base but comes natively with a subset of collections.

On top of the project split there is also going to be a change in the Ansible core engine naming.

  • Ansible core engine is called ansible-base which is new for version 2.10, and ansible-core with 2.11+.

Ansible 3

As mentioned previously, the installation of Ansible 3.x is considered a community package which will install ansible-base and ansible 3.x. The package list will no longer just show ansible as it has in the past.

In a fresh virtual environment Ansible is installed.

(ansible-3)
~/ansible-testing
▶ pip install ansible
Collecting ansible
  Downloading ansible-3.2.0.tar.gz (31.3 MB)
     |████████████████████████████████| 31.3 MB 25.7 MB/s
Collecting ansible-base<2.11,>=2.10.7
  Using cached ansible-base-2.10.7.tar.gz (5.7 MB)
---- output omitted ----
Successfully installed MarkupSafe-1.1.1 PyYAML-5.4.1 ansible-3.2.0 ansible-base-2.10.7 cffi-1.14.5 cryptography-3.4.7 jinja2-2.11.3 packaging-20.9 pycparser-2.20 pyparsing-2.4.7

If we check out packages with pip freeze | grep ansible, the project split is evident. We have ansible 3.2.0 with its dependency of ansible-base pinned to specific versions >=2.10.6,<2.11.

Note: 2.11 is when ansible-base is renamed to ansible-core.

▶ pip freeze | grep ansible
ansible==3.2.0
ansible-base==2.10.7

▶ pip show ansible | grep Requires
Requires: ansible-base

Since Ansible 3.x is the community package to see the native collections, execute ansible-galaxy collection list:

(ansible-3)
~/ansible-testing
▶ ansible-galaxy collection list

# /Users/ntc/ansible-testing/ansible-3/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    1.4.1
ansible.netcommon             1.5.0
ansible.posix                 1.2.0
ansible.utils                 2.0.2
ansible.windows               1.4.0
arista.eos                    1.3.0
---- omitted ----
vyos.vyos                     1.1.1
wti.remote                    1.0.1

Ansible 4

Ansible 4.0.0 was released in May 2021. It is similar to Ansible 3.x, i.e., it will be a community package that includes a subset of collections, the main difference will be Ansible 4.x dependency will be ansible-core which is >=2.11,<2.12.

(ansible-4)
~/ansible-testing
▶ pip install ansible
Collecting ansible
  Downloading ansible-4.1.0.tar.gz (34.0 MB)
     |████████████████████████████████| 34.0 MB 14.3 MB/s 
Collecting ansible-core<2.12,>=2.11.1
  Downloading ansible-core-2.11.1.tar.gz (6.1 MB)
     |████████████████████████████████| 6.1 MB 9.5 MB/s 
---- output omitted ----

Checking PIP freeze we see ansible-core was installed.

▶ pip freeze | grep ansible
ansible==4.1.0
ansible-core==2.11.1

▶ pip show ansible | grep Requires
Requires: ansible-core

After the install, running ansible-galaxy collection list shows the collections that came natively with the community package. This is similar to Ansible 3.x.

(ansible-4)
~/ansible-testing
▶ ansible-galaxy collection list

# /Users/ntc/ansible-testing/ansible-4/lib/python3.9/site-packages/ansible_collections
Collection                    Version
----------------------------- -------
amazon.aws                    1.5.0  
ansible.netcommon             2.1.0  
ansible.posix                 1.2.0  
ansible.utils                 2.2.0  
ansible.windows               1.6.0  
arista.eos                    2.1.2  
---- omitted ----
vyos.vyos                     2.3.0  
wti.remote                    1.0.1 

Collection Flexibility

For anyone that has worked in or works in a locked down environment, the Ansible project split offers additional flexibility that allows a user to install ansible-base(3.0) or ansible-core(4.0) and then only install the collections that are needed. For example, perhaps the environment only has Cisco IOS—it is possible to run the core Ansible and then install only the Cisco IOS collection.

To demonstrate that functionality, we will install ansible-base and then install the Cisco IOS collection.

Install Ansible Base:

(ansible-base-only)
~/ansible-testing
▶ pip install ansible-base==2.10.7

Collecting ansible-base==2.10.7
  Using cached ansible-base-2.10.7.tar.gz (5.7 MB)
---- omitted ----

Successfully installed MarkupSafe-1.1.1 PyYAML-5.4.1 ansible-base-2.10.7 cffi-1.14.5 cryptography-3.4.7 jinja2-2.11.3 packaging-20.9 pycparser-2.20 pyparsing-2.4.7

PIP shows only ansible-base is installed.

(ansible-base-only)
~/ansible-testing
▶ pip freeze | grep ansible
ansible-base==2.10.7

Checking the collection list shows no collections installed.

▶ ansible-galaxy collection list

Next, install the Cisco IOS collection.

▶ ansible-galaxy collection install cisco.ios
Starting galaxy collection install process
Process install dependency map
Starting collection install process
Installing 'cisco.ios:2.0.1' to '/Users/ntc/.ansible/collections/ansible_collections/cisco/ios'
Downloading https://galaxy.ansible.com/download/cisco-ios-2.0.1.tar.gz to /Users/ntc/.ansible/tmp/ansible-local-333579nqv2gur/tmp_96gsuu5
cisco.ios (2.0.1) was installed successfully
Installing 'ansible.netcommon:2.0.1' to '/Users/ntc/.ansible/collections/ansible_collections/ansible/netcommon'
Downloading https://galaxy.ansible.com/download/ansible-netcommon-2.0.1.tar.gz to /Users/ntc/.ansible/tmp/ansible-local-333579nqv2gur/tmp_96gsuu5
ansible.netcommon (2.0.1) was installed successfully
Installing 'ansible.utils:2.0.2' to '/Users/ntc/.ansible/collections/ansible_collections/ansible/utils'
Downloading https://galaxy.ansible.com/download/ansible-utils-2.0.2.tar.gz to /Users/ntc/.ansible/tmp/ansible-local-333579nqv2gur/tmp_96gsuu5
ansible.utils (2.0.2) was installed successfully

When the Cisco IOS collection is installed it will execute a dependency check and install required collections. In the case of Cisco IOS, the Ansible Netcommon and Ansible Utils collections are installed.

Listing the collections shows only the 3 collections versus the 85+ in the community package.

▶ ansible-galaxy collection list

# /Users/ntc/.ansible/collections/ansible_collections
Collection            Version
--------------------- -------
ansible.netcommon     2.0.1
ansible.utils         2.0.2
cisco.ios             2.0.1

Summary

As the Ansible project continues to evolve the code base split changes the way Ansible is managed in an environment. It becomes more flexible, but also has some additional dependencies that you need to be aware of. While troubleshooting new Ansible installs, a few helpful commands include:

ansible --version

Note: The Ansible version will show the core/base version number NOT the community package version.

ansible-galaxy collection list

These commands show which collections are installed and the path to the collections respectively.


Conclusion

Finally, the ansible-galaxy command for collections doesn’t currently support an uninstall option. To delete a collection, use rm -rf /path/to/collection. To force an update of a collection use the --force command line argument.

-Jeff



ntc img
ntc img

Contact Us to Learn More

Share details about yourself & someone from our team will reach out to you ASAP!

Author