Skip to content

Commit c30a353

Browse files
committed
feat: add ansible execution environment for playbooks
This creates an ansible based container that has ansible-runner as the executor inside which can then be loaded with playbooks and roles so that we can have a consistent way to configure different parts of the system or react to events in the system and execute a series of steps. To provide a consistent way to configure the overall system and react to events in the system. Some areas where this might be useful is for OpenStack Helm has a bootstrap bash script that executes on deployment. This is a big hardcoded blob and will be easier to be configurable via ansible.
1 parent 903100f commit c30a353

File tree

10 files changed

+125
-0
lines changed

10 files changed

+125
-0
lines changed

.ansible-lint

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
exclude_paths:
4+
- ansible/.venv/

.github/workflows/containers.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ on:
77
branches:
88
- main
99
paths:
10+
- "ansible/**"
1011
- "containers/**"
1112
- ".github/workflows/containers.yaml"
1213
- "python/**"
1314
pull_request:
1415
types: [opened, synchronize, reopened, closed]
1516
paths:
17+
- "ansible/**"
1618
- "containers/**"
1719
- ".github/workflows/containers.yaml"
1820
- "python/**"
@@ -123,6 +125,7 @@ jobs:
123125
container:
124126
- name: ironic-nautobot-client
125127
- name: nova-flavors
128+
- name: ansible
126129

127130
steps:
128131
- name: setup docker buildx
@@ -182,6 +185,7 @@ jobs:
182185
- dnsmasq
183186
- ironic-nautobot-client
184187
- nova-flavors
188+
- ansible
185189

186190
steps:
187191
- name: clean up PR container

.pre-commit-config.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ repos:
4848
- id: ruff
4949
args: [--fix]
5050
- id: ruff-format
51+
- repo: https://github.com/ansible/ansible-lint
52+
rev: v25.1.2
53+
hooks:
54+
- id: ansible-lint
55+
entry: "sh -c 'cd ansible && python3 -m ansiblelint -v --force-color'"
56+
additional_dependencies:
57+
- ansible
58+
- jmespath
59+
files: '^ansible/.*$'
5160
- repo: https://github.com/python-poetry/poetry
5261
rev: '1.7.1'
5362
hooks:

ansible/playbooks/debug.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
# Copyright (c) 2025 Rackspace Technology, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
- name: Debug
17+
hosts: localhost
18+
19+
roles:
20+
- role: debug

ansible/requirements.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ansible-core==2.18.4
2+
ansible-runner==2.4.0
3+
openstacksdk==4.3.0
4+
pynautobot==2.6.1
5+
jmespath==1.0.1

ansible/requirements.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
collections:
2+
- name: community.general
3+
version: "==10.5.0"
4+
- name: openstack.cloud
5+
version: "==2.4.1"
6+
- name: networktocode.nautobot
7+
version: "==5.6.0"

ansible/roles/debug/tasks/main.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
---
2+
# Copyright (c) 2025 Rackspace Technology, Inc.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
5+
# not use this file except in compliance with the License. You may obtain
6+
# a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
# License for the specific language governing permissions and limitations
14+
# under the License.
15+
16+
- name: Debug
17+
ansible.builtin.debug:
18+
msg: debug

containers/ansible/Dockerfile.ansible

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
FROM python:3.12-slim
2+
3+
ENV PIP_NO_CACHE_DIR=off \
4+
PIP_DISABLE_PIP_VERSION_CHECK=on \
5+
PIP_DEFAULT_TIMEOUT=100
6+
7+
RUN apt-get update \
8+
&& apt-get install -y --no-install-recommends \
9+
git \
10+
&& apt-get autoremove -y \
11+
&& apt-get clean \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
RUN --mount=type=cache,target=/root/.cache/pip pip install dumb-init==1.2.5
15+
16+
COPY ansible/requirements.txt ansible/requirements.yml ./
17+
18+
RUN --mount=type=cache,target=/root/.cache/pip pip install -r requirements.txt
19+
RUN --mount=type=cache,target=/root/.cache/pip ansible-galaxy collection install -r requirements.yml
20+
21+
RUN useradd -m -d /runner -s /bin/bash runner
22+
WORKDIR /runner
23+
USER runner
24+
25+
COPY ansible/playbooks/ /runner/project/
26+
COPY ansible/roles/ /runner/project/roles/
27+
28+
ENTRYPOINT ["dumb-init"]
29+
CMD ["ansible-runner"]

docs/component-ansible.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Ansible
2+
3+
Ansible is used to configure different parts of the overall system
4+
in a consistent manner. To this effect a container is produced with
5+
playbooks, roles and collections pre-installed and it can be run by
6+
providing system configuration to it.
7+
8+
## Execution Environment
9+
10+
Ansible is executed within a container which is build within this repo.
11+
The configuration and the source are contained within the
12+
[`ansible/`][ansible-src] directory.
13+
14+
## Configuration
15+
16+
The execution environment within the container is [ansible-runner][ansible-runner].
17+
An inventory directory is necessary to be provided which would be part
18+
of your system deployment data.
19+
20+
## Sample Execution
21+
22+
```bash
23+
docker run --rm -it ghcr.io/rackerlabs/understack/ansible:latest -- \
24+
ansible-runner run /runner --playbook debug.yaml
25+
```
26+
27+
[ansible-src]: <https://github.com/rackerlabs/understack/tree/main/ansible>
28+
[ansible-runner]: <https://ansible.readthedocs.io/projects/runner/en/stable/intro/>

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ nav:
116116
- component-networking-neutron.md
117117
- component-argo-workflows.md
118118
- component-understack-workflows.md
119+
- component-ansible.md
119120
- 'Deployment Guide':
120121
- deploy-guide/index.md
121122
- Quick Start: deploy-guide/gitops-install.md

0 commit comments

Comments
 (0)