ansible inventory 主机清单

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

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

vim /etc/ansible/hosts

webservers

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

192.168.80.12: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.30:3

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

nginx

apache

相关推荐
Sokach10154 分钟前
Linux Shell 脚本从零到能用:一个新手的一天学习总结
linux
AlfredZhao16 小时前
Docker 容器时区不对,`timedatectl` 不存在怎么办?
linux·timezone
zzzzzz3102 天前
9K Star 炸裂开源!这个 C 语言写的代码知识图谱,把 Linux 内核索引压缩到了 3 分钟
linux·服务器·sql
XIAOHEZIcode2 天前
Linux系统鼠标偏移常见原因以及修复方案
linux·运维·游戏
A小辣椒4 天前
TShark:Wireshark CLI 功能
linux
A小辣椒4 天前
TShark:基础知识
linux
AlfredZhao4 天前
OCI 明明分配了 200G 系统盘,为什么 df 只看到 30G?
linux·oci
AlfredZhao5 天前
vi 删除指定范围的行,不用再反复按 dd
linux·vi
用户9718356334665 天前
银河麒麟 KY10 申威(SW64) 安装 nginx-1.16.1-2.p01.ky10.sw_64.rpm 详细步骤
linux
猪脚踏浪5 天前
linux 拷贝文件或目录到指定的位置
linux