【Ubuntu18.04】ansible的安装
ansible配置图
主机名称 | 操作系统 | IP地址 |
Ansible管理端 | Ubuntu18.04 | 192.168.1.13 |
Ansible被管理端 | Ubuntu18.04 | 192.168.1.14 |
Ansible被管理端 | Ubuntu18.04 | 192.168.1.15 |
Ansible被管理端 | Ubuntu18.04 | 192.168.1.16 |
什么是ansible
ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。
ansible是基于 paramiko 开发的,并且基于模块化工作,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。ansible不需要在远程主机上安装client/agents,因为它们是基于ssh来和远
程主机通讯的。ansible目前已经已经被红帽官方收购,是自动化运维工具中大家认可度最高的,并且上手容易,学习简单。是每位运维工程师必须掌握的技能之一。
ansible管理端安装
apt update
apt install software-properties-common
apt-add-repository --yes --update ppa:ansible/ansible
apt install ansible
查看ansible版本
ansible --version
公钥批量分发至Ansible被管理端服务器
ssh-keygen (管理端生成)
公钥分发
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected]
写文件
vim /etc/ansible/hosts
[ALL]
192.168.1.14
192.168.1.15
192.168.1.16
查看是否连通
ansible all -a "hostname"
ansible ALL -m ping