ansible inventory 主机清单

Inventory支持对主机进行分组,每个组内可以定义多个主机,每个主机都可以定义在任何一个或多个主机组内。

如果是名称类似的主机,可以使用列表的方式标识各个主机。

vim /etc/ansible/hosts

webservers

192.168.80.11:2222 #冒号后定义远程连接端口,默认是 ssh 的 22 端口

192.168.80.1[2:5] #[ ]中指定连续的范围

dbservers

db-[a:f].example.org #支持匹配 a~f

inventory 中的变量

Inventory变量名 含义

ansible_host ansible连接节点时的IP地址

ansible_port 连接对方的端口号,ssh连接时默认为22

ansible_user 连接对方主机时使用的用户名。不指定时,将使用执行ansible或ansible-playbook命令的用户

ansible_password 连接时的用户的ssh密码,仅在未使用密钥对验证的情况下有效

ansible_ssh_private_key_file 指定密钥认证ssh连接时的私钥文件

ansible_ssh_common_args 提供给ssh、sftp、scp命令的额外参数

ansible_become 允许进行权限提升

ansible_become_method 指定提升权限的方式,例如可使用sudo/su/runas等方式

ansible_become_user 提升为哪个用户的权限,默认提升为root

ansible_become_password 提升为指定用户权限时的密码

1)主机变量(横向表示)

webservers

192.168.20.11 ansible_port=22 ansible_user=root ansible_password=abc1234

(2)组变量(纵向表示)

webservers:vars\] #表示为 webservers 组内所有主机定义变量 ansible_user=root ansible_password=abc1234 \[all:vars\] #表示为所有组内的所有主机定义变量 ansible_port=22 (3)组嵌套 \[nginx

192.168.20.20

192.168.20.21

192.168.20.22

apache

192.168.20.3[0:3]

webs:children\] #表示为 webs 主机组中包含了 nginx 组和 apache 组内的所有主机 nginx apache

相关推荐
Full Stack Developme1 小时前
Linux 多种压缩格式,优缺点和适用场景
linux·运维·服务器
旖旎夜光1 小时前
Linux(4)(下)
linux·学习
TG:@yunlaoda360 云老大5 小时前
华为云国际站代理商GeminiDB的企业级高可用具体是如何实现的?
服务器·网络·数据库·华为云
Shanxun Liao5 小时前
Cenots 7.9 配置多台 SSH 互信登陆免密码
linux·运维·ssh
j_xxx404_5 小时前
Linux:第一个程序--进度条|区分回车与换行|行缓冲区|进度条代码两个版本|代码测试与优化
linux·运维·服务器
looking_for__6 小时前
【Linux】Ext系列文件系统
linux
OliverH-yishuihan7 小时前
开发linux项目-在 Windows 上 基于“适用于 Linux 的 Windows 子系统(WSL)”
linux·c++·windows
南棱笑笑生8 小时前
20251224给飞凌OK3588-C开发板适配Rockchip原厂的Buildroot【linux-6.1】系统时确认ssh服务【内置dropbear】
linux·c语言·ssh·rockchip
I · T · LUCKYBOOM8 小时前
30.Firewalld-Linux
linux·运维·安全
沙滩小绵羊8 小时前
Linux常见命令
linux·运维·服务器