
    Vh                         d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ d dlmZ 	 d dlZd	Z G d de      Zy# e$ rZd
ZY dZ[dZ[ww xY w)    )absolute_importdivisionprint_functiona  
author: Unknown (!UNKNOWN)
name: chef_databag
short_description: fetches data from a Chef Databag
description:
  - 'This is a lookup plugin to provide access to chef data bags using the pychef package. It interfaces with the chef server
    API using the same methods to find a knife or chef-client config file to load parameters from, starting from either the
    given base path or the current working directory. The lookup order mirrors the one from Chef, all folders in the base
    path are walked back looking for the following configuration file in order: C(.chef/knife.rb), C(~/.chef/knife.rb), C(/etc/chef/client.rb).'
requirements:
  - "pychef (L(Python library, https://pychef.readthedocs.io), C(pip install pychef))"
options:
  name:
    description:
      - Name of the databag.
    type: string
    required: true
  item:
    description:
      - Item to fetch.
    type: string
    required: true
z}
- ansible.builtin.debug:
    msg: "{{ lookup('community.general.chef_databag', 'name=data_bag_name item=data_bag_item') }}"
zV
_raw:
  description:
    - The value from the databag.
  type: list
  elements: dict
)AnsibleError)
LookupBase)parse_kvNTFc                   2     e Zd ZdZd fd	Zd ZddZ xZS )LookupModulez%
    Chef data bag lookup module
    c                 L    t        t        | 
  ||fi | d | _        d | _        y N)superr
   __init__nameitem)selfloadertemplarkwargs	__class__s       q/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/lookup/chef_databag.pyr   zLookupModule.__init__=   s)    lD*67EfE 		    c           	          dD ]0  }	 |j                  |d      }|t        |      }t        | ||       2 |r%t	        dt        |j                                     y# t        $ r t	        d| d d      w xY w)z1
        parse key-value style arguments
        )r   r   Nzcan't parse arg =z
 as stringz)unrecognized arguments to with_sequence: )popstrsetattr
ValueErrorr   listkeys)r   argsargarg_rawparseds        r   parse_kv_argszLookupModule.parse_kv_argsE   s    
 $ 
	C	((3-?Wc6*
	 ;D<M;PQ  	  "&se1WIZ@ s   AAA:c                 `   t         st        d      |D ]  }| j                  t        |              t	        j
                         }t        |t        j                  j                        st        d      t	        j                  | j                        }|| j                     }t        |      gS )Nz9PyChef needed for lookup plugin, try `pip install pychef`z%Unable to connect to Chef Server API.)HAS_CHEFr   r$   r   chefautoconfigure
isinstanceapiChefAPIDataBagr   r   dict)r   terms	variablesr   term
api_objectdata_bag_objectdata_bag_items           r   runzLookupModule.runZ   s    Z[[ 	/Dx~.	/ '')
*dhh&6&67FGG,,tyy1'		2]#$$r   )NNr   )__name__
__module____qualname____doc__r   r$   r4   __classcell__)r   s   @r   r
   r
   9   s    *%r   r
   )
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURNansible.errorsr   ansible.plugins.lookupr   ansible.parsing.splitterr   r'   r&   ImportErrormissing_moduler
    r   r   <module>rF      sc    C B0

 ( - -H
2%: 2%	  Hs   8 A	AA	