getent¶
Collection Note
This module is part of the ansible.builtin collection. To install the collection, use:
Added in version1.8.
Synopsis¶
- Runs getent against one of its various databases and returns information into the host's facts, in a C(getent_
) prefixed variable.
Parameters¶
| Parameter | Defaults / Choices | Comments |
|---|---|---|
| database str required |
The name of a getent database supported by the target system (passwd, group, hosts, etc). | |
| fail_key bool |
Default: yes |
If a supplied key is missing this will make the task fail if V(true). |
| key str |
Key from which to return values from the specified database, otherwise the full contents are returned. | |
| service str |
Override all databases with the specified service The underlying system must support the service flag which is not always available. Version Added: 2.9 |
|
| split str |
Character used to split the database values into lists/arrays such as V(:) or V(\\t), otherwise it will try to pick one depending on the database. |
Notes¶
Note
- Not all databases support enumeration, check system documentation for details.
Examples¶
- 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
Return Values¶
| Key | Data Type | Description | Returned |
|---|---|---|---|
| ansible_facts | dict | Facts to add to ansible_facts. | always |
Authors¶
- Brian Coca (@bcoca)