ansible.builtin.getent 模块 – unix getent 实用程序的包装器
注意
此模块是 ansible-core
的一部分,包含在所有 Ansible 安装中。在大多数情况下,即使不指定 collections 关键字,也可以使用简短的模块名称 getent
。但是,我们建议您使用 完全限定的集合名称 (FQCN) ansible.builtin.getent
,以便轻松链接到模块文档并避免与可能具有相同模块名称的其他集合冲突。
概要
针对其各种数据库之一运行 getent,并将信息返回到主机的 facts 中,使用
getent_<database>
前缀变量。
参数
参数 |
注释 |
---|---|
目标系统支持的 getent 数据库的名称 (passwd、group、hosts 等)。 |
|
如果提供的键缺失,则如果 选项
|
|
从中返回指定数据库值的键,否则返回完整内容。 |
|
使用指定的 service 覆盖所有数据库 底层系统必须支持 service 标志,但这并不总是可用的。 |
|
用于将数据库值拆分为列表/数组的字符,例如 |
属性
备注
注意
并非所有数据库都支持枚举,请查看系统文档了解详细信息。
示例
- name: Get root user info
ansible.builtin.getent:
database: passwd
key: root
- ansible.builtin.debug:
var: ansible_facts.getent_passwd
- name: Get all groups
ansible.builtin.getent:
database: group
split: ':'
- ansible.builtin.debug:
var: ansible_facts.getent_group
- name: Get all hosts, split by tab
ansible.builtin.getent:
database: hosts
- ansible.builtin.debug:
var: ansible_facts.getent_hosts
- name: Get http service info, no error if missing
ansible.builtin.getent:
database: services
key: http
fail_key: False
- ansible.builtin.debug:
var: ansible_facts.getent_services
- name: Get user password hash (requires sudo/root)
ansible.builtin.getent:
database: shadow
key: www-data
split: ':'
- ansible.builtin.debug:
var: ansible_facts.getent_shadow
返回的事实
此模块返回的事实将添加到/更新 hostvars
主机 facts 中,并且可以像任何其他主机 facts 一样按名称引用。它们不需要注册即可使用。
键 |
描述 |
---|---|
结果列表或单个结果,作为数据库提供的字段列表 列表元素取决于查询的数据库,请参阅 getent 手册页以了解结构 从 2.11 开始,它现在返回多个重复条目,以前它只返回最后一个条目 返回:始终 |