:orphan:
.. _testing_integration:
***** ***** ***** **
Integration tests
***** ***** ***** **
.. contents :: Topics
The Ansible integration Test system.
Tests for playbooks, by playbooks.
Some tests may require credentials. Credentials may be specified with `credentials.yml` .
Some tests may require root.
[backport][docs][2.10]Docsbackportapalooza 8 (#71379)
* Move 2.10.0rc1 release date a few days forward. (#71270)
At yesterday's meeting it was decided to have ansible-2.10.0 depend on
ansible-base-2.10.1 so that we can get several fixes for ansible-base's
routing (including adding the gluster.gluster collection).
ansible-base-2.10.1 will release on September 8th. So we will plan on
releasing ansible-2.10.0rc1 on the 10th.
https://meetbot.fedoraproject.org/ansible-community/2020-08-12/ansible_community_meeting.2020-08-12-18.00.html
(cherry picked from commit e507c127e58791755d207b46f6c829dacd7ad55c)
* a few writing style updates (#71212)
(cherry picked from commit 4f0bd5de38fb72c4aa686fa8736a3d8cc75393c0)
* Fix code markups and add link to CVE (#71082)
(cherry picked from commit 92d59a58c09f2a8baf811abe1beb09e4f911eb54)
* Fix 404 links (#71256)
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit ecea0185064b4ce8932917702a84962a75280fcf)
* Writing style updates to Developing dynamic inventory topic (#71245)
* modified the writing style
* incorporated peer feedback
(cherry picked from commit ecd3b52ad7e0dbe9042b71b2e22b33e5cef79141)
* Fix roadmap formatting. (#71275)
(cherry picked from commit ee48e0b0ad33dab245ff6a64f3ac0344de06ae56)
* Update password.py (#71295)
List md5_crypt, bcrypt, sha256_crypt, sha512_crypt as hash schemes in the password plugin.
(cherry picked from commit 1d1de2c6fd2231a88b494574eba7f4d3fd7ba5b5)
* Update ansible european IRC channel (#71326)
Signed-off-by: Rémi VERCHERE <remi@verchere.fr>
(cherry picked from commit 824cd4cbeb0a576bcd9b8a118c1f9fdcc7816ce1)
* Add warning about copyright year change (#71251)
To simplify project administration and avoid any legal issues,
add a warning in the docs. This reflects - https://github.com/ansible/ansible/issues/45989#issuecomment-423635622 and fixes: #45989
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit 606604bb97ab7ab94b42a53669f09c51f7e4d818)
* subelements: Clarify parameter docs (#71177)
skip_missing parameter in subelements lookup plugin is accepted from
inside the dictionary.
Fixes: #38182
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit 6d17736ef45cbb81bdcbafd5b52dc45f75535baf)
* Writing style updates to Using Variables topic (#71194)
* updated topic title, underline length for headings, and incorporated peer feedback
(cherry picked from commit 4d68efbe248cdf75b4a9d87c9a04bd19db81a1d1)
* cron module defaults to current user, not root (#71337)
(cherry picked from commit 4792d83e13d7622832e3885ffa2d3d0e543d42b6)
* Update Network Getting Started for FQCN/collection world (#71188)
* pull out network roles, cleanup, update first playbook examples, update gather facts section, some inventory conversion to .yml, update inventory and roles, simplify the navigation titles, fix tocs, feedback comments
(cherry picked from commit f79a7c558574a44016d2ff978aaddf00f241a08c)
* Add documentation about info/facts module development (#71250)
Fixes: #40151
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit 4f993922c87a6f12821f40c460750471bd6ee1e7)
* network: Correct documentation (#71246)
ini-style inventory does not support Ansible Vault password.
This fixes network_best_practices_2.5 doc.
Fixes: #69039
Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
(cherry picked from commit a1257d75aa2f874ea2768dd99c4affe8b37a886f)
* tidies up vars page (#71339)
(cherry picked from commit 02ea80f6d77f03ebb06ac78efc4bff183afe3c6e)
* base.yml: Fix typos (#71346)
(cherry picked from commit 41d7d53573e4f1bf366299b7f1eff15d6643c7ab)
* quick fix to change main back to devel (#71342)
* quick fix to change main back to devel
* Update docs/docsite/rst/dev_guide/developing_collections.rst
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 74f88c56a515d7edbc2c0572ad56c367a3775fd0)
* Add note about integration tests for new modules to the dev guide (#71345)
(cherry picked from commit b82889eef550cbb4074859b9fa0c38b6c04f56f1)
* update fest link (#71376)
(cherry picked from commit 80b8fde94652ba5a183a8dd3df64c1780a86c57d)
* incorporate minimalism feedback on debugging page (#71272)
Co-authored-by: bobjohnsrh <50667510+bobjohnsrh@users.noreply.github.com>
(cherry picked from commit 5073cfc8bc0dbd3c8796e460891aee971921faa2)
* fix header problem
Co-authored-by: Toshio Kuratomi <a.badger@gmail.com>
Co-authored-by: Sayee <57951841+sayee-jadhav@users.noreply.github.com>
Co-authored-by: Baptiste Mille-Mathias <baptiste.millemathias@gmail.com>
Co-authored-by: Abhijeet Kasurde <akasurde@redhat.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
Co-authored-by: rovshango <rovshan.go@gmail.com>
Co-authored-by: Remi Verchere <rverchere@users.noreply.github.com>
Co-authored-by: Jake Howard <RealOrangeOne@users.noreply.github.com>
Co-authored-by: Alicia Cozine <879121+acozine@users.noreply.github.com>
Co-authored-by: Per Lundberg <perlun@gmail.com>
Co-authored-by: Andrew Klychkov <aaklychkov@mail.ru>
4 years ago
.. note ::
Every new module and plugin should have integration tests, even if the tests cannot be run on Ansible CI infrastructure.
In this case, the tests should be marked with the `` unsupported `` alias in `aliases file <https://docs.ansible.com/ansible/latest/dev_guide/testing/sanity/integration-aliases.html> `_ .
Quick Start
===========
It is highly recommended that you install and activate the `` argcomplete `` python package.
It provides tab completion in `` bash `` for the `` ansible-test `` test runner.
Configuration
=============
ansible-test command
--------------------
The example below assumes `` bin/ `` is in your `` $PATH `` . An easy way to achieve that
is to initialize your environment with the `` env-setup `` command::
source hacking/env-setup
ansible-test --help
You can also call `` ansible-test `` with the full path::
bin/ansible-test --help
integration_config.yml
----------------------
Making your own version of `` integration_config.yml `` can allow for setting some
tunable parameters to help run the tests better in your environment. Some
tests (for example, cloud tests) will only run when access credentials are provided. For more
information about supported credentials, refer to the various `` cloud-config-*.template ``
files in the `` test/integration/ `` directory.
Prerequisites
=============
Some tests assume things like hg, svn, and git are installed, and in path. Some tests
(such as those for Amazon Web Services) need separate definitions, which will be covered
later in this document.
(Complete list pending)
Non-destructive Tests
=====================
These tests will modify files in subdirectories, but will not do things that install or remove packages or things
outside of those test subdirectories. They will also not reconfigure or bounce system services.
.. note :: Running integration tests within Docker
To protect your system from any potential changes caused by integration tests, and to ensure a sensible set of dependencies are available we recommend that you always run integration tests with the `` --docker `` option, for example `` --docker centos8 `` . See the `list of supported docker images <https://github.com/ansible/ansible/blob/devel/test/lib/ansible_test/_data/completion/docker.txt> `_ for options (the `` default `` image is used for sanity and unit tests, as well as for platform independent integration tests such as those for cloud modules).
.. note :: Avoiding pulling new Docker images
Use the `` --docker-no-pull `` option to avoid pulling the latest container image. This is required when using custom local images that are not available for download.
Run as follows for all POSIX platform tests executed by our CI system in a fedora32 docker container::
ansible-test integration shippable/ --docker fedora32
You can target a specific tests as well, such as for individual modules::
ansible-test integration ping
You can use the `` -v `` option to make the output more verbose::
ansible-test integration lineinfile -vvv
Use the following command to list all the available targets::
ansible-test integration --list-targets
.. note :: Bash users
If you use `` bash `` with `` argcomplete `` , obtain a full list by doing: `` ansible-test integration <tab><tab> ``
Destructive Tests
=================
These tests are allowed to install and remove some trivial packages. You will likely want to devote these
to a virtual environment, such as Docker. They won't reformat your filesystem::
ansible-test integration destructive/ --docker fedora32
Windows Tests
=============
These tests exercise the `` winrm `` connection plugin and Windows modules. You'll
need to define an inventory with a remote Windows 2008 or 2012 Server to use
for testing, and enable PowerShell Remoting to continue.
Running these tests may result in changes to your Windows host, so don't run
them against a production/critical Windows environment.
Enable PowerShell Remoting (run on the Windows host via Remote Desktop)::
Enable-PSRemoting -Force
Define Windows inventory::
cp inventory.winrm.template inventory.winrm
${EDITOR:-vi} inventory.winrm
Run the Windows tests executed by our CI system::
ansible-test windows-integration -v shippable/
Tests in Docker containers
==========================
If you have a Linux system with Docker installed, running integration tests using the same Docker containers used by
the Ansible continuous integration (CI) system is recommended.
.. note :: Docker on non-Linux
Using Docker Engine to run Docker on a non-Linux host (such as macOS) is not recommended.
Some tests may fail, depending on the image used for testing.
Using the `` --docker-privileged `` option when running `` integration `` (not `` network-integration `` or `` windows-integration `` ) may resolve the issue.
Running Integration Tests
-------------------------
To run all CI integration test targets for POSIX platforms in a Ubuntu 18.04 container::
ansible-test integration shippable/ --docker ubuntu1804
You can also run specific tests or select a different Linux distribution.
For example, to run tests for the `` ping `` module on a Ubuntu 18.04 container::
ansible-test integration ping --docker ubuntu1804
Container Images
----------------
Python 2
`` ` ` ` ` ``
Most container images are for testing with Python 2:
- centos6
- centos7
- fedora28
- opensuse15py2
- ubuntu1404
- ubuntu1604
Python 3
`` ` ` ` ` ``
To test with Python 3 use the following images:
- centos8
- fedora32
- opensuse15
- ubuntu1804
Legacy Cloud Tests
==================
Some of the cloud tests run as normal integration tests, and others run as legacy tests; see the
:ref: `testing_integration_legacy` page for more information.
Other configuration for Cloud Tests
===================================
In order to run some tests, you must provide access credentials in a file named
`` cloud-config-aws.yml `` or `` cloud-config-cs.ini `` in the test/integration
directory. Corresponding .template files are available for for syntax help. The newer AWS
tests now use the file test/integration/cloud-config-aws.yml
IAM policies for AWS
====================
Ansible needs fairly wide ranging powers to run the tests in an AWS account. This rights can be provided to a dedicated user. These need to be configured before running the test.
testing-policies
----------------
The GitHub repository `mattclay/aws-terminator <https://github.com/mattclay/aws-terminator/> `_
contains two sets of policies used for all existing AWS module integratoin tests.
The `hacking/aws_config/setup_iam.yml` playbook can be used to setup two groups:
- `ansible-integration-ci` will have the policies applied necessary to run any
integration tests not marked as `unsupported` and are designed to mirror those
used by Ansible's CI.
- `ansible-integration-unsupported` will have the additional policies applied
necessary to run the integraion tests marked as `unsupported` including tests
for managing IAM roles, users and groups.
Once the groups have been created, you'll need to create a user and make the user a member of these
groups. The policies are designed to minimize the rights of that user. Please note that while this policy does limit
the user to one region, this does not fully restrict the user (primarily due to the limitations of the Amazon ARN
notation). The user will still have wide privileges for viewing account definitions, and will also able to manage
some resources that are not related to testing (for example, AWS lambdas with different names). Tests should not
be run in a primary production account in any case.
Other Definitions required
--------------------------
Apart from installing the policy and giving it to the user identity running the tests, a
lambda role `ansible_integration_tests` has to be created which has lambda basic execution
privileges.
Network Tests
=============
For guidance on writing network test see :ref: `testing_resource_modules` .
Where to find out more
======================
If you'd like to know more about the plans for improving testing Ansible, join the `Testing Working Group <https://github.com/ansible/community/blob/master/meetings/README.md> `_ .