o nnh@s|ddlmZdZdZddlZddlmZddlmZm Z ddl m Z ddl m Z mZdd lmZedZGd d d eZdS) ) annotationsa name: yaml version_added: "2.4" short_description: Uses a specific YAML file as an inventory source. description: - "YAML-based inventory, should start with the C(all) group and contain hosts/vars/children entries." - Host entries can have sub-entries defined, which will be treated as variables. - Vars entries are normal group vars. - "Children are 'child groups', which can also have their own vars/hosts/children and so on." - File MUST have a valid extension, defined in configuration. notes: - If you want to set vars for the C(all) group inside the inventory file, the C(all) group must be the first entry in the file. - Enabled in configuration by default. options: yaml_extensions: description: list of 'valid' extensions for files containing YAML type: list elements: string default: ['.yaml', '.yml', '.json'] env: - name: ANSIBLE_YAML_FILENAME_EXT - name: ANSIBLE_INVENTORY_PLUGIN_EXTS ini: - key: yaml_valid_extensions section: defaults - section: inventory_plugin_yaml key: yaml_valid_extensions a all: # keys must be unique, i.e. only one 'hosts' per group hosts: test1: test2: host_var: value vars: group_all_var: value children: # key order does not matter, indentation does other_group: children: group_x: hosts: test5 # Note that one machine will work without a colon #group_x: # hosts: # test5 # But this won't # test7 # group_y: hosts: test6: # So always use a colon vars: g2_var2: value3 hosts: test4: ansible_host: 127.0.0.1 last_group: hosts: test1 # same host as above, additional group membership vars: group_last_var: value N)MutableMapping) AnsibleErrorAnsibleParserError) string_types) to_nativeto_text)BaseFileInventoryPlugincsJeZdZdZfddZfddZd fdd Zd d Zd d ZZ S)InventoryModuleyamlcstt|dS)N)superr __init__)self __class__I/usr/local/lib/python3.10/dist-packages/ansible/plugins/inventory/yaml.pyr TszInventoryModule.__init__cs>d}tt||rtj|\}}|r||dvrd}|S)NFyaml_extensionsT)r r verify_fileospathsplitext get_option)rrvalid file_nameextrrrrXs zInventoryModule.verify_fileTc stt|||||z |jj|dd}Wnty(}zt|d}~ww|s/tdt|t s must be a string. Enclose integers/floats in quotation marks.)_expand_hostpattern TypeErrorr)rr> hostnamesr?rrrr6s  zInventoryModule._parse_host)T) __name__ __module__ __qualname__NAMEr rrr'r6 __classcell__rrrrr Ps   1r ) __future__r DOCUMENTATIONEXAMPLESrcollections.abcransible.errorsrransible.module_utils.sixr+ansible.module_utils.common.text.convertersrransible.plugins.inventoryr r%r/r rrrrs !