Bazel rules for running Ansible playbooks
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
# See releases for urls and checksums
http_archive(
name = "rules_ansible",
sha256 = "{sha256}",
urls = ["https://github.com/abrisco/rules_ansible/releases/download/{version}/rules_ansible-v{version}.tar.gz"],
)
load("@rules_ansible//ansible:repositories.bzl", "rules_ansible_dependencies")
rules_ansible_dependencies()
The rules provide sufficient python requirements for running Ansible. To load these requirements, use the following snippet.
load("@rules_ansible//ansible:transitive.bzl", "rules_ansible_transitive_dependencies")
rules_ansible_transitive_dependencies()
load("@rules_ansible//ansible:pip_deps.bzl", "rules_ansible_pip_dependencies")
rules_ansible_pip_dependencies()
load("@rules_ansible//ansible:pip_deps_install.bzl", "rules_ansible_pip_dependencies_install")
rules_ansible_pip_dependencies_install()
load("@rules_ansible//ansible:repositories.bzl", "ansible_register_toolchains")
ansible_register_toolchains()
However, if users whish to control the version of Ansible being used, they can create a custom ansible_toolchain with their own requirements and register that in the workspace.
ansible_lint_test(name, config, playbook)
A test rule for running ansible-lint
on an Ansible playbook.
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
config | The ansible-lint config file to use | Label | optional | //ansible:lint_config |
playbook | The ansible_playbook target to lint. |
Label | required |
ansible_playbook(name, config, inventory, playbook, roles, vault)
A rule for running Ansible playbooks
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
config | The path to an Ansible config file. | Label | optional | //ansible:config |
inventory | Ansible inventory files | List of labels | optional | [] |
playbook | The ansible playbook yaml file. | Label | required | |
roles | The source files for all ansible roles required by the playbook. | List of labels | optional | [] |
vault | Vautl files to be decrypted before running | List of labels | optional | [] |
ansible_toolchain(name, ansible, ansible_core, ansible_lint)
An ansible toolchain
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
ansible | An ansible py_library target. |
Label | required | |
ansible_core | An ansible-core py_library target. |
Label | required | |
ansible_lint | An ansible-lint py_library target. |
Label | required |
current_ansible_toolchain(name, lib)
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required | |
lib | Which py_library within the ansible toolchain to yield providers from | String | optional | "ansible" |
ansible_register_toolchains(register_toolchains)
PARAMETERS
Name | Description | Default Value |
---|---|---|
register_toolchains | - |
True |
rules_ansible_dependencies()
ansible_lint_aspect(name)
An aspect for linting ansible targets.
ASPECT ATTRIBUTES
ATTRIBUTES
Name | Description | Type | Mandatory | Default |
---|---|---|---|---|
name | A unique name for this target. | Name | required |