Skip to content

Instantly share code, notes, and snippets.

@jgoos
Created June 24, 2022 13:20
Show Gist options
  • Save jgoos/aa9fa3a83829b7a559930acaccc0d2e4 to your computer and use it in GitHub Desktop.
Save jgoos/aa9fa3a83829b7a559930acaccc0d2e4 to your computer and use it in GitHub Desktop.
To test ansible roles via Jenkins using molecule and podman
pipeline {
agent any
stages {
stage('Create ENV') {
steps {
sh '''
# Remove we do not have local collections
rm -rf $HOME/.ansible
# Initialize new venv
python3.8 -m venv venv
# Update pip
source venv/bin/activate
python -m pip install --upgrade pip wheel
python -m pip install "molecule[lint,podman]" ansible-core yamllint ansible-lint flake8
'''
}
}
stage('Show versions') {
parallel {
stage('Show versions') {
steps {
sh '''
source venv/bin/activate
podman -v
python -V
ansible --version
molecule --version
'''
}
}
stage('What') {
steps {
sh 'ls -fla'
}
}
}
}
stage('Molecule lint') {
parallel {
stage('Molecule lint') {
steps {
sh '''
source venv/bin/activate
pwd
cd ansible_code
molecule lint
'''
}
}
stage('Install Collections') {
steps {
sh 'ansible-galaxy collection install containers.podman'
}
}
}
}
stage('Molecule test') {
steps {
sh '''
source venv/bin/activate
cd ansible_code
export PLATFORM_NAME="$(uuidgen)"
mkdir -p "${MOLECULE_PROJECT_DIRECTORY}/tmp/${PLATFORM_NAME}"
export MOLECULE_EPHEMERAL_DIRECTORY="${MOLECULE_PROJECT_DIRECTORY}/tmp/${PLATFORM_NAME}"
molecule test
'''
}
}
}
environment {
PY_COLORS = 1
ANSIBLE_FORCE_COLOR = 1
}
post {
always {
cleanWs(cleanWhenNotBuilt: false, deleteDirs: true, disableDeferredWipeout: true, notFailBuild: true, patterns: [[pattern: '.gitignore', type: 'INCLUDE'],
[pattern: '.propsfile', type: 'EXCLUDE']])
}
}
options {
checkoutToSubdirectory('ansible_code')
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment