我建议不要使用 Ansible 插件,而是使用 Jenkins 方式:
从Jenkinsfile创建一个管道,例如:
pipeline {
parameters {
string(name: 'Parameter1', defaultValue: 'value1', description: 'Parameter1?')
string(name: 'Parameter2', defaultValue: 'value2', description: 'Parameter2?')
string(name: 'Parameter3', defaultValue: 'value3', description: 'Parameter3?')
}
agent any
options {
ansiColor('xterm')
timestamps()
}
stages {
stage('Run Ansible Playbook') {
steps {
script {
retry (1) {
try {
echo "Build ${params.Parameter1} on ${params.Parameter2}"
sh "export ANSIBLE_FORCE_COLOR=true && \
ansible-playbook -vv \
-i inventories/hosts \
-e \"var1=${Parameter1}\" \
-e \"var2=${Parameter2}\" \
-e \"var3=${Parameter3}\" \
--vault-password-file ~/.ansible/vaultpass.txt \
playbooks/main.yml"
}
catch (exception) {
throw exception
}
finally {
sh "export ANSIBLE_FORCE_COLOR=true && \
ansible-playbook -vv \
-i inventories/hosts \
-e \"var1=${Parameter1}\" \
-e \"var2=${Parameter2}\" \
-e \"var3=${Parameter3}\" \
--vault-password-file ~/.ansible/vaultpass.txt \
playbooks/clean.yml"
}
}
}
}
}
}
}
与使用 Ansible 插件相比,您可以以更简洁、更简单的方式控制您的管道。