This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Ansible

Bazel rules for ansible

al_ansible_package from //tools/ansible/rules:al_ansible_package.bzl declares mapped sources, their runtime package, an <name>_bin executable and AL command wrappers. For example:

al_ansible_package(
    name = "ansible",
    srcs = ["inventory.yaml"] + glob(["group_vars/**/*.yaml", "playbook_*.yaml"]),
    configs = ["//infra/example:al"],
    plugin_labels = {"ansible": "", "vault_env": "default_default"},
)

The default command uses --inventory inventory.yaml playbook_deploy.yaml. Pass an args dictionary to declare custom command suffixes and arguments; the macro supplies the executable. Sources retain package-relative paths. renames changes individual destinations, while packaged_srcs supplies the complete ordered list of mapped source groups (including :srcs_files). srcs_name and files_name override those source target names, and binary_visibility grants access to the packaged executable independently. The binary includes the shared infrastructure Ansible configuration and repository collection. Run bazel test //path/to/package:<name>.syntax to check the default playbook or append .syntax to a named command to check its playbook. Each test uses the command’s arguments and packaged extra-vars files without loading deployment plugins.

ansible_lint runs ansible-lint from Bazel-managed Python dependencies. A Go test runner exposes the CLI binaries under their hyphenated names, configures writable Ansible paths, and invokes the linter against workspace-relative sources.

Python dependencies are declared in pyproject.toml and locked in uv.lock. Update the lock with //tools/ansible:uv_lock.update and review its diff. Build //tools/ansible:uv_lock to generate it without source writes. These use the shared uv locking workflow, whose sandboxed resolution action requires network access to PyPI.

The current lock uses ansible-core 2.22 for Python 3.15 targets. Its matching Ansible community bundle is 15.0.0rc1, selected because the stable community bundle still requires an older core. The compatibility change records that release-candidate constraint and deployment validation.

bazel run //tools/ansible:molecule -- --version runs the locked Molecule CLI using the same Python dependency set as Ansible. The disposable QEMU guest runner and collection scenarios are tracked in the Molecule runner change.

1 - Bzl

Bazel code

1.1 - al_ansible_binaries

al_ansible_binaries

load("@com_alwaldend_src//tools/ansible/rules:al_ansible_binaries.bzl", "al_ansible_binaries")

al_ansible_binaries(name, args, visibility, **kwargs)

Generate a binary for earch ansible command

PARAMETERS

NameDescriptionDefault Value
namename prefixnone
argsspecific kwargs{}
visibilityvisibilityNone
kwargscommon argumentsnone

1.2 - al_ansible_binary

al_ansible_binary

load("@com_alwaldend_src//tools/ansible/rules:al_ansible_binary.bzl", "al_ansible_binary")

al_ansible_binary(name, data, ansible, arguments, process_name)

Run an ansible command

ATTRIBUTES

NameDescriptionTypeMandatoryDefault
nameA unique name for this target.Namerequired
dataDataList of labelsoptional[]
ansibleAnsible executableDictionary: String -> Labeloptional{"ansible": "@com_alwaldend_src//tools/ansible", "ansible_config": "@com_alwaldend_src//tools/ansible:ansible_config", "ansible_console": "@com_alwaldend_src//tools/ansible:ansible_console", "ansible_doc": "@com_alwaldend_src//tools/ansible:ansible_doc", "ansible_galaxy": "@com_alwaldend_src//tools/ansible:ansible_galaxy", "ansible_inventory": "@com_alwaldend_src//tools/ansible:ansible_inventory", "ansible_playbook": "@com_alwaldend_src//tools/ansible:ansible_playbook", "ansible_pull": "@com_alwaldend_src//tools/ansible:ansible_pull", "ansible_test": "@com_alwaldend_src//tools/ansible:ansible_test", "ansible_vault": "@com_alwaldend_src//tools/ansible:ansible_vault"}
argumentsAnsible argumentsList of stringsoptional[]
process_nameProcess nameStringrequired

1.3 - al_ansible_extension

al_ansible_extension

al_ansible_extension = use_extension("@com_alwaldend_src//tools/ansible/rules:al_ansible_extension.bzl", "al_ansible_extension")
al_ansible_extension.lock(name, lock)

Ansible extensions

TAG CLASSES

Attributes

NameDescriptionTypeMandatoryDefault
nameName prefixNamerequired
lockAnsible lock pathLabelrequired

1.4 - al_ansible_package

Repository Ansible packages with mapped runtime files and AL commands.

al_ansible_package

load("@com_alwaldend_src//tools/ansible/rules:al_ansible_package.bzl", "al_ansible_package")

al_ansible_package(name, srcs, configs, plugin_labels, args, packaged_srcs, renames, srcs_name,
                   files_name, binary_visibility, extra_vars_files, **kwargs)

Package sources and expose Ansible playbook commands and syntax tests.

PARAMETERS

NameDescriptionDefault Value
nameCommand prefix; the packaged executable is <name>_bin.none
srcsFiles to map relative to the caller’s package.none
configsAL configuration dependencies for command wrappers.[]
plugin_labelsAL plugin selectors for command wrappers.{}
argsCommand suffix to Ansible argument list, without the executable. Defaults to the inventory.yaml/playbook_deploy.yaml invocation.None
packaged_srcsMapped source groups; defaults to the files_name target.None
renamesDestination overrides for srcs.{}
srcs_nameCombined runtime source target name."srcs"
files_nameMapped source target name."srcs_files"
binary_visibilityOptional visibility for the packaged executable.None
extra_vars_filesPackaged Ansible variables files passed in order to each playbook.[]
kwargsCommon target attributes for the package and commands.none

1.5 - al_ansible_role

al_ansible_role

load("@com_alwaldend_src//tools/ansible/rules:al_ansible_role.bzl", "al_ansible_role")

al_ansible_role(name, srcs, visibility, renames, deps, **kwargs)

Create targets for an ansible role

PARAMETERS

NameDescriptionDefault Value
namename prefixnone
srcsrole sourcesnone
visibilityresulting archive visibilitynone
renames

-

{}
deps

-

[]
kwargskwargs for pkg_filesnone

1.6 - al_ansible_scripts