
    Vh                    \    d dl mZ dZdZdZd dlZd dlmZ d dlm	Z	 d Z
ed	k(  r e
        yy)
    )annotationsas  
---
module: getent
short_description: A wrapper to the unix getent utility
description:
     - Runs getent against one of its various databases and returns information into
       the host's facts, in a C(getent_<database>) prefixed variable.
version_added: "1.8"
options:
    database:
        description:
            - The name of a getent database supported by the target system (passwd, group,
              hosts, etc).
        type: str
        required: True
    key:
        description:
            - Key from which to return values from the specified database, otherwise the
              full contents are returned.
        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"
    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
    fail_key:
        description:
            - If a supplied key is missing this will make the task fail if V(true).
        type: bool
        default: 'yes'
extends_documentation_fragment:
  - action_common_attributes
  - action_common_attributes.facts
attributes:
    check_mode:
        support: full
    diff_mode:
        support: none
    facts:
        support: full
    platform:
        platforms: posix
notes:
   - Not all databases support enumeration, check system documentation for details.
author:
- Brian Coca (@bcoca)
aD  
- 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

a  
ansible_facts:
  description: Facts to add to ansible_facts.
  returned: always
  type: dict
  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, previously it only returned the last one
      returned: always
      type: list
N)AnsibleModule)	to_nativec                    t        t        t        dd      t        dd      t        d      t        d      t        dd      	      d
      } g d}| j                  d   }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j                  j                  d      }| j	                  dd      }||||g}n||g}||j                  d|g       |||v rd}	 | j                  |      \  }	}
}d}d|z  }|i i}	dk(  ri }
j                         D ]~  }|j                  |      }|d   |v rN||d      dk(  r||   |d      g||   |d   <   ||   |d      j                  |dd         ||d   xx   dz  cc<   i|dd  ||   |d   <   d||d   <    | j                  |       n4|	dk(  rd}n,|	dk(  r d}|s#d ||   |<   | j                  ||       n|	dk(  rd}| j                  |        y # t        $ r9}| j                  t        |      t        j                                Y d }~:d }~ww xY w)!NstrT)typerequiredF)r   no_log)r   bool)r   default)databasekeyservicesplitfail_key)argument_specsupports_check_mode)passwdshadowgroupgshadowr   r   r   r   r   getentz-s:)msg	exceptionzUnexpected failure!z	getent_%sr      )ansible_factsz'Missing arguments, or database unknown.   z<One or more supplied key could not be found in the database.)r   r      z+Enumeration not supported on this database.)r   )r   dictparamsgetget_bin_pathextendrun_command	Exception	fail_jsonr   	traceback
format_exc
splitlinesr   append	exit_json)modulecolonr   r   r   r   r   
getent_bincmdrcouterrer   dbtreeresultsseenlinerecords                      F/home/dcms/DCMS/lib/python3.12/site-packages/ansible/modules/getent.pymainr;   {   s   ut4%.e$E"vt4
 !	F 5E}}Z(H
--

E
"CMMg&Emm	*G}}  ,H$$Xt4J
8S)8$

D'?#}U*M))#.C  C8#FrlG	QwNN$ 	$DZZ&FayD q	?a'29&/&)2L1MGFOF1I.q	*11&*=VAY1$ .4ABZq	*"#VAY	$ 	w/	q7	qL#'GFOC 7<	q;
I  MYq\Y5I5I5KLLMs   H 	I '.II __main__)
__future__r   DOCUMENTATIONEXAMPLESRETURNr(   ansible.module_utils.basicr   +ansible.module_utils.common.text.convertersr   r;   __name__     r:   <module>rF      sG    #4l%N
  4 AGT zF rE   