Ansible standardization of roles with Jenkins Continuous Integration (c)
1. Standardization roles Playbook
1.1 directory structure is created roles basic prototype
[root@Ansible /]# tree /myroles/
/myroles/
├── nginx.yaml #入口触发配置文件
└── roles #playbook的原型配置目录
└── nginx #nginx相关模组配置目录
├── files #copy模块和script模块的参数src默认会从这个文件夹查找
├── handlers #用来存放notify的
├── tasks #用来存放ansible模块任务的
├── templates #用来存放j2的
└── vars #用来存放变量的
7 directories, 1 file
1.2 Entrance trigger profile
[root@Ansible /]# mkdir -p /myroles/roles/nginx
[root@Ansible /]# cat /myroles/nginx.yaml
---
- hosts: all #执行的主机范围
gather_facts: True #开启系统内置变量
roles: #启用roles原型配置
- nginx #执行nginx原型模组
1.3 roles in tasks using the task orchestration module
1.3.1 Adding tasks task profile module in nginx
[root@Ansible /]# mkdir -p /myroles/roles/nginx/tasks/
[root@Ansible /]# cat /myroles/roles/nginx/tasks/main.yaml
---
- name: check alived #任务1的名字
ping: #执行ping模块
- name: #任务2的名字
shell: ls / #执行shell模块
register: ls_result #将执行结果保存给变量
- debug: var=ls_result #变量的值赋值给debug进行输出
1.3.2 After completion of the directory structure shown below
[root@Ansible /]# tree /myroles/
/myroles/
├── nginx.yaml #nginx模组入口配置文件
└── roles
└── nginx #nginx原型模组目录
└── tasks
└── main.yaml #nginx模组的tasks任务配置文件
3 directories, 2 files
1.3.3 perform nginx.yaml entrance profiles View Results
[root@Ansible myroles]# pwd
/myroles
[root@Ansible myroles]# ansible-playbook nginx.yaml
PLAY [all] *************************************************************************************
TASK [Gathering Facts] *************************************************************************
ok: [Web02]
ok: [Web01]
TASK [nginx : check alived] ********************************************************************
ok: [Web02]
ok: [Web01]
TASK [nginx : shell] ***************************************************************************
changed: [Web01]
changed: [Web02]
TASK [nginx : debug] ***************************************************************************
ok: [Web01] => {
"ls_result": {
"changed": true,
"cmd": "ls /",
"delta": "0:00:00.008101",
"end": "2018-09-09 03:33:26.602832",
"failed": false,
"rc": 0,
"start": "2018-09-09 03:33:26.594731",
"stderr": "",
"stderr_lines": [],
"stdout": "bin\nboot\ndev\netc\nhome\nlib\nlib64\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsrv\nsys\ntmp\nusr\nvar",
"stdout_lines": [
"bin",
"boot",
"dev",
"etc",
"home",
"lib",
"lib64",
"media",
"mnt",
"opt",
"proc",
"root",
"run",
"sbin",
"srv",
"sys",
"tmp",
"usr",
"var"
]
}
}
ok: [Web02] => {
"ls_result": {
"changed": true,
"cmd": "ls /",
"delta": "0:00:00.007408",
"end": "2018-09-09 03:33:26.609171",
"failed": false,
"rc": 0,
"start": "2018-09-09 03:33:26.601763",
"stderr": "",
"stderr_lines": [],
"stdout": "bin\nboot\ndev\netc\nhome\nlib\nlib64\nmedia\nmnt\nopt\nproc\nroot\nrun\nsbin\nsrv\nsys\ntmp\nusr\nvar",
"stdout_lines": [
"bin",
"boot",
"dev",
"etc",
"home",
"lib",
"lib64",
"media",
"mnt",
"opt",
"proc",
"root",
"run",
"sbin",
"srv",
"sys",
"tmp",
"usr",
"var"
]
}
}
PLAY RECAP *************************************************************************************
Web01 : ok=4 changed=1 unreachable=0 failed=0
Web02 : ok=4 changed=1 unreachable=0 failed=0
Find tasks task list after ansible-playbook execution entry profile nginx.yaml, it will automatically find the directory nginx roles in the directory and enter and execute tasks main.yaml profile
#本配置和之前的roles配置等效
[root@Ansible /]# cat /service/scripts/test.yaml
---
- hosts: all
gather_facts: True
tasks: #其实roles的本质就是将tasks任务单独写了。
- name: check alived #并在入口文件里追加了roles去查找tasks配置文件路径
ping:
- name:
shell: ls /
register: ls_result
- debug: var=ls_result
1.4 roles in vars modules use custom variables
1.4.1 Adding vars task profile module in nginx
[root@Ansible nginx]# pwd
/myroles/roles/nginx
[root@Ansible nginx]# mkdir vars
[root@Ansible nginx]# cat vars/main.yaml #vars模组的配置文件
---
my_name: yangwenbo
phone: 17310658206
[root@Ansible nginx]# cat tasks/main.yaml #tasks模组的配置文件
---
- name: check alived
ping:
- name:
shell: ls /
register: ls_result
- debug: var=ls_result
- name: #添加对变量引用的任务编排
shell: echo my phone is {{ phone }}
register: echo_result
- debug: var=echo_result
1.4.2 After completion of the directory structure shown below
[root@Ansible nginx]# tree /myroles/
/myroles/
├── nginx.retry
├── nginx.yaml #nginx模组入口配置文件
└── roles
└── nginx #nginx原型模组目录
├── tasks
│ └── main.yaml #nginx模组的tasks任务配置文件
└── vars
└── main.yaml #nginx模组的vars任务配置文件
5 directories, 5 files
1.4.3 perform nginx.yaml entrance profiles View Results
[root@Ansible myroles]# pwd
/myroles
[root@Ansible myroles]# ansible-playbook nginx.yaml
PLAY [all] *************************************************************************************
TASK [Gathering Facts] *************************************************************************
ok: [Web01]
ok: [Web02]
TASK [nginx : check alived] ********************************************************************
ok: [Web02]
ok: [Web01]
TASK [nginx : shell] ***************************************************************************
changed: [Web02]
changed: [Web01]
TASK [nginx : debug] ***************************************************************************
ok: [Web01] => {
#中间省略。。。
ok: [Web02] => {
#中间省略。。。
TASK [nginx : shell] ***************************************************************************
changed: [Web01]
changed: [Web02]
TASK [nginx : debug] ***************************************************************************
ok: [Web01] => {
"echo_result": {
"changed": true,
"cmd": "echo my phone is 17310658206",
"delta": "0:00:00.004659",
"end": "2018-09-09 03:48:24.375861",
"failed": false,
"rc": 0,
"start": "2018-09-09 03:48:24.371202",
"stderr": "",
"stderr_lines": [],
"stdout": "my phone is 17310658206",
"stdout_lines": [
"my phone is 17310658206" #输出的结果
]
}
}
ok: [Web02] => {
"echo_result": {
"changed": true,
"cmd": "echo my phone is 17310658206",
"delta": "0:00:00.006155",
"end": "2018-09-09 03:48:24.397609",
"failed": false,
"rc": 0,
"start": "2018-09-09 03:48:24.391454",
"stderr": "",
"stderr_lines": [],
"stdout": "my phone is 17310658206",
"stdout_lines": [
"my phone is 17310658206" #输出的结果
]
}
}
PLAY RECAP *************************************************************************************
Web01 : ok=6 changed=2 unreachable=0 failed=0
Web02 : ok=6 changed=2 unreachable=0 failed=0
1.5 Use copy, script module standardization
roles model in the use of copy, script module, the default look from roles / nginx / files there
1.5.1 Adding files task profile module in nginx
[root@Ansible nginx]# pwd
/myroles/roles/nginx
[root@Ansible nginx]# mkdir files
[root@Ansible nginx]# cat files/test #files模组的配置文件
welcome to yunjisuan
[root@Ansible nginx]# cat files/test.sh #files模组的配置文件
echo "My name is yangwenbo" >> /tmp/test
[root@Ansible nginx]# chmod +x files/test.sh
[root@Ansible nginx]# ll files/test.sh
-rwxr-xr-x. 1 root root 41 Sep 9 04:11 files/test.sh
[root@Ansible nginx]# cat tasks/main.yaml #tasks模组的配置文件
---
- name: check alived
ping:
- name:
shell: ls /
register: ls_result
- debug: var=ls_result
- name:
shell: echo my phone is {{ phone }}
register: echo_result
- debug: var=echo_result
- name: #添加copy模块
copy: src=test dest=/root/
- name: #添加script模块(自动在目标IP机器上执行脚本)
script: test.sh
1.5.2 After completion of the directory structure shown below
[root@Ansible nginx]# tree /myroles/
/myroles/
├── nginx.retry
├── nginx.yaml
└── roles
└── nginx #nginx原型模组目录
├── files
│ ├── test #nginx模组的files任务配置文件
│ └── test.sh #nginx模组的files的脚本
├── tasks
│ └── main.yaml #nginx模组的tasks任务配置文件
└── vars
└── main.yaml #nginx模组的vars任务配置文件
5 directories, 6 files
1.5.3 perform nginx.yaml entry profile
[root@Ansible myroles]# ansible-playbook nginx.yaml
PLAY [all] *************************************************************************************
TASK [Gathering Facts] *************************************************************************
ok: [Web01]
ok: [Web02]
TASK [nginx : check alived] ********************************************************************
ok: [Web01]
ok: [Web02]
TASK [nginx : shell] ***************************************************************************
changed: [Web01]
changed: [Web02]
TASK [nginx : debug] ***************************************************************************
ok: [Web01] => {
#中间省略。。。
ok: [Web02] => {
#中间省略。。。
TASK [nginx : shell] ***************************************************************************
changed: [Web01]
changed: [Web02]
TASK [nginx : debug] ***************************************************************************
ok: [Web01] => {
#中间省略。。。
ok: [Web02] => {
#中间省略。。。
TASK [nginx : copy] ****************************************************************************
changed: [Web02]
changed: [Web01]
TASK [nginx : script] **************************************************************************
changed: [Web02]
changed: [Web01]
PLAY RECAP *************************************************************************************
Web01 : ok=8 changed=4 unreachable=0 failed=0
Web02 : ok=8 changed=4 unreachable=0 failed=0
1.5.4 View the results
[root@Web01 ~]# cat /root/test
welcome to yunjisuan
[root@Web01 ~]# cat /tmp/test
My name is yangwenbo
[root@Web02 ~]# cat /root/test
welcome to yunjisuan
[root@Web02 ~]# cat /tmp/test
My name is yangwenbo
Use 1.6 roles in template module
roles model in use template module from the default look for roles / nginx / template inside
1.6.1 Add template task profile module in nginx
[root@Ansible nginx]# pwd
/myroles/roles/nginx
[root@Ansible nginx]# mkdir templates
[root@Ansible nginx]# cat templates/test.j2 #templates模组的配置文件
myname is {{ my_name }},my phone is {{ phone }} #引用自定义变量
my ipaddress is {{ansible_all_ipv4_addresses[0]}} #引用内置变量
[root@Ansible nginx]# cat tasks/main.yaml #tasks模组的配置文件
---
- name: check alived
ping:
- name:
shell: ls /
register: ls_result
- debug: var=ls_result
- name:
shell: echo my phone is {{ phone }}
register: echo_result
- debug: var=echo_result
- name:
copy: src=test dest=/root/
- name:
script: test.sh
- name:
template: src=test.j2 dest=/root/test2 #下发可变配置文件
1.6.2 After completion of the directory structure shown below
[root@Ansible nginx]# tree /myroles/
/myroles/
├── nginx.retry
├── nginx.yaml
└── roles
└── nginx #nginx原型模组目录
├── files
│ ├── test #nginx模组的files任务配置文件
│ └── test.sh #nginx模组的files的脚本
├── tasks
│ └── main.yaml #nginx模组的tasks任务配置文件
├── templates
│ └── test.j2 #nginx模组的templates任务配置文件
└── vars
└── main.yaml #nginx模组的vars任务配置文件
5 directories, 6 files
1.6.3 perform nginx.yaml entry profile
[root@Ansible myroles]# pwd
/myroles
[root@Ansible myroles]# ansible-playbook nginx.yaml
PLAY [all] *************************************************************************************
TASK [Gathering Facts] *************************************************************************
ok: [Web01]
ok: [Web02]
TASK [nginx : check alived] ********************************************************************
ok: [Web01]
ok: [Web02]
TASK [nginx : shell] ***************************************************************************
changed: [Web01]
changed: [Web02]
TASK [nginx : debug] ***************************************************************************
ok: [Web01] => {
#中间省略。。。
ok: [Web02] => {
#中间省略。。。
TASK [nginx : shell] ***************************************************************************
changed: [Web01]
changed: [Web02]
TASK [nginx : debug] ***************************************************************************
ok: [Web01] => {
#中间省略。。。
ok: [Web02] => {
#中间省略。。。
TASK [nginx : copy] ****************************************************************************
ok: [Web02]
ok: [Web01]
TASK [nginx : script] **************************************************************************
changed: [Web01]
changed: [Web02]
TASK [nginx : template] ************************************************************************
changed: [Web02]
changed: [Web01]
PLAY RECAP *************************************************************************************
Web01 : ok=9 changed=4 unreachable=0 failed=0
Web02 : ok=9 changed=4 unreachable=0 failed=0
1.6.4 View the results
[root@Web01 ~]# cat /root/test2
myname is yangwenbo,my phone is 17310658206
my ipaddress is 192.168.200.74
[root@Web02 ~]# cat /root/test2
myname is yangwenbo,my phone is 17310658206
my ipaddress is 192.168.200.75
Use 1.7 roles in the notify module
roles use notify module, the default look from roles / nginx / handles inside
1.7.1 Add template task profile module in nginx
[root@Ansible nginx]# pwd
/myroles/roles/nginx
[root@Ansible nginx]# mkdir handlers
[root@Ansible nginx]# cat handlers/main.yaml #handlers模组的配置文件
---
- name: start_nginx #定义handlers的动作类型
shell: /usr/local/nginx/sbin/nginx
- name: stop_nginx #定义handlers的动作类型
shell: /usr/local/nginx/sbin/nginx -s stop
- name: reload_nginx #定义handlers的动作类型
shell: /usr/local/nginx/sbin/nginx -s reload
[root@Ansible nginx]# cat tasks/main.yaml #tasks模组的配置文件
---
- name: check alived
ping:
- name:
shell: ls /
register: ls_result
- debug: var=ls_result
- name:
shell: echo my phone is {{ phone }}
register: echo_result
- debug: var=echo_result
- name:
copy: src=test dest=/root/
- name:
script: test.sh
- name:
template: src=test.j2 dest=/root/test2
notify: start_nginx #执行template任务后下发通知给handlers执行start_nginx
1.7.2 After completion of the directory structure shown below
[root@Ansible nginx]# tree /myroles/
/myroles/
├── nginx.retry
├── nginx.yaml
└── roles
└── nginx #nginx原型模组目录
├── files
│ ├── test #nginx模组的files任务配置文件
│ └── test.sh #nginx模组的files的脚本
├── handlers
│ └── main.yaml #nginx模组的handlers任务配置文件
├── tasks
│ └── main.yaml #nginx模组的tasks任务配置文件
├── templates
│ └── test.j2 #nginx模组的templates任务配置文件
└── vars
└── main.yaml #nginx模组的vars任务配置文件
5 directories, 6 files
1.7.3 perform nginx.yaml entry profile
[root@Ansible myroles]# pwd
/myroles
[root@Ansible myroles]# ansible-playbook nginx.yaml
PLAY [all] *************************************************************************************
TASK [Gathering Facts] *************************************************************************
ok: [Web02]
ok: [Web01]
TASK [nginx : check alived] ********************************************************************
ok: [Web01]
ok: [Web02]
TASK [nginx : shell] ***************************************************************************
changed: [Web02]
changed: [Web01]
TASK [nginx : debug] ***************************************************************************
ok: [Web01] => {
#中间省略。。。
ok: [Web02] => {
#中间省略。。。
TASK [nginx : shell] ***************************************************************************
changed: [Web01]
changed: [Web02]
TASK [nginx : debug] ***************************************************************************
ok: [Web01] => {
#中间省略。。。
ok: [Web02] => {
#中间省略。。。
TASK [nginx : copy] ****************************************************************************
ok: [Web01]
ok: [Web02]
TASK [nginx : script] **************************************************************************
changed: [Web01]
changed: [Web02]
TASK [nginx : template] ************************************************************************
ok: [Web01]
ok: [Web02]
PLAY RECAP *************************************************************************************
Web01 : ok=9 changed=3 unreachable=0 failed=0
Web02 : ok=9 changed=3 unreachable=0 failed=0
Special Note: issued a notice notify task before it only if the resulting changes will be executed, if nothing has changed, then notify will not be executed. E.g:
1.7.4 tasks task caused change, triggering notify
[root@Ansible /]# cat /tmp/test.yaml #notify模组的配置文件
---
- hosts: Web01
gather_facts: True
tasks:
- name:
copy: src=/tmp/test dest=/root/ #这步造成目标改变才能出发notify
notify: start_nginx
handlers:
- name: start_nginx
shell: /usr/local/nginx/sbin/nginx
1.7.5 execute notify entry profile
#第一次执行/tmp/test.yaml
[root@Ansible /]# ansible-playbook /tmp/test.yaml
PLAY [Web01] ***********************************************************************************
TASK [Gathering Facts] *************************************************************************
ok: [Web01]
TASK [copy] ************************************************************************************
changed: [Web01] #发生了改变
RUNNING HANDLER [start_nginx] #触了发notify ******************************************************************
changed: [Web01]
PLAY RECAP *************************************************************************************
Web01 : ok=3 changed=2 unreachable=0 failed=0
#再次执行/tmp/test.yaml
[root@Ansible /]# ansible-playbook /tmp/test.yaml
PLAY [Web01] ***********************************************************************************
TASK [Gathering Facts] *************************************************************************
ok: [Web01]
TASK [copy] ************************************************************************************
ok: [Web01] #没有造成任务改变,未触发notify通知
PLAY RECAP *************************************************************************************
Web01 : ok=2 changed=0 unreachable=0 failed=0
2. Jenkins environment to build
Because Jenkins is dependent on java, it is first introduced to build java environment
2.1 official binary package and extract install, Download the official binary package:
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2.2 Installation Java (decompression, can be moved)
[root@Ansible yang]# pwd
/yang
[root@Ansible yang]# ls
jdk-8u171-linux-x64.tar.gz
[root@Ansible yang]# tar xf jdk-8u171-linux-x64.tar.gz -C /usr/local/
[root@Ansible yang]# cd /usr/local/
[root@Ansible local]# mv jdk1.8.0_171 jdk
[root@Ansible local]# /usr/local/jdk/bin/java -version #全路径验证java是否安装成功
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
2.3 Configuration Environment Variables java / etc / profile
[root@Ansible local]# sed -i.org '$a export JAVA_HOME=/usr/local/jdk/' /etc/profile
[root@Ansible local]# sed -i.org '$a export PATH=$PATH:$JAVA_HOME/bin' /etc/profile
[root@Ansible local]# sed -i.org '$a export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar' /etc/profile
[root@Ansible local]# tail -3 /etc/profile
export JAVA_HOME=/usr/local/jdk/
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
[root@Ansible local]# source /etc/profile
[root@Ansible local]# java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
2.4 Jenkins download and run
#下载jinkins
[root@Ansible yang]# wget http://ftp-chi.osuosl.org/pub/jenkins/war-stable/2.107.2/jenkins.war
[root@Ansible yang]# ls
jenkins.war
#启动jenkins并后台运行
[root@Ansible ~]# nohup java -jar jenkins.war &> /tmp/jenkins.out &
[root@Ansible yang]# netstat -antup | grep java | grep -v grep
tcp6 0 0 :::8080 :::* LISTEN 1405/java
tcp6 1 0 192.168.200.73:48132 52.202.51.185:443 CLOSE_WAIT 1405/java
udp 0 0 192.168.200.73:54730 192.168.200.2:53 ESTABLISHED 1472/java
udp6 0 0 :::5353 :::* 1405/java
udp6 0 0 :::33848 :::* 1405/java
2.5 We then be accessed in the browser: http: //192.168.200.73: 8080 appears the following interface
[root@Ansible ~]# cat .jenkins/secrets/initialAdminPassword
a21db34167d442f1bb23ff335016b5d3
3. Jenkins introduction and initial configuration
Jenkins's role?
- Visual Management Server
- Continuous build, or directly to the pull tag on svn git and issued to the server
- Visualization ansible
Jenkins listening on port 8080
- Jenkins started way: nohup java -jar jenkins.war &> /tmp/jenkins.out &
- Check listening port: netstat -antup | grep java
- Access method: http: //192.168.200.73: 8080
- Jenkins path default password is required to view the server where Jenkins: /root/.jenkins/secrets/initialAdminPassword
- Jenkins initial configuration: Copy the password on the server to come to after submitting the browser, calmly waiting, the following interface
3.1 install the necessary plug-ins
3.2 Adding a new user yunjisuan
3.3 permission to view Jenkins (login user can do anything)
System Management ---> Global Security Configuration
4. Jenkins order to achieve visualization of the results
4.1 ssh way to add the managed server
系统管理--->系统设置--->找到Publish over SSH可以添加对应的操作服务器
这就添加好一台被管理的主机了。要继续添加被管理的主机只需要重复之前的过程
4.2 创建新任务
4.3 立刻构建任务并执行
5. Jenkins+svn实现持续化集成
需求,开发改完代码上传到svn上,然后运维打包最新版本代码部署到业务服务器上。
svn的部署与应用请参考专题(一)
5.1 设置svn的连接密码,并进行代码的部署测试
设置完毕后,应用保存。
在windows上对svn的yunjisuan项目进行版本提交后
选择立刻构建项目
[root@Web01 /]# hostname -I
192.168.200.74
[root@Web01 /]# ls /tmp/test/
新建文本文档.txt
5.2 模拟真实环境web服务器的代码部署和备份
5.2.1 模拟真实环境web服务器的代码部署和备份
[root@Web01 /]# mkdir -p /www/{html,backup}
[root@Web02 /]# mkdir -p /www/{html,backup}
[root@Web01 /]# tree /www
/www
├── backup #html网页目录的备份放置目录
└── html #网页目录
2 directories, 0 files
5.2.2 在jenkins上设置Web01,Web02两台服务器作为项目的构建目标
5.2.3将以下shell脚本代码复制到构建目标的Exec command里
#备份web服务器旧网页目录代码,并将部署到服务器上的新代码覆盖到网页目录里
cd /www
/usr/bin/tar zcf html_$(date +%F-%H-%S).tar.gz html
rm -rf html/*
mv html_*.tar.gz backup/
mv /tmp/test/* /www/html/
5.2.4 选择立刻构建进行测试
[root@Web01 /]# tree /www
/www
├── backup
│ └── html_2018-09-11-06-53.tar.gz
└── html
├── 123123.txt
└── \346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt
2 directories, 3 files
[root@Web02 /]# tree /www
/www
├── backup
│ └── html_2018-09-11-06-53.tar.gz
└── html
├── 123123.txt
└── \346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt
2 directories, 3 files
5.3 模拟真实环境,开发进行代码回滚
5.3.1 右键点击共享目录选择TortoiseSVN--->Show log
右键点击想要回滚的版本选择Revert to this revision
此时你发现你的共享目录里的东西已经被回滚到了指定的版本。
最后我们千万别忘记了右键点击共享目录,将结果进行提交(SVN commit)
5.3.2 重新进行jenkins项目构建,并检查部署情况
[root@Web01 /]# tree /www
/www
├── backup
│?? ├── html_2018-09-11-06-34.tar.gz
│?? └── html_2018-09-11-06-53.tar.gz
└── html
└── 123123.txt
2 directories, 3 files
[root@Web02 /]# tree /www
/www
├── backup
│?? ├── html_2018-09-11-06-34.tar.gz
│?? └── html_2018-09-11-06-53.tar.gz
└── html
└── 123123.txt
2 directories, 3 files
至此,测试成功!
6. Jenkins实现ansible可视化
6.1 安装jenkins ansible插件,启动ansible插件
最后进入安装界面最下方勾选,安装完成时重启Jenkins
6.2 系统管理--->全局工具配置---->配置ansible
6.3 新建一个项目任务,使用ansible进行构建,跑个shell和copy模块
6.3.1 Create a new project called the ansible_test task
6.3.2 enter the configuration of the project. Construction of a task-based ansible
6.3.3 Then click once constructed function, and view the output results
6.3.4 Create a new project tasks, build using ansible-playbook
[root@Ansible /]# cat /myroles/roles/nginx/ansible-playbook/test.yaml
#准备一个playbook的配置文件
---
- hosts: all
tasks:
- name: test jenkins ansible_playbook
shell: echo "welcome to yunjisuan" >> /tmp/yunwei.txt
Then create a new project tasks, configure
Select the visual output test results immediately build and view Construction