From ada3517df6ee4228c39ebd41abf0897f64415844 Mon Sep 17 00:00:00 2001 From: eshulman Date: Thu, 27 Jun 2024 10:30:26 +0300 Subject: [PATCH] Create container to run ansible playbooks from Create container to run ansible playbooks from. This container is meantto be used for NFV performance test runs using test operator --- container-images/containers.yaml | 2 +- container-images/kolla/base/uid_gid_manage.sh | 1 + .../tcib/base/ansible-tests/ansibleTests.yaml | 24 +++++++++++ .../tcib/base/ansible-tests/ansible_sudoers | 1 + .../tcib/base/ansible-tests/run_ansible.sh | 41 +++++++++++++++++++ 5 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 container-images/tcib/base/ansible-tests/ansibleTests.yaml create mode 100644 container-images/tcib/base/ansible-tests/ansible_sudoers create mode 100644 container-images/tcib/base/ansible-tests/run_ansible.sh diff --git a/container-images/containers.yaml b/container-images/containers.yaml index feb9fa1..05b86ef 100644 --- a/container-images/containers.yaml +++ b/container-images/containers.yaml @@ -1,4 +1,5 @@ container_images: +- imagename: quay.io/podified-master-centos9/openstack-ansible-tests:current-podified - imagename: quay.io/podified-master-centos9/openstack-aodh-api:current-podified - imagename: quay.io/podified-master-centos9/openstack-aodh-evaluator:current-podified - imagename: quay.io/podified-master-centos9/openstack-aodh-listener:current-podified @@ -31,7 +32,6 @@ container_images: - imagename: quay.io/podified-master-centos9/openstack-heat-api:current-podified - imagename: quay.io/podified-master-centos9/openstack-heat-engine:current-podified - imagename: quay.io/podified-master-centos9/openstack-horizon:current-podified -- imagename: quay.io/podified-master-centos9/openstack-horizontest:current-podified - imagename: quay.io/podified-master-centos9/openstack-ironic-api:current-podified - imagename: quay.io/podified-master-centos9/openstack-ironic-conductor:current-podified - imagename: quay.io/podified-master-centos9/openstack-ironic-inspector:current-podified diff --git a/container-images/kolla/base/uid_gid_manage.sh b/container-images/kolla/base/uid_gid_manage.sh index 718336c..38a959d 100755 --- a/container-images/kolla/base/uid_gid_manage.sh +++ b/container-images/kolla/base/uid_gid_manage.sh @@ -70,6 +70,7 @@ _SUPPORTED_USERS['swift']='swift 42445 42445 /var/lib/swift kolla' _SUPPORTED_USERS['tempest']='tempest 42480 42480 /var/lib/tempest kolla' _SUPPORTED_USERS['tobiko']='tobiko 42495 42495 /var/lib/tobiko kolla' _SUPPORTED_USERS['tss']='tss 59 59' +_SUPPORTED_USERS['ansible']='ansible 227 227 /var/lib/ansible kolla' for _USER_TO_CREATE in $_USERS_TO_CREATE; do # Initialize computed args diff --git a/container-images/tcib/base/ansible-tests/ansibleTests.yaml b/container-images/tcib/base/ansible-tests/ansibleTests.yaml new file mode 100644 index 0000000..4553e9f --- /dev/null +++ b/container-images/tcib/base/ansible-tests/ansibleTests.yaml @@ -0,0 +1,24 @@ +tcib_envs: + USE_EXTERNAL_FILES: true +tcib_actions: +- run: bash /usr/local/bin/uid_gid_manage {{ tcib_user }} +- run: dnf -y install {{ tcib_packages.common | join(' ') }} && dnf clean all && rm -rf /var/cache/dnf +- run: pip3 install ansible==2.9.27 openstacksdk +- run: cp /usr/share/tcib/container-images/tcib/base/ansible-tests/run_ansible.sh /var/lib/ansible/run_ansible.sh +- run: chmod +x /var/lib/ansible/run_ansible.sh +- run: chown -R ansible:ansible /var/lib/ansible + +tcib_entrypoint: /var/lib/ansible/run_ansible.sh + +tcib_packages: + common: + - gcc + - git + - python3 + - python3-devel + - python3-pip + - python3-setuptools + - libffi-devel + - rsync + +tcib_user: ansible diff --git a/container-images/tcib/base/ansible-tests/ansible_sudoers b/container-images/tcib/base/ansible-tests/ansible_sudoers new file mode 100644 index 0000000..16a6afb --- /dev/null +++ b/container-images/tcib/base/ansible-tests/ansible_sudoers @@ -0,0 +1 @@ +ansible ALL=(ALL) NOPASSWD: ALL diff --git a/container-images/tcib/base/ansible-tests/run_ansible.sh b/container-images/tcib/base/ansible-tests/run_ansible.sh new file mode 100644 index 0000000..7389a9a --- /dev/null +++ b/container-images/tcib/base/ansible-tests/run_ansible.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +set -euo pipefail + +ANSIBLE_DIR="/var/lib/perf/ansible" + +# 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" + +# 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 collection 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 \ No newline at end of file