Ansible介绍
Ansible是2013年推出的一款批量管理工具,基于Python语言开发,2015年被RedHat收购
Ansible基于Paramiko实现SSH协议链接通讯,默认只要被管理节点开启SSH服务,Ansible就可以管理远程主机
使用Ansible不需要在客户端主机(被管理主机)安装Agent
Ansible模块化设计,并且模块丰富,支持自定义模块,自定义模块可用任何语言编写
Ansible基于PyYAML模块支持Playbook,可以通过Playbook完成可重复的复杂工作
Ansible通过 Roles(角色)比Playbook更加强大,适合部署非常负责的环境(搭建OpenStack云平台)
官网:Ansible is Simple IT Automation
批量管理工具:
-
Ansible:基于Python语言开发,轻量级批量管理工具
-
SaltStack:基于Python语言开发 ,C/S架构
-
Puppet:基于Ruby语言开发
-
Chef:基于Ruby语言开发
实验环境准备
主机名 | 角色 |
---|---|
Ansible-server | 管理主机 |
host01 | 被管理主机 |
host02 | 被管理主机 |
-
关闭防火墙与SElinux
[root@ansible-server ~]# systemctl stop firewalld [root@ansible-server ~]# systemctl disable firewalld [root@ansible-server ~]# setenforce 0 [root@ansible-server ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
-
管理节点修改/etc/hosts文件实现本地解析
[root@ansible-server ~]# vim /etc/hosts ... 192.168.0.12 host12 192.168.0.13 host13
-
管理节点与被管理节点实现SSH密钥认证
[root@ansible-server ~]# ssh-keygen
-
传递公钥到被管理节点
[root@ansible-server ~]# for i in host12 host13 do ssh-copy-id $i done
-
验证SSH免密登录
[root@ansible-server ~]# ssh host12 [root@ansible-server ~]# ssh host13
安装Ansible软件包
-
安装ansible软件包,由于ansible需要epel源,本实验配置了阿里的epel源和阿里的Base源(Base源用于安装ansible所需依赖)
[root@ansible-server ~]# yum -y install wget #下载wget工具 [root@ansible-server ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo #下载阿里Base源 [root@ansible-server ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo #下载阿里epel源
-
安装ansible软件包
[root@ansible-server ~]# yum -y install ansible
-
查看ansible版本信息
[root@ansible-server ~]# ansible --version ansible 2.9.17
定义Ansible主机清单
-
ansible主配置文件:/etc/ansible/ansible.cfg
-
ansible默认清单文件:/