abrisco / rules_ansible

Bazel rules for Ansible
5 stars 1 forks source link

Add `ansible_playbook_test` rule #7

Open abrisco opened 1 year ago

abrisco commented 1 year ago

This rule should be able to consume an ansible_playbook target and a docker image where the playbook can be run.

load("@rules_ansible//ansible:defs.bzl", "ansible_playbook", "ansible_playbook_test")

ansible_playbook(
    name = "lamp_simple",
    inventory = ["hosts"] + glob([
        "group_vars/**",
    ]),
    playbook = "site.yml",
    roles = glob(["roles/**"]),
)

ansible_playbook_test(
    name = "lamb_simple_test",
    playbook = ":lamp_simple",
    # This will likely come from https://github.com/bazelbuild/rules_docker
    image = "@ubuntu20//image",
    # This is equivilant to passing `--check` to `ansible-playbook`.
    # Notably, arguments should be exposed as attributes for this rule
    # vs the rule getting a generic `args` attribute.
    check = True,
)
abrisco commented 1 year ago

Without this rule ansible_playbook is largely untested. It would be great to have a test rule like this that would run the ansible_playbook targets directly against some test container. This way regressions could be caught in pull-requests.