快速安装ansible 简单又快捷
快速安装ansible 简单又快捷
1,安装epel源
yum install -y epel-release
2,安装ansible
yum install ansible -y
3,查看ansible版本
ansible --version
4,展开文件夹
tree /etc/ansible/
/etc/ansible/
├── ansible.cfg #ansible的配置文件
├── hosts #ansible的主仓库,用于存储需要管理的远程主机
└── roles #角色
5,配置主机清单
cd /etc/ansible
vim hosts #配置主机清单
[webservers]
192.168.199.50
[mysql]
192.168.199.60
6,获取密钥对
主机获取密钥对
ssh-keygen -t rsa
将密钥发送给被管理端
[root@ruyi~]#cd .ssh/
[root@ruyi~/.ssh]#ls
id_rsa id_rsa.pub #密钥存放的位置
ssh-copy-id [email protected] #发送到被服务端
ssh-copy-id [email protected]
[root@muzi~]#cd .ssh/
[root@muzi~/.ssh]#ls
authorized_keys #密钥在被服务端存放的位置
扫描二维码关注公众号,回复:
13148018 查看本文章

7,简单查看被服务端的时间
ansible mysql -m command -a 'date'
8,免交互代理
利用ssh设置免交互登录
ssh-agent bash
ssh-add
ansible 192.168.199.50 -m command -a 'date' #查看是否需要验证密钥
验证发现已经不需要密钥就可以登录