W3cubDocs

/Ansible 2.11

ansible.builtin.getent – A wrapper to the unix getent utility

Note

This module is part of ansible-base and included in all Ansible installations. In most cases, you can use the short module name getent even without specifying the collections: keyword. Despite that, we recommend you use the FQCN for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name.

New in version 1.8: of ansible.builtin

Synopsis

  • Runs getent against one of it’s various databases and returns information into the host’s facts, in a getent_<database> prefixed variable.

Parameters

Parameter Choices/Defaults Comments
database
string / required
The name of a getent database supported by the target system (passwd, group, hosts, etc).
fail_key
boolean
    Choices:
  • no
  • yes
If a supplied key is missing this will make the task fail if yes.
key
string
Default:
""
Key from which to return values from the specified database, otherwise the full contents are returned.
service
string
added in 2.9 of ansible.builtin
Override all databases with the specified service
The underlying system must support the service flag which is not always available.
split
string
Character used to split the database values into lists/arrays such as ':' or ' ', 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
  getent:
    database: passwd
    key: root
- debug:
    var: getent_passwd

- name: Get all groups
  getent:
    database: group
    split: ':'
- debug:
    var: getent_group

- name: Get all hosts, split by tab
  getent:
    database: hosts
- debug:
    var: getent_hosts

- name: Get http service info, no error if missing
  getent:
    database: services
    key: http
    fail_key: False
- debug:
    var: getent_services

- name: Get user password hash (requires sudo/root)
  getent:
    database: shadow
    key: www-data
    split: ':'
- debug:
    var: getent_shadow

Authors

  • Brian Coca (@bcoca)

© 2012–2018 Michael DeHaan
© 2018–2021 Red Hat, Inc.
Licensed under the GNU General Public License version 3.
https://docs.ansible.com/ansible/2.11/collections/ansible/builtin/getent_module.html