服务端安装ansible
- 安装ansible
[root@jenkins ~]# yum install -y epel-release [root@jenkins ~]# yum install -y ansible
- 免密
[root@jenkins ~]# ssh-keygen -t rsa [root@jenkins ~]# ssh-copy-id 192.168.90.16
- 定义机器组
[root@jenkins ~]# vim /etc/ansible/hosts [server] server1 ansible_ssh_host=192.168.90.16 server2 ansible_ssh_host=192.168.90.17
- 测试
[root@jenkins ~]# ansible -m ping server server2 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" } server1 | SUCCESS => { "ansible_facts": { "discovered_interpreter_python": "/usr/bin/python" }, "changed": false, "ping": "pong" }
集成到共享库
package org.devops
//ansible
def AnsibleDeploy(hosts,func){
sh " ansible ${func} ${hosts}"
}
- 引入到jenkinsfile
#!groovy
@Library('jenkinslib@master') _
def build = new org.devops.build()
def deploy = new org.devops.deploy()
String buildShell = "${env.buildShell}"
String buildType = "${env.buildType}"
String deployHosts = "${env.deployHosts}"
pipeline{
agent { node { label "master"}}
stages{
stage("build"){
steps{
script{
build.Build(buildType,buildShell)
deploy.AnsibleDeploy("${deployHosts}","-m ping ")
}
}
}
}
}
Jenkins添加机器参数
- 构建测试
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论