Ansible 介绍及安装
1. 介绍、
- Ansible 是一个 IT 自动化工具。它能配置系统、部署软件、编排更复杂的 IT 任务,如连续部署或零停机时间滚动更新。
- Ansible 用 Python 编写,尽管市面上已经有很多可供选择的配置管理解决方案(例如 saltstack、Puppet、Chef等),但它们各有优劣,而Ansible的特点在于它的简洁。让 Ansible 在主流的配置管理系统中与众不同的一点便是,它并不需要你在想要配置的每个节点上安装自己的组件。同时提供的另一个优点,如果需要的话,你可以在不止一个地方控制你的整个基础架构。
2. 工作原理
-
1、在ANSIBLE 管理体系中,存在"管理节点" 和 “被管理节点” 两种角色。
-
2、被管理节点通常被称为"资产"
-
3、在管理节点上,Ansible将 AdHoc 或 PlayBook 转换为Python脚本。
并通过SSH将这些Python 脚本传递到被管理服务器上。
在被管理服务器上依次执行,并实时的将结果返回给管理节点。
3. 如何安装
先决条件
管理节点
- 确保存在OpenSSH
- 确保Python 版本 >= 2.6
- 确保安装ansible
被管理节点
- 确保存在OpenSSH
- 确保Python 版本 >= 2.4 //若为2.4 版本,确保安装了python-samplesjson 扩展
- 不需要安装ansible
安装Ansible
- yun安装
[root@lwq.com ~]# yum install epel-release
[root@lwq.com ~]# yum install ansible
- pip安装
这里是使用系统自带的 python2 的环境
如果系统中安装的 pip ,可以直接使用 pip 安装 ansible
[root@lwq.com ~]# yum install epel-release
[root@lwq.com ~]# yum install python2-pip
[root@lwq.com ~]# pip install ansible
- 查看版本
[root@lwq.com ~]# ansible --version
ansible 2.9.6
config file = /etc/ansible/ansible.cfg
configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/site-packages/ansible
executable location = /usr/bin/ansible
python version = 2.7.5 (default, Aug 7 2019, 00:51:29) [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)]