o nnh>@sXddlmZdZdZdZddlZddlmZddlm Z ddl m Z Gd d d e Z dS) ) annotationsaT name: together author: Bradley Young (!UNKNOWN) version_added: '1.3' short_description: merges lists into synchronized list description: - Creates a list with the iterated elements of the supplied lists - "To clarify with an example, [ 'a', 'b' ] and [ 1, 2 ] turn into [ ('a',1), ('b', 2) ]" - This is basically the same as the 'zip_longest' filter and Python function - Any 'unbalanced' elements will be substituted with 'None' options: _terms: description: list of lists to merge required: True z - name: item.0 returns from the 'a' list, item.1 returns from the '1' list ansible.builtin.debug: msg: "{{ item.0 }} and {{ item.1 }}" with_together: - ['a', 'b', 'c', 'd'] - [1, 2, 3, 4] zO _list: description: synchronized list type: list elements: list N) AnsibleError) LookupBase)listify_lookup_plugin_termsc@s"eZdZdZddZdddZdS) LookupModulez Transpose a list of arrays: [1, 2, 3], [4, 5, 6] -> [1, 4], [2, 5], [3, 6] Replace any empty spots in 2nd array with None: [1, 2], [3] -> [1, 3], [2, None] cCs*g}|D]}t||jd}||q|S)N)templar)r_templarappend)selftermsresultsx intermediaterJ/usr/local/lib/python3.10/dist-packages/ansible/plugins/lookup/together.py_lookup_variables4s  zLookupModule._lookup_variablesNc sH|}|dd}t|dkrtdfddtj|ddiDS)Nrz8with_together requires at least one element in each listcsg|]}|qSr)_flatten).0r r rr Csz$LookupModule.run.. fillvalue)rlenr itertools zip_longest)r r variableskwargsmy_listrrrrun;s   zLookupModule.run)N)__name__ __module__ __qualname____doc__rrrrrrr,sr) __future__r DOCUMENTATIONEXAMPLESRETURNransible.errorsransible.plugins.lookupransible.utils.listifyrrrrrrs