jenkins集成ansible
一、jenkins集成ansible步骤1、在jenkins全局配置工具中配置ansible的执行路径,如下:2、创建一个pipeline的流水线,如下:jenkins与gitlab集成步骤省略3、gitlab创建Jenkinsfile文件如下:jenkinsfile内容如下:pipeline {agent {label 'k8s-master'}stages {stage('daemon an
·
一、jenkins集成ansible步骤
1、在jenkins全局配置工具中配置ansible的执行路径,如下:
2、创建一个pipeline的流水线,如下:
jenkins与gitlab集成步骤省略
3、gitlab创建Jenkinsfile文件如下:
jenkinsfile内容如下:
pipeline {
agent {
label 'k8s-master'
}
stages {
stage('daemon ansible') {
steps {
ansiblePlaybook (
playbook: "${env.WORKSPACE}/daemon.yaml",
inventory: "${env.WORKSPACE}/hosts",
credentialsId: "f1d56643-64f3-45f1-ab86-adc116644828"
)
}
}
}
}
上传文件至gitlab,如下:
[root@weizb-3 jenkins-ansible]# git add .
[root@weizb-3 jenkins-ansible]# git commit -m "update daemon.yaml"
[master df95780] update daemon.yaml
2 files changed, 2 insertions(+), 2 deletions(-)
[root@weizb-3 jenkins-ansible]# git push -u origin
Counting objects: 7, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (4/4), 380 bytes | 0 bytes/s, done.
Total 4 (delta 2), reused 0 (delta 0)
To http://172.20.150.168:48080/root/jenkins-ansible.git
6668c89..df95780 master -> master
Branch master set up to track remote branch master from origin.
4、jenkins触发构建,如下:
日志如下:
Started by GitLab push by Administrator
Obtained Jenkinsfile from git http://172.20.150.168:48080/root/jenkins-ansible.git
Running in Durability level: MAX_SURVIVABILITY
[Pipeline] Start of Pipeline
[Pipeline] node
Running on k8s-master in /jenkins/workspace/jenkins-ansible
[Pipeline] {
[Pipeline] stage
[Pipeline] { (Declarative: Checkout SCM)
[Pipeline] checkout
The recommended git tool is: NONE
using credential jenkins to gitlab passwd
Fetching changes from the remote Git repository
skipping resolution of commit remotes/origin/master, since it originates from another repository
Checking out Revision df95780c0e80d6575933f78b0d6e89e80d472fd1 (refs/remotes/origin/master)
> /usr/bin/git rev-parse --resolve-git-dir /jenkins/workspace/jenkins-ansible/.git # timeout=10
> /usr/bin/git config remote.origin.url http://172.20.150.168:48080/root/jenkins-ansible.git # timeout=10
Fetching upstream changes from http://172.20.150.168:48080/root/jenkins-ansible.git
> /usr/bin/git --version # timeout=10
> git --version # 'git version 1.8.3.1'
using GIT_ASKPASS to set credentials jenkins to gitlab passwd
> /usr/bin/git fetch --tags --progress http://172.20.150.168:48080/root/jenkins-ansible.git +refs/heads/*:refs/remotes/origin/* # timeout=10
> /usr/bin/git rev-parse refs/remotes/origin/master^{commit} # timeout=10
> /usr/bin/git config core.sparsecheckout # timeout=10
> /usr/bin/git checkout -f df95780c0e80d6575933f78b0d6e89e80d472fd1 # timeout=10
Commit message: "update daemon.yaml"
> /usr/bin/git rev-list --no-walk 6668c89f4465a38d669b15494d601ae09063e9fd # timeout=10
[Pipeline] }
[Pipeline] // stage
[Pipeline] withEnv
[Pipeline] {
[Pipeline] stage
[Pipeline] { (daemon ansible)
[Pipeline] ansiblePlaybook
[jenkins-ansible] $ sshpass ******** ansible-playbook /jenkins/workspace/jenkins-ansible/daemon.yaml -i /jenkins/workspace/jenkins-ansible/hosts -u root -k
PLAY [web] *********************************************************************
TASK [Gathering Facts] *********************************************************
ok: [192.168.100.54]
TASK [echo daemon] *************************************************************
changed: [192.168.100.54]
PLAY RECAP *********************************************************************
192.168.100.54 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0
[Pipeline] }
[Pipeline] // stage
[Pipeline] }
[Pipeline] // withEnv
[Pipeline] }
[Pipeline] // node
[Pipeline] End of Pipeline
Finished: SUCCESS
更多推荐
已为社区贡献1条内容
所有评论(0)