The following is an example of a test for Testinfra that checks the availability of Git in a specific version and the Let's Encrypt configuration file:
# We want Git installed on our host
def test_git_is_installed(host):
git = host.package("git")
# we test if the package is installed
assert git.is_installed
# and if it matches version 1:2.1.4 (using Debian versioning)
assert git.version.startswith("1:2.1.4")
# We want the file /etc/letsencrypt/config/example.com.conf to:
def test_letsencrypt_file(host):
le = host.file("/etc/letsencrypt/config/example.com.conf")
assert le.user == "letsencrypt" # be owned by the letsencrypt user
assert le.mode == 0o600 # access mode 0600
assert le.contains("example.com") # contain the text example.com in the contents
Testinfra uses plain Python syntax. It should be readable, but just like Serverspec, you may need some training to confidently write tests...