
    Vh                        d dl mZ dZdZdZd dlmc mZ d dl	m
Z d dlmZmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZ  G d de      Zd Zd Z G d de      Zy)    )annotationsaJ  
    name: config
    author: Ansible Core Team
    version_added: "2.5"
    short_description: Display the 'resolved' Ansible option values.
    description:
      - Retrieves the value of an Ansible configuration setting, resolving all sources, from defaults, ansible.cfg, environment,
        CLI, and variables, but not keywords.
      - The values returned assume the context of the current host or C(inventory_hostname).
      - You can use C(ansible-config list) to see the global available settings, add C(-t all) to also show plugin options.
    options:
      _terms:
        description: The option(s) to look up.
        required: True
      on_missing:
        description: Action to take if term is missing from config
        default: error
        type: string
        choices:
            error: Issue an error message and raise fatal signal
            warn:  Issue a warning message and continue
            skip:  Silently ignore
      plugin_type:
        description: The type of the plugin referenced by 'plugin_name' option.
        choices: ['become', 'cache', 'callback', 'cliconf', 'connection', 'httpapi', 'inventory', 'lookup', 'netconf', 'shell', 'vars']
        type: string
        version_added: '2.12'
      plugin_name:
        description: The name of the plugin for which you want to retrieve configuration settings.
        type: string
        version_added: '2.12'
      show_origin:
        description: Set this to return what configuration subsystem the value came from
                     (defaults, config file, environment, CLI, or variables).
        type: bool
        version_added: '2.16'
    notes:
      - Be aware that currently this lookup cannot take keywords nor delegation into account,
        so for options that support keywords or are affected by delegation, it is at best a good guess or approximation.
a  
    - name: Show configured default become user
      ansible.builtin.debug: msg="{{ lookup('ansible.builtin.config', 'DEFAULT_BECOME_USER')}}"

    - name: print out role paths
      ansible.builtin.debug:
        msg: "These are the configured role paths: {{lookup('ansible.builtin.config', 'DEFAULT_ROLES_PATH')}}"

    - name: find retry files, skip if missing that key
      ansible.builtin.find:
        paths: "{{lookup('ansible.builtin.config', 'RETRY_FILES_SAVE_PATH')|default(playbook_dir, True)}}"
        patterns: "*.retry"

    - name: see the colors
      ansible.builtin.debug: msg="{{item}}"
      loop: "{{lookup('ansible.builtin.config', 'COLOR_OK', 'COLOR_CHANGED', 'COLOR_SKIP', wantlist=True)}}"

    - name: skip if bad value in var
      ansible.builtin.debug: msg="{{ lookup('ansible.builtin.config', config_in_var, on_missing='skip')}}"
      var:
        config_in_var: UNKNOWN

    - name: show remote user and port for ssh connection
      ansible.builtin.debug: msg={{q("ansible.builtin.config", "remote_user", "port", plugin_type="connection", plugin_name="ssh", on_missing='skip')}}

    - name: show remote_tmp setting for shell (sh) plugin
      ansible.builtin.debug: msg={{q("ansible.builtin.config", "remote_tmp", plugin_type="shell", plugin_name="sh")}}
z
_raw:
  description:
    - A list of value(s) of the key(s) in the config if show_origin is false (default)
    - Optionally, a list of 2 element lists (value, origin) if show_origin is true
  type: raw
N)	constants)AnsibleErrorAnsibleLookupErrorAnsibleOptionsError)	to_native)string_types)
LookupBase)Sentinelc                      e Zd Zy)MissingSettingN)__name__
__module____qualname__     M/home/dcms/DCMS/lib/python3.12/site-packages/ansible/plugins/lookup/config.pyr   r   ]   s    r   r   c                P   	 t        t        d|z        }|j                  | d      }|t        d|d| d      t        j
                  j                  |||j                  |      \  }}||fS # t        $ r  t        $ r#}t        |      }	d|	v rt        |	|	      |d }~ww xY w)
Nz	%s_loaderT)
class_onlyzUnable to load z	 plugin "")plugin_typeplugin_name	variableszwas not definedorig_exc)getattrplugin_loadergetr   Cconfigget_config_value_and_origin
_load_namer   r   r   )
pnameptyper    r   loaderpresultoriginemsgs
             r   _get_plugin_configr+   a   s    e(;<JJuJ.9$u%UVV==fRWefeqeq  ~G=  H 6>   l# q11	s   A*A0 0B%B  B%c                    	 t        t        |       }t        |      rt        d| z        	 |S # t        $ r}t        t        |      |      d }~ww xY w)NzInvalid setting "%s" attemptedr   )r   r   callabler   AttributeErrorr   r   )r    r'   r)   s      r   _get_global_configr/   t   s[    7F#F$%E%NOO 
 M  7Yq\A667s   ). 	AAAc                      e Zd ZddZy)LookupModuleNc           	        | j                  ||       | j                  d      }| j                  d      }| j                  d      }| j                  d      }|s|r|r|st        d      t        |t              r|dvrt        d|z        g }|D ]  }	t        |	t              st        d	|	d
t        |	            t        }
d }	 |rt        |||	|      \  }
}nt        |	      }
|
t        us^|r|j                  |
|f       t|j                  |
        |S # t        $ rI}|dk(  rt        d|	z  |      |dk(  r| j                  j                  d|	z         n|dk(  r	 Y d }~d }~ww xY w)N)var_optionsdirect
on_missingr   r   show_originzOBoth plugin_type and plugin_name are required, cannot use one without the other)errorwarnskipzJ"on_missing" must be a string and one of "error", "warn" or "skip", not %szInvalid setting identifier, "z" is not a string, its a r7   zUnable to find setting %sr   r8   z!Skipping, did not find setting %sr9   )set_options
get_optionr   
isinstancer	   typer   r+   r/   r   r   _displaywarningappend)selftermsr   kwargsmissingr$   r#   r6   rettermr'   r(   r)   s                r   runzLookupModule.run   sx   Yv>//,/..oom4UUu%&wxx'<0GC\4\%&ru|&|}} 	'DdL1)jnptuypz*{||FF%7udI%VNFF/5F X%JJ/0JJv&/	'0 
 " g%,-H4-OZ[\\&MM))*MPT*TU&s   D	E,#?E''E,)N)r   r   r   rG   r   r   r   r1   r1      s    )r   r1   )
__future__r   DOCUMENTATIONEXAMPLESRETURNansible.plugins.loaderpluginsr%   r   ansibler   r   ansible.errorsr   r   r   +ansible.module_utils.common.text.convertersr   ansible.module_utils.sixr	   ansible.plugins.lookupr
   ansible.utils.sentinelr   r   r+   r/   r1   r   r   r   <module>rT      s`    #'R:
 / . " P P A 1 - +	( 	&+: +r   