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

A wrapper to the unix getent utility

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

Authors: Brian Coca (@bcoca)

Install Ansible via pip

Install with pip install ansible-core==2.16.5

Description

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

Usage examples

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

Inputs

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

split:
    description:
    - 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.
    type: str

service:
    description:
    - Override all databases with the specified service
    - The underlying system must support the service flag which is not always available.
    type: str
    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
    type: str

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

Outputs

ansible_facts:
  contains:
    getent_<database>:
      description:
      - A list of results or a single result as a list of the fields the db provides
      - The list elements depend on the database queried, see getent man page for
        the structure
      - Starting at 2.11 it now returns multiple duplicate entries, previouslly it
        only returned the last one
      returned: always
      type: list
  description: Facts to add to ansible_facts.
  returned: always
  type: dict