Ansible安装
step1:下载epel源,从epel源中下载ansible
yum -y install epel-release
step2:查看epel中的ansible安装包
yum list |grep ansible
step3:安装并且查看版本
yum -y install ansible
ansible --version
step4:修改ansible配置
默认配置文件:/etc/ansible/ansible.cfg
主机与组定义文件: /etc/ansible/hosts
自定义文件:
/root/ansible/ansible.cfg
[defaults]
inventory = /root/ansible/hosts
host_key_checking = False
/root/ansible/hosts
[web]
yw-19
yw-20 =================基于/etc/hosts文件
连续几台:yw-[11:20]
ansible 主机集合 --list-hosts //列出主机集合中的主机
子组定义:
[app:children]
主机集合1
主机集合2 //app主机集合继承主机集合1和2中的主机
step5:取消ansible管理主机和被管理主机之间的密码验证
ssh-keygen -N '' -f /root/.ssh/id_rsa
ssh-copy-id root@被管理主机ip
ansible 主机组 -m ping [-k ] //测试服务器的通信状态,如果已经免密,则无需-k
-k:ssh密码
-K:sudo密码
普通用户
ansible 主机组 -m ping
vim /root/ansible/hosts
[all:vars]
ansible_ssh_user=mcloud
ansible_ssh_pass=Memoriae20210804!@#.
ansible_sudo_pass=Memoriae20210804!@#.