Ansible — Inventory 清单文件
发布日期:2021-06-30 10:05:33 浏览次数:3 分类:技术文章

本文共 1335 字,大约阅读时间需要 4 分钟。

目录

文章目录

Inventory 清单文件

Inventory 清单文件是一个描述主机和组的 Ansible 文件,INI 格式。Inventory 清单文件有两种类型:

  1. Static Inventory:手动编写。
  2. External Inventory Script:通过 Inventory Script 提供,常见在公有云部署场景。

Groups 与 Hosts 对象

Inventory 清单文件中主要有两个概念:

  • [Group]:在系统级别进行分类,便于对不同的系统进行区别管理。
  • Host:实际的一台托管节点,用 hostname 或 IP address 来表示。

Inventory 清单文件描述了这些 Groups 和 Hosts 之间的关系,并且 Groups 和 Hosts 之前是完全解耦的关系。例如:

mail.example.com[webservers]foo.example.combar.example.com[dbservers]one.example.comtwo.example.comthree.example.com

嵌套 Groups

[atlanta]host1host2[raleigh]host2host3[southeast:children]atlantaraleigh

Hostname 通配符

生产场景中,通常大量 Hosts 的 hostname 仅仅是 index 不同,此时可以考虑使用 Hostname 通配符。

db-[1:100]-node.example.com# ordb-[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 版本的情况。

转载地址:https://is-cloud.blog.csdn.net/article/details/117886093 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Ansible — Ad-Hoc Commands
下一篇:Ansible — Overview

发表评论

最新留言

哈哈,博客排版真的漂亮呢~
[***.90.31.176]2024年04月29日 01时28分06秒