Skip to content

Ansible

Ansible #43

Workflow file for this run

name: Ansible
# The workflow triggered by any change in deployments/ansible/.
# 1. Run lint checks and Ansible Molecule tests.
# 2. Push a new "ansible-v<VERSION>" tag, if the version was updated
# in deployments/ansible/galaxy.yml.
on:
push:
paths:
- '.github/workflows/ansible.yml'
- 'deployments/ansible/galaxy.yml'
branches:
- main
pull_request:
paths:
- '.github/workflows/ansible.yml'
- 'deployments/ansible/**'
- '!**.md'
schedule:
- cron: '0 0 * * 1,4' # Every Monday and Thrusday at midnight UTC
concurrency:
group: ansible-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
permissions:
contents: write
defaults:
run:
working-directory: 'deployments/ansible'
jobs:
lint:
name: Lint
# Use 20.04.5 until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/16450 is resolved
runs-on: ubuntu-20.04
steps:
- name: Check out the codebase.
uses: actions/checkout@v4
- name: Set up Python 3.
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install yamllint.
run: pip3 install yamllint
- name: Lint code.
run: yamllint .
linux-test:
name: Linux Test
needs: lint
# Use 20.04.5 until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/16450 is resolved
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
ansible:
# Testing only the versions currently supported per https://endoflife.date/ansible
- ansible~=9.2.0
- ansible~=8.7.0
distro:
- amazonlinux2
- amazonlinux2023
- centos8
- centos9
- debian9
- debian10
- debian11
- debian12
- opensuse12
- opensuse15
- ubuntu1604
- ubuntu1804
- ubuntu2004
- ubuntu2204
exclude:
# ansible-core used by ansible 9.2.0 requires a minimum of Python2 version 2.7 or Python3 version 3.6. Current version: 3.5.2
- distro: ubuntu1604
ansible: ansible~=9.2.0
steps:
- name: Check out the codebase.
uses: actions/checkout@v4
- uses: DamianReeves/write-file-action@v1.3
with:
path: "${{ github.workspace }}/requirements.txt"
contents: |
${{ matrix.ansible }}
ansible-lint==6.22.2
molecule==6.0.3
molecule-plugins[docker]==23.5.0
docker==7.0.0
requests<2.32.0
urllib3<2
- name: Set up Python 3.
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: "${{ github.workspace }}/requirements.txt"
- name: Install test dependencies.
run: |
# workaround for https://github.com/yaml/pyyaml/issues/724
pip3 install 'wheel==0.40.0'
pip3 install 'Cython<3.0' 'PyYaml~=5.0' --no-build-isolation
pip3 install --use-pep517 -r ${GITHUB_WORKSPACE}/requirements.txt
- name: Run Molecule tests.
run: molecule --debug -v --base-config ./molecule/config/docker.yml test --all
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_DISTRO: ${{ matrix.distro }}
windows-test:
name: Windows Test
needs: lint
runs-on: ubuntu-24.04
timeout-minutes: 60
strategy:
fail-fast: false
matrix:
ansible:
# Testing only the versions currently supported per https://endoflife.date/ansible
- ansible~=9.2.0
- ansible~=8.7.0
distro:
- "2016"
- "2019"
- "2022"
scenario:
- default
- custom_vars
- with_instrumentation
steps:
- name: Free up disk space for vagrant box
uses: jlumbroso/free-disk-space@v1.3.1
- name: Check out the codebase.
uses: actions/checkout@v4
- name: Install vagrant and virtualbox
run: |
sudo apt update && sudo apt install -y virtualbox
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install -y vagrant
- uses: DamianReeves/write-file-action@v1.3
with:
path: "${{ github.workspace }}/requirements.txt"
contents: |
${{ matrix.ansible }}
ansible-compat==4.1.11
ansible-lint==6.22.2
molecule==6.0.3
molecule-plugins[vagrant]==23.5.0
pywinrm==0.4.3
- name: Set up Python 3.
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: "${{ github.workspace }}/requirements.txt"
- name: Install test dependencies.
run: pip3 install --use-pep517 -r ${GITHUB_WORKSPACE}/requirements.txt
- name: Download vagrant box
run: |
box=$( yq ".platforms[] | select(.name == \"${{ matrix.distro }}\") | .box" ./molecule/config/windows.yml )
box_version=$( yq ".platforms[] | select(.name == \"${{ matrix.distro }}\") | .box_version" ./molecule/config/windows.yml )
eval "box_version=${box_version}"
json=$( wget -nv -O- https://vagrantcloud.com/api/v2/vagrant/${box} )
url=$( echo "$json" | jq -r ".versions[] | select(.version == \"${box_version}\") | .providers[] | select(.name == \"virtualbox\") | .url" )
wget -nv -O /tmp/vagrant.box $url
- name: Run Molecule tests.
run: molecule --debug -v --base-config ./molecule/config/windows.yml test -s ${{ matrix.scenario }} -p ${{ matrix.distro }}
env:
PY_COLORS: '1'
ANSIBLE_FORCE_COLOR: '1'
MOLECULE_VAGRANT_BOX_URL: /tmp/vagrant.box
MOLECULE_VAGRANT_BOX_VERSION: " " # version must not be set when using a local box
push-release-tag:
name: Push Release Tag
needs: lint
# Use 20.04.5 until https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/16450 is resolved
runs-on: ubuntu-20.04
if: github.ref == 'refs/heads/main'
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Read current version of the Ansible Collection
id: read-galaxy-yaml
uses: cumulusds/get-yaml-paths-action@v1
with:
file: deployments/ansible/galaxy.yml
version: version
- name: Ensure version is fetched from galaxy.yml
if: steps.read-galaxy-yaml.outputs.version == ''
run: echo "Fail to read version from galaxy.yml" && exit 1
- name: Push new release tag if it doesn't exist
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const tagRef = "tags/ansible-v${{ steps.read-galaxy-yaml.outputs.version }}"
const existingRefs = await github.rest.git.listMatchingRefs({
owner: context.repo.owner,
repo: context.repo.repo,
ref: tagRef
})
if (existingRefs.data.length === 0) {
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/" + tagRef,
sha: context.sha
})
} else {
console.log(tagRef + " already exists")
}