Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions containers/ansible-test/ansible-test/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ARG BASE_IMAGE=localhost/openstack/openstack-base:latest
FROM ${BASE_IMAGE}

LABEL summary="OpenStack Ansible Test" \
io.k8s.description="Ansible test runner for feature verification testing with kolla interface"

ARG CONSTRAINTS_FILE=requirements.lock
COPY ${CONSTRAINTS_FILE} /deps-upper-constraints.txt

RUN uid_gid_manage ansible

COPY ansible-test/bindeps.txt /tmp/bindeps.txt
RUN pkgs=$(cat /tmp/bindeps.txt | grep -v '^#' | grep -v '^$' | tr '\n' ' ') && \
if [ -n "${pkgs}" ]; then microdnf -y install ${pkgs} && microdnf clean all && rm -rf /var/cache/dnf; fi && \
rm /tmp/bindeps.txt

COPY ansible-test/pythondeps.txt /tmp/pythondeps.txt
RUN extrapkgs=$(cat /tmp/pythondeps.txt | grep -v '^#' | grep -v '^$' | tr '\n' ' ') && \
pip3 install --no-cache-dir --prefix=/usr -c /deps-upper-constraints.txt ${extrapkgs} && \
rm /tmp/pythondeps.txt

COPY common/ansible_sudoers /etc/sudoers.d/ansible_sudoers
RUN chmod 440 /etc/sudoers.d/ansible_sudoers

COPY ansible-test/run_ansible.sh /usr/local/bin/run_ansible.sh
RUN chmod +x /usr/local/bin/run_ansible.sh && \
mkdir -p /var/lib/ansible && \
chown -R ansible:ansible /var/lib/ansible

ENTRYPOINT ["/usr/local/bin/run_ansible.sh"]
USER ansible
7 changes: 7 additions & 0 deletions containers/ansible-test/ansible-test/bindeps.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
gcc
git-core
python3-devel
python3-pip
python3-setuptools
libffi-devel
rsync
2 changes: 2 additions & 0 deletions containers/ansible-test/ansible-test/pythondeps.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ansible
openstacksdk
52 changes: 52 additions & 0 deletions containers/ansible-test/ansible-test/run_ansible.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

set -euo pipefail

ANSIBLE_DIR="/var/lib/ansible/ansible"
ANSIBLE_FILE_EXTRA_VARS_PARAM="${ANSIBLE_FILE_EXTRA_VARS_PARAM:-}"
POD_ANSIBLE_PLAYBOOK="${POD_ANSIBLE_PLAYBOOK:-}"
POD_ANSIBLE_EXTRA_VARS="${POD_ANSIBLE_EXTRA_VARS:-}"
POD_ANSIBLE_GIT_REPO="${POD_ANSIBLE_GIT_REPO:-}"
POD_ANSIBLE_GIT_BRANCH="${POD_ANSIBLE_GIT_BRANCH:-}"

# Check and set ansible debug verbosity
ANSIBLE_DEBUG=""
if [[ ${POD_DEBUG:-true} == true ]]; then
ANSIBLE_DEBUG="-vvvv"
fi

# Clone the Ansible repository
git clone "$POD_ANSIBLE_GIT_REPO" "$ANSIBLE_DIR"

if [[ -n "$POD_ANSIBLE_GIT_BRANCH" ]]; then
pushd "$ANSIBLE_DIR"
git fetch && git checkout --track origin/${POD_ANSIBLE_GIT_BRANCH}
popd
fi

# Handle extra vars file if provided
if [[ -n "${POD_ANSIBLE_FILE_EXTRA_VARS:-}" ]]; then
echo "$POD_ANSIBLE_FILE_EXTRA_VARS" > "$ANSIBLE_DIR/extra_vars.yaml"
ANSIBLE_FILE_EXTRA_VARS_PARAM="-e @$ANSIBLE_DIR/extra_vars.yaml"
fi

# Handle inventory file if provided
if [[ -n "${POD_ANSIBLE_INVENTORY:-}" ]]; then
echo "$POD_ANSIBLE_INVENTORY" > "$ANSIBLE_DIR/inventory"
fi

# Install collections if specified
if [[ -n "${POD_INSTALL_COLLECTIONS:-}" ]]; then
ansible-galaxy collection install $POD_INSTALL_COLLECTIONS
fi

# Install collections from requirements.yaml if the file exists
if [[ -f "$ANSIBLE_DIR/requirements.yaml" ]]; then
ansible-galaxy install -r "$ANSIBLE_DIR/requirements.yaml"
else
echo "requirements.yaml doesn't exist, skipping requirements installation"
fi

# Navigate to ansible directory and run playbook
cd "$ANSIBLE_DIR"
ansible-playbook "$POD_ANSIBLE_PLAYBOOK" $ANSIBLE_DEBUG -i $ANSIBLE_DIR/inventory $POD_ANSIBLE_EXTRA_VARS $ANSIBLE_FILE_EXTRA_VARS_PARAM
1 change: 1 addition & 0 deletions containers/ansible-test/common/ansible_sudoers
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ansible ALL=(ALL) NOPASSWD: ALL
1 change: 1 addition & 0 deletions containers/ansible-test/sources.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
master upper-constraints https://opendev.org/openstack/requirements.git master a56b052dc4bd64f4a1fa035a28f3358ad79caefc
Empty file.
Empty file.