5 月 082015
 

如果有了跳板机,Jenkins还能工作么?答案是可以的。

Jenkins+ansible

参考文档:

案例:http://birdinroom.blog.51cto.com/7740375/1351875

ansible使用介绍:http://blog.chinaunix.net/uid-21458680-id-3599736.html

由于我们的Jenkins使用的比他还复杂。所以就不啰嗦了。主要介绍下ansible的使用:

一、ansible 安装
1、软件包安装
EPEL已经提供了ansible所需的所有支持软件包,所以在这里使用epel源进行安装: 
$sudo rpm -ivh http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm
安装ansible
$sudo yum install ansible -y
===============================================================================
Package                        Arch                  Version                      Repository           Size
===============================================================================
Installing:
ansible                        noarch                1.0-1.el6                    epel                336 k
Installing for dependencies:
PyYAML                         x86_64                3.10-3.el6                   epel                157 k
libyaml                        x86_64                0.1.3-1.el6                  epel                 52 k
python-babel                   noarch                0.9.4-5.1.el6                base                1.4 M
python-crypto                  x86_64                2.0.1-22.el6                 base                159 k
python-jinja2                  x86_64                2.2.1-1.el6                  base                465 k
python-paramiko                noarch                1.7.5-2.1.el6                base                728 k
Transaction Summary
===============================================================================
Install       7 Package(s)
Total download size: 3.3 M
Installed size: 17 M
2、免密钥
在master服务器生成ssh-key,并分发到所有客户端(在这里也许你有更好的方法,至少目前该方法是最简单的实现方式)
$ssh-keygen -t rsa  【一路回车】
$ssh-copy-id -i ~/.ssh/id_rsa.pub【客户端IP地址】
在此过程提示输入客户端密码
3、建立hosts文件
ansible的hosts默认在/etc/ansible/目录中,采用rpm安装的ansible会将该hosts作为范例,其中提示ansible是支持域名和ip两种客户端命名格式的【经过测试是没有问题的】,还介绍了不同的安装分组方法,建议好好看看:
在这里一共两台服务器master和slave,分为两组
$vim /etc/ansible/hosts   【原博客人员这里写的有误】
[localhost]
127.0.0.1
[slave]
192.168.30.3
4、测试ansible的使用
在这里使用 ping模块
$ansible slave -i /etc/ansible/hosts -m ping
192.168.30.3 | success >> {
    “changed”: false,
    “ping”: “pong”
}
解读:从返回值分析,ansible slave节点192.168.30.3的ping值成功。说明ansible的已经能够使用!

主要通过Jenkins调用的命令就是

ansible slave -i /etc/ansible/hosts -m shell -a  “echo hello”

当然这种方案报错信息的问题不好处理,可能没有做跳转的提示信息更多。

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理

This website stores cookies on your computer. These cookies are used to provide a more personalized experience and to track your whereabouts around our website in compliance with the European General Data Protection Regulation. If you decide to to opt-out of any future tracking, a cookie will be setup in your browser to remember this choice for one year.

Accept or Deny