Inventory 清单文件
Inventory 清单文件是一个描述主机和组的 Ansible 文件,INI 格式。Inventory 清单文件有两种类型:
- Static Inventory:手动编写。
- External Inventory Script:通过 Inventory Script 提供,常见在公有云部署场景。
Inventory 清单文件中主要有两个概念:
- [Group]:在系统级别进行分类,便于对不同的系统进行区别管理。
- Host:实际的一台托管节点,用 hostname 或 IP address 来表示。
Inventory 清单文件描述了这些 Groups 和 Hosts 之间的关系,并且 Groups 和 Hosts 之前是完全解耦的关系。例如:
mail.example.com
[webservers]
foo.example.com
bar.example.com
[dbservers]
one.example.com
two.example.com
three.example.com
嵌套 Groups
[atlanta]
host1
host2
[raleigh]
host2
host3
[southeast:children]
atlanta
raleigh
Hostname 通配符
生产场景中,通常大量 Hosts 的 hostname 仅仅是 index 不同,此时可以考虑使用 Hostname 通配符。
db-[1:100]-node.example.com
# or
db-[a:f].example.com
Inventory 清单文件的参数说明
- ansible_ssh_host:指示托管节点的 SSH Hostname。
- ansible_ssh_port:指示托管节点的 SSH Port。
- ansible_ssh_user:指示托管节点的 SSH Username。
- ansible_ssh_pass:指示托管节点的 SSH Password(明文密码不安全,推荐使用 Public Key 认证)。
- ansible_sudo_pass:指示托管节点的 SSH Sudo User 的 Password(明文密码不安全,推荐使用 Public Key 认证)。
- ansible_sudo_exe:指示托管节点的 sudo CLI Path(new in version 1.8)。
- ansible_connection:远程连接类型,枚举:local、ssh、paramiko。其中,local(Local Connection)表示我们正在管理的事本地主机而不是远端机器。
- ansible_ssh_private_key_file:指示管理节点 SSH 免密登陆托管节点的私钥文件路径。
- ansible_shell_type:指示托管节点的 Shell 类型,枚举:sh、csh、fish。
- ansible_python_interpreter:指示托管节点的 Python 解析器的路径(e.g. /usr/bin/python),适用于系统中存在多个 Python 版本的情况。