一 ansible 安装
- ubuntu: sudo apt-get install ansible
- centos: sudo yum -y install ansible
3. 安装好后验证是否已经安装: ansible --version, 如果出现版本号, 则表示安装正常
二 ansible 批量管理 LINUX(root 用户下):
1. 准备诺干台 LINUX 的虚拟机, 每台分配 256 内存就好, 最小安装, 不要安装 GUI 界面, 因为吃内存
2. 虚拟机的上网方式为 NAT 或者 桥接
3. 配置主机清单 (两种形式):
1. 编辑 sudo vi /etc/ansible/hosts 添加以下内容 (ip 写你虚拟机的 ip):
- [test_linux]
- 192.168.1.123
- 192.168.1.124
- 192.168.1.125
2. cp /etc/ansible/hosts /home / 你的用户目录 / hosts 后, 在 cp 过来的 hosts 文件添加以下内容
- [test_linux]
- 192.168.1.123
- 192.168.1.124
- 192.168.1.125
4. 生成密钥:
1.ssh-keygen 一直回车
2. 密钥分发
sudo ansible 172.16.78.128 -m copy -a "src=/home/root/.ssh/id_rsa.pub dest=/root/.ssh/" -k
来源: http://www.bubuko.com/infodetail-2509140.html