Introduction to Ansible-Test | Infogen Labs
Ciklum India
We develop Digital Solutions for Fortune 500 and fast-growing organisations alike around the world.
As automation becomes increasingly important in more business cases, testing the automation code becomes more important. This is where ansible-test comes in: developers may use ansible-test to create testing processes that integrate with source code repositories to test their Ansible Content Collections for sanity, unit, and integration tests.
Collection developers can utilize ansible-test, a cli tool included with both ansible-core and ansible-base, to test their Collection and its content. From linting module documentation and code to performing unit and integration tests, the ansible test can handle a wide range of testing activities.
How to run ansible-test?
With Ansible-2.9's wide release of Ansible Content Collections, a user can now use ansible-test to test the collection itself. In order for ansible-test to execute tests on the Collection, it must be run from the collection root or below.
If you try to execute ansible-test outside of the aforementioned directory norms, you'll get the following error:
root@root ~/.ansible/collections ansible-test sanity
ERROR: The current working directory must be at or below:
- an Ansible collection: {...}/ansible_collections/{namespace}/{collection}/?????????????????????????????????????????????????????????????????Current working directory: /root/.ansible/collections
You can see how a collection root appears to ansible-test in the output above; it must be in the form of:
{...}/ansible_collections/{namespace}/{collection}/
When you install a collection from Ansible Galaxy or Automation Hub, the default installation location is: {...}/ansible_collections/{namespace}/{collection}/ , which already satisfies the above directory convention.
Even if you specify the installation path to the ansible-galaxy cli (using the -p option), it will also install a collection inside the ansible_collections directory by creating one in the given path, like below:
领英推荐
root@root ~/temp ll
total 0
?
root@root ~/temp ansible-galaxy collection install arista.eos -p .
Process install dependency map
Starting collection install process
Installing 'arista.eos:1.2.0' to '/root/temp/ansible_collections/arista/eos'
Installing 'ansible.netcommon:1.4.1' to '/root/temp/ansible_collections/ansible/netcommon'
?
root@root ~/temp ll
total 4.0K
drwxrwxr-x. 4 root root 4.0K Jan 18 19:21 ansible_collections
How to test your collection using ansible-test?
ansible-test allows you to conduct several types of tests on your Collections. These tests are classified as follows:
Sanity Tests
Unit Tests
Integration Tests
We'll go over each of these tests thoroughly.
?Visit Us:?corp.infogen-labs.com?
Business Enquiry:??[email protected]?/?[email protected]
?