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

相关推荐
一个人旅程~6 小时前
linuxmint如何使用iphone手机上网以及如何管理iphone手机的照片和文件?需要下载哪些基础包和依赖?
linux·windows·经验分享·电脑
异步的告白6 小时前
链接脚本SECTIONS逐行深度解析
linux·开发语言
南境十里·墨染春水7 小时前
linux学习进展 信号
linux·服务器·学习
SiYuanFeng7 小时前
一展使用gpt-5-mini和gemini-3.1-flash-image-preview-0.5k的运行demo代码
linux·python·gpt
YuanDaima20487 小时前
堆(优先队列)基础原理与题目说明
linux·运维·服务器·人工智能·python··代码
another heaven7 小时前
【软考 对称加密与非对称加密】
服务器·网络
生万千欢喜心7 小时前
linux 安装 人大金仓数据库
linux·运维·数据库
傻啦嘿哟7 小时前
Python多进程编程:用multiprocessing突破GIL限制
服务器·网络·数据库
@insist1237 小时前
网络工程师-网络规划与设计(三):数据中心机房设计规范全解析
服务器·网络·数据库·网络工程师·软考·软件水平考试
mounter6257 小时前
深度拦截:Linux 内核引入 Firmware LSM 挂钩,eBPF 再下一城!
linux·服务器·ebpf·kernel·firmware