Skip to content

Instantly share code, notes, and snippets.

@loncarales
Last active July 8, 2020 17:18
Show Gist options
  • Save loncarales/7772d93a0fa2cb17a8861c4b0e25ca36 to your computer and use it in GitHub Desktop.
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.
---
- 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"
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