最近由于工做须要学习了ansible,把这几天所学的东西作了个总结,和你们分享一下:python
ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优势,实现了批量系统配置、批量程序部署、批量运行命令等功能。
ansible是基于模块工做的,自己没有批量部署的能力。真正具备批量部署的是ansible所运行的模块,ansible只是提供一种框架。主要包括:
(1)链接插件connection plugins:负责和被监控端实现通讯;
(2)host inventory:指定操做的主机,是一个配置文件里面定义监控的主机;
(3)各类模块核心模块、command模块、自定义模块;
(4)借助于插件完成记录日志邮件等功能;
(5)playbook:剧本执行多个任务时,非必需可让节点一次性运行多个任务。编程
了解了ansible的基本概念以及它的用途,下来,咱们开始部署ansible(本次部署实在Redhat7上进行的),让ansible在本身的机器上跑起来。
为了能使用yum安装,首先咱们得配置本地yum源,具体配置参考个人另外一篇文章
RHEL7配置本地yum源json
安装ansible
一、安装python-devel
yum install python-devel
二、setuptools模块安装
三、pycrypto模块安装
四、PyYAML模块安装
五、Jinja2模块安装
六、paramiko模块安装
七、simplejson模块安装
八、ansible安装
在网上下载以上模块以及ansiblede的.tar.gz包
分别执行tar xvzf *解压后 再执行python setup.py install --record log.txt 命令安装vim
ansible安装成功以后,接下来进行Ansible的配置
一、SSH免密钥登陆设置segmentfault
[root@localhost ~]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: c9:72:68:d4:5a:a7:73:8c:f6:29:3b:44:99:7e:ae:20 root@localhost.localdomain The key's randomart image is: +--[ RSA 2048]----+ | | | . | | . oo. | | . =+* | | =oS o | | . +o+.. | | E ...oo | | . ..o. | | oo | +-----------------+
二、将信任文件分发到指定服务器上服务器
ssh-copy-id -i /root/.ssh/id_rsa.pub 172.28.159.103
三、配置ansible.cfg微信
[root@localhost ~]# vim /etc/ansible/ansible.cfg [defaults] private_key_file = /root/.ssh/id_rsa
四、主机组定义框架
[root@localhost ~]# vim /etc/ansible/hosts [test] localhost 192.168.56.103
五、简单测试运维
[root@localhost ~]# ansible test -m ping 192.168.56.103 | SUCCESS => { "changed": false, "ping": "pong" } localhost | SUCCESS => { "changed": false, "ping": "pong" }
个人我的 微信公众号:**Java编程社区** 欢迎你们的关注