Last active
July 8, 2020 17:18
-
-
Save loncarales/7772d93a0fa2cb17a8861c4b0e25ca36 to your computer and use it in GitHub Desktop.
Let's look at a simple example. Let's say we would like to test if some set of packages were installed within the role.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| --- | |
| - name: Verify | |
| hosts: all | |
| tasks: | |
| - name: Gather the package manager facts | |
| package_facts: | |
| manager: auto | |
| - name: Assert that following packages are installed | |
| assert: | |
| that: | |
| - "'docker-ce' in ansible_facts.packages" | |
| - "'kubelet' in ansible_facts.packages" | |
| - "'kubectl' in ansible_facts.packages" | |
| - "'kubeadm' in ansible_facts.packages" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import pytest | |
| import testinfra.utils.ansible_runner | |
| testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | |
| os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all') | |
| @pytest.mark.parametrize('pkg', [ | |
| 'docker-ce', | |
| 'kubelet', | |
| 'kubectl', | |
| 'kubeadm' | |
| ]) | |
| def test_pkg(host, pkg): | |
| package = host.package(pkg) | |
| assert package.is_installed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment