Ansible 使用基础 ( 一 )
安装
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm -y # 安装epel扩展源
dnf install ansible # dnf安装ansible
ansible --version # 校验安装
使用 sshpass 批量实现基于 key 验证:
ssh-keygen #生成公私钥
ssh-copy-id x.x.x.x #每台被控主机都需要公私钥交互
ps:在 root 下操作,便于之后的实验使用
修改 Ansible 中 hosts 文件,配置管理主机【/etc/ansible/hosts】
在 hosts 文件末尾处添加管理主机组和主机 IP 地址: 使用 [xxxx] 描述组名,x.x.x.x 描述主机 IP 地址,例:
[web]
192.168.162.222
192.168.162.220
使用 Ansbile 中 Ping 模块测试 ssh 验证是否成功:
使用命令 ansible all -m ping ;ps: ansible xxxx【管理主机】 -m xxxx【模块名】 -a xxxx【参数】
192.168.162.222 | SUCCESS => {
"ansible_facts": {
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": false,
"ping": "pong"
} # 成功
作用 |
实例 |
所有主机 |
all |
所有主机 |
* |
并集 |
dev:staging |
交集 |
|