Skip to content

metabrainz/ansible-role-haproxy

Repository files navigation

Ansible Role: HAProxy

Testing

Prerequisites

  • Docker installed and running
  • Python 3.11 (or Python 3.10)
  • User must have Docker permissions

Setup

  1. Install Docker (if not already installed):
sudo apt-get install docker.io  # Debian/Ubuntu
# or
sudo yum install docker  # RHEL/CentOS
  1. Start Docker and enable it:
sudo systemctl start docker
sudo systemctl enable docker
  1. Add your user to the docker group:
sudo usermod -aG docker $USER
newgrp docker
  1. Create a virtual environment and install tox:
python3 -m venv .venv
source .venv/bin/activate
pip install tox

Running Tests

Run all test environments:

tox

Run a specific test environment:

tox -e py311-ansible7

Available test environments:

  • py310-ansible5, py310-ansible6, py310-ansible7
  • py311-ansible5, py311-ansible6, py311-ansible7

Test Environment Variables

You can customize the test environment:

# Use a different distro (default: ubuntu2004)
MOLECULE_DISTRO=ubuntu2204 tox

# Use a different playbook
MOLECULE_PLAYBOOK=custom.yml tox

Modifying the Test Matrix

To add or remove Python/Ansible versions, edit tox.ini:

Add a new version:

[tox]
envlist = py{310,311,312}-ansible{5,6,7,8}  # Add py312 and ansible8

Add dependencies for new Ansible version:

[testenv]
deps =
    ansible5: ansible == 5.*
    ansible6: ansible == 6.*
    ansible7: ansible == 7.*
    ansible8: ansible == 8.*  # Add new version

Remove a version: Simply remove it from the envlist (e.g., remove py310 or ansible5).

Updating Tests After Template Changes

When you modify the HAProxy configuration template or add new features, update the test files:

  1. Update test variables in molecule/default/inventory/group_vars/all.yml:
haproxy_config_peers:
  mypeers:
    peer:
      - haproxy1 192.168.0.1:1024
  1. Update expected output in molecule/default/files/haproxy.cfg:
peers mypeers
    peer haproxy1 192.168.0.1:1024
  1. Run tests to verify:
tox -e py311-ansible7

About

Ansible role to install, configure and manage HAProxy on Ubuntu systems

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

  •  

Contributors 3

  •  
  •  
  •