3. Apache Playbook test

This repository includes example Apache configuration code that configures and starts the httpd service in three variants: Debian, RedHat, and multi-OS. Looking at the repo you see the molecule directory with specific test scenarios and the default one; at this stage you are executing such content. Now let’s take a look into details.

I will use the Debian example for the first test. Let’s look at the Debian test layout, which is still minimalistic with the molecule and verify files, along with an additional Dockerfile.

molecule/
  apache1_debian/
    Dockerfile
    molecule.yml
    verify.yml
    requirements.yml

Let’s look inside molecule.yml.

# molecule.yml
---
ansible:
  cfg:
    defaults:
      deprecation_warnings: false

driver:
  name: podman

platforms:
  - name: ubuntu
    image: ubuntu:22.04
    pre_build_image: false
    dockerfile: Dockerfile
    groups: [webservers]

provisioner:
  name: ansible
  playbooks:
    converge: ../../apache1_debian.yml

Notice the Podman driver, as the test will run on a Podman instance. The platforms section describes the infrastructure layer. Debian code is straightforward; however, the apache2_redhat platforms section comes with additional complexity due to Podman ignoring systemd; additional configurations configure systemd.

The provisioner section contains a link to the converge playbook. Because the goal was to test the playbook directly, it was natural to configure it here rather than in an external file. The inventory section is also defined in the same place. Finally, the verifier section uses Ansible, which points to the verify.yml file containing the actual test assertions.

Note

Apart from core functional arguments, you spot a few of them like test_scenario with commented lines and deprecation_warnings. I added them to make Molecule progress console log free of errors, which makes the learning path easier.