Ansible #1262
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
- '!packaging/technical-addon/**' | |
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 | |
env: | |
GO_VERSION: 1.23.10 | |
jobs: | |
setup-environment: | |
runs-on: ubuntu-24.04 | |
needs: lint | |
steps: | |
- name: Check out the codebase. | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
cache-dependency-path: '**/go.sum' | |
- name: Installing dependency | |
run: | | |
make install-tools | |
cross-compile: | |
runs-on: ubuntu-24.04 | |
needs: [ setup-environment ] | |
strategy: | |
matrix: | |
SYS_BINARIES: [ "binaries-linux_amd64", "binaries-linux_arm64", "binaries-linux_ppc64le", "binaries-windows_amd64" ] | |
steps: | |
- name: Check out the codebase. | |
uses: actions/checkout@v4 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
cache-dependency-path: '**/go.sum' | |
- name: Build Collector | |
run: | | |
make ${{ matrix.SYS_BINARIES }} | |
- name: Uploading binaries | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.SYS_BINARIES }} | |
path: | | |
./bin/* | |
agent-bundle-linux: | |
runs-on: ${{ fromJSON('["ubuntu-24.04", "otel-arm64"]')[matrix.ARCH == 'arm64'] }} | |
needs: lint | |
strategy: | |
matrix: | |
ARCH: [ "amd64", "arm64" ] | |
fail-fast: false | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
id: bundle-cache | |
with: | |
path: .cache/buildx/agent-bundle-${{ matrix.ARCH }} | |
key: agent-bundle-buildx-${{ matrix.ARCH }}-${{ hashFiles('packaging/bundle/**') }} | |
restore-keys: | | |
agent-bundle-buildx-${{ matrix.ARCH }}- | |
- run: make -C packaging/bundle agent-bundle-linux ARCH=${{ matrix.ARCH }} | |
env: | |
BUNDLE_CACHE_HIT: "${{ steps.bundle-cache.outputs.cache-hit }}" | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: agent-bundle-linux-${{ matrix.ARCH }} | |
path: ./dist/agent-bundle_linux_${{ matrix.ARCH }}.tar.gz | |
build-package: | |
runs-on: ubuntu-24.04 | |
needs: [ cross-compile, agent-bundle-linux ] | |
strategy: | |
matrix: | |
SYS_PACKAGE: [ "deb", "rpm", "tar" ] | |
ARCH: [ "amd64", "arm64" ] | |
fail-fast: false | |
steps: | |
- name: Check out the codebase. | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
cache-dependency-path: '**/go.sum' | |
- name: Downloading binaries-linux_${{ matrix.ARCH }} | |
uses: actions/download-artifact@v4 | |
with: | |
name: binaries-linux_${{ matrix.ARCH }} | |
path: ./bin | |
- uses: actions/download-artifact@v4 | |
with: | |
name: agent-bundle-linux-${{ matrix.ARCH }} | |
path: ./dist | |
- name: Build ${{ matrix.SYS_PACKAGE }} ${{ matrix.ARCH }} package | |
run: make ${{ matrix.SYS_PACKAGE }}-package SKIP_COMPILE=true SKIP_BUNDLE=true VERSION="" ARCH="${{ matrix.ARCH }}" | |
- name: Uploading ${{ matrix.SYS_PACKAGE }} ${{ matrix.ARCH }} package artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: ${{ matrix.SYS_PACKAGE }}-${{ matrix.ARCH }}-package | |
path: ./dist/splunk-otel-collector* | |
agent-bundle-windows: | |
needs: lint | |
runs-on: ${{ matrix.OS }} | |
strategy: | |
matrix: | |
OS: [ "windows-2025" ] | |
env: | |
PIP_CACHE_DIR: ${{ github.workspace }}/.cache/pip | |
steps: | |
- uses: actions/checkout@v4 | |
- uses: actions/cache@v4 | |
with: | |
path: ${{ env.PIP_CACHE_DIR }} | |
key: agent-bundle-windows-pip-${{ hashFiles('packaging/bundle/collectd-plugins.yaml', 'packaging/bundle/scripts/requirements.txt') }} | |
- run: ./packaging/bundle/scripts/windows/make.ps1 bundle | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: agent-bundle-windows-${{ matrix.OS }} | |
path: ./dist/agent-bundle_windows_amd64.zip | |
msi-custom-actions: | |
runs-on: windows-2025 | |
needs: lint | |
steps: | |
- name: Check out the codebase. | |
uses: actions/checkout@v4 | |
- name: Uninstall default WiX | |
run: choco uninstall wixtoolset | |
- name: Install WiX 3.14.0 | |
run: choco install wixtoolset --version 3.14.0 --allow-downgrade --force | |
- name: Build Custom Actions | |
working-directory: packaging/msi/SplunkCustomActions | |
run: | | |
dotnet test ./test/SplunkCustomActionsTests.csproj -c Release | |
dotnet publish ./src/SplunkCustomActions.csproj -c Release -o ./bin/Release | |
- name: Package Custom Actions | |
run: | | |
$WixPath = "${Env:ProgramFiles(x86)}\WiX Toolset v3.14" | |
$sfxcaDll = "${WixPath}\SDK\x64\sfxca.dll" | |
$Env:PATH = "${WixPath}\SDK;" + $Env:PATH | |
$customActionDir = "${PWD}\packaging\msi\SplunkCustomActions" | |
$customActionBinDir = "${customActionDir}\bin\Release" | |
MakeSfxCA.exe "${PWD}\dist\SplunkCustomActions.CA.dll" ` | |
"${sfxcaDll}" ` | |
"${customActionBinDir}\SplunkCustomActions.dll" ` | |
"${customActionBinDir}\Microsoft.Deployment.WindowsInstaller.dll" ` | |
"${customActionDir}\src\CustomAction.config" | |
- uses: actions/upload-artifact@v4 | |
with: | |
name: msi-custom-actions | |
path: ./dist/SplunkCustomActions.CA.dll | |
msi-build: | |
runs-on: ubuntu-24.04 | |
env: | |
WINDOWS_VER: "windows-2025" | |
needs: [cross-compile, agent-bundle-windows, msi-custom-actions] | |
steps: | |
- name: Check out the codebase. | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Downloading binaries-windows_amd64 | |
uses: actions/download-artifact@v4 | |
with: | |
name: binaries-windows_amd64 | |
path: ./bin | |
- name: Set up Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: ${{ env.GO_VERSION }} | |
cache-dependency-path: '**/go.sum' | |
- name: Downloading agent-bundle-windows | |
uses: actions/download-artifact@v4 | |
with: | |
name: agent-bundle-windows-${{ env.WINDOWS_VER }} | |
path: ./dist | |
- name: Downloading msi-custom-actions | |
uses: actions/download-artifact@v4 | |
with: | |
name: msi-custom-actions | |
path: ./packaging/msi/SplunkCustomActions/bin/Release | |
- name: Build MSI | |
run: | | |
mkdir -p dist | |
make msi SKIP_COMPILE=true VERSION="" | |
- name: Uploading msi build artifacts | |
uses: actions/upload-artifact@v4 | |
with: | |
name: msi-build | |
path: ./dist/*.msi | |
lint: | |
name: Lint | |
runs-on: ubuntu-24.04 | |
defaults: | |
run: | |
working-directory: 'deployments/ansible' | |
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, build-package] | |
runs-on: ubuntu-24.04 | |
defaults: | |
run: | |
working-directory: 'deployments/ansible' | |
strategy: | |
fail-fast: false | |
matrix: | |
ansible: | |
# Testing only the versions currently supported per https://endoflife.date/ansible | |
- ansible~=11.6.0 | |
- ansible~=10.7.0 | |
distro: | |
- amazonlinux2023 | |
- centos9 | |
- debian11 | |
- debian12 | |
- ubuntu2004 | |
- ubuntu2204 | |
steps: | |
- name: Check out the codebase. | |
uses: actions/checkout@v4 | |
- uses: actions/download-artifact@v4 | |
with: | |
path: /tmp | |
- uses: DamianReeves/[email protected] | |
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.13' | |
cache: 'pip' | |
cache-dependency-path: "${{ github.workspace }}/requirements.txt" | |
- name: Install test dependencies. | |
run: | | |
python -m pip install --upgrade setuptools | |
# 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, msi-build] | |
runs-on: ubuntu-24.04 | |
defaults: | |
run: | |
working-directory: 'deployments/ansible' | |
timeout-minutes: 60 | |
strategy: | |
fail-fast: false | |
matrix: | |
ansible: | |
# Testing only the versions currently supported per https://endoflife.date/ansible | |
- ansible~=11.6.0 | |
- ansible~=10.7.0 | |
distro: | |
- "2016" | |
- "2019" | |
- "2022" | |
scenario: | |
- default | |
- default_install_remote_version | |
- custom_vars | |
- with_instrumentation | |
- custom_vars_install_old_version | |
steps: | |
- name: Free up disk space for vagrant box | |
uses: jlumbroso/[email protected] | |
- name: Check out the codebase. | |
uses: actions/checkout@v4 | |
- name: Make tmp directory for msi build artifact | |
run: mkdir -p /tmp/msi-build | |
- uses: actions/download-artifact@v4 | |
with: | |
name: msi-build | |
path: /tmp/msi-build | |
- 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/[email protected] | |
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: Clean VirtualBox cache | |
run: | | |
# Related issues: | |
# https://bbs.archlinux.org/viewtopic.php?id=298056 | |
# https://forums.virtualbox.org/viewtopic.php?t=112438 | |
# https://forums.virtualbox.org/viewtopic.php?t=112481 | |
echo "3" | sudo tee /proc/sys/vm/drop_caches | |
echo "1" | sudo tee /proc/sys/vm/drop_caches | |
- name: free after clean cache | |
run: | | |
free -h | |
- 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 | |
runs-on: ubuntu-24.04 | |
defaults: | |
run: | |
working-directory: 'deployments/ansible' | |
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") | |
} |