o nnhA@sddlmZddlmZddlZddlZddlmZddlm Z ddl m Z ddl mZmZddlmZmZmZdd lmZdd lmZdd lmZmZeZGd d d eZdddZedkreedSdS)) annotations)CLIN) constants)context)option_helpers) AnsibleErrorAnsibleOptionsError)to_bytes to_nativeto_text) combine_vars)Display)get_vars_from_inventory_sourcesget_vars_from_pathcseZdZdZdZddiZfddZfddZfd d Zfd d Z e d dZ ddZ ddZ ddZe ddZe ddZe ddZe d(ddZd(ddZd d!Zd"d#Zd$d%Zd&d'ZZS)) InventoryCLIzE used to display or dump the configured inventory as Ansible sees it zansible-inventorygroupAThe name of a group in the inventory, relevant when using --graphcs&tt||d|_d|_d|_dSN)superr__init__vmloader inventory)selfargs __class__@/usr/local/lib/python3.10/dist-packages/ansible/cli/inventory.pyr#s zInventoryCLI.__init__cs8tt|jdddt|jt|jt|jt|j|jj dt j tj d|jj dddd d |j d d }|j d ddddd|j dddddd|j dddddd|j ||jj ddddddd|jj ddddd d|jj d!ddd"d#d|jj d$dtjd%d&d|jj d'dd(d)d*dS)+Nzusage: %prog [options] [group]zWShow Ansible inventory information, by default it uses the inventory script JSON format)usagedescz --list-hosts)helpactionrr?r)metavarnargsr!Actionsz6One of following must be used on invocation, ONLY ONE!z--list store_trueFlistz0Output all hosts info, works as inventory script)r"defaultdestr!z--hoststorehostzJOutput specific host info, works as inventory script. It will ignore limitz--graphgraphz`create inventory graph, if supplying pattern it must be a valid group name. It will ignore limitz-yz--yamlyamlz szEInventoryCLI.json_inventory..format_group..rbrr1r) rrbrrupdateaddrrQrr)rrrasubgroup format_group seen_groupsrrrrs"       z1InventoryCLI.json_inventory..format_groupcs|]}|jVqdSrrrrrr 2z.InventoryCLI.json_inventory..r_meta)setrrRr frozensetrT)rrdrbrar,hvarsrrrrZs  zInventoryCLI.json_inventorycsDttfddtddj|jD}||S)Ncs4i}i||j<i||jd<|jD]-}|jdkr>|jvr+||jd|jiiq||jd|||jqi||jd<|jdkrt|jD]%}|j|vrVqNi}|jvri|jj|d}|||jd|j<qNtjdr|}|r|||jd< ||j||js||j=|S)NrrCrbrLr1r) rrrrrbrTrrQrr)rrrarrrcgvarsrr seen_hostsrrrrBs8              z1InventoryCLI.yaml_inventory..format_groupcsrrrrrrrrjrz.InventoryCLI.yaml_inventory..)rrrrRr)rrdrrrrrX=s ( zInventoryCLI.yaml_inventorycs`ttttdd|jDfddtddj|jD}||}|S)Ncss |] }|jdkr|jVqdS) ungroupedN)rrb)rgrrrrpsz.InventoryCLI.toml_inventory..c s4i}i||j<g||jd<|jD]"}|jdkrsq|jdkr+||jd|j|||q|jdkrx|jD];}|j|vrDq<|jvrV|jj|d}ni}z |||jd|j<Wq<tyw|j|i||jd<Yq.format_groupcsrrrrrrrrr)rboolnextrrrrRr)rrdrrarrrrYms$ zInventoryCLI.toml_inventory)r)__name__ __module__ __qualname____doc__r ARGUMENTSrr3rDrO staticmethodrUrrTrWrrrrrrVrZrXrY __classcell__rrrrrs4   ) 2       %0rcCst|dSr)r cli_executor)rrrrmainsr__main__r) __future__r ansible.clirr_r;ansiblerr?ransible.cli.argumentsrr4ansible.errorsrr+ansible.module_utils.common.text.convertersr r r ansible.utils.varsr ansible.utils.displayr ansible.vars.pluginsrrrFrrrrrrrs*