ansible.builtin.getent (v2.9.7) — module

A wrapper to the unix getent utility

| "added in version" 1.8 of ansible.builtin"

Authors: Brian Coca (@bcoca)

stableinterface | supported by core

Install Ansible via pip

Install with pip install ansible==2.9.7

Description

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

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# get root user info
- getent:
    database: passwd
    key: root
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- debug:
    var: getent_passwd
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# get all groups
- getent:
    database: group
    split: ':'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- debug:
    var: getent_group
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# get all hosts, split by tab
- getent:
    database: hosts
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- debug:
    var: getent_hosts
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# get http service info, no error if missing
- getent:
    database: services
    key: http
    fail_key: False
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- debug:
    var: getent_services
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# get user password hash (requires sudo/root)
- getent:
    database: shadow
    key: www-data
    split: ':'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
- debug:
    var: getent_shadow

Inputs

    
key:
    default: ''
    description:
    - Key from which to return values from the specified database, otherwise the full
      contents are returned.

split:
    description:
    - "Character used to split the database values into lists/arrays such as ':' or '\t\
      ', otherwise  it will try to pick one depending on the database."

service:
    description:
    - Override all databases with the specified service
    - The underlying system must support the service flag which is not always available.
    version_added: '2.9'
    version_added_collection: ansible.builtin

database:
    description:
    - The name of a getent database supported by the target system (passwd, group, hosts,
      etc).
    required: true

fail_key:
    default: 'yes'
    description:
    - If a supplied key is missing this will make the task fail if C(yes).
    type: bool