Server IP : 85.214.239.14 / Your IP : 3.147.54.100 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/2/root/proc/3/root/usr/lib/python3/dist-packages/ansible/plugins/lookup/ |
Upload File : |
# (c) 2013, Bradley Young <young.bradley@gmail.com> # (c) 2012-17 Ansible Project # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import (absolute_import, division, print_function) __metaclass__ = type DOCUMENTATION = """ name: together author: Bradley Young (!UNKNOWN) <young.bradley@gmail.com> 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 """ EXAMPLES = """ - 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] """ RETURN = """ _list: description: synchronized list type: list elements: list """ import itertools from ansible.errors import AnsibleError from ansible.plugins.lookup import LookupBase from ansible.utils.listify import listify_lookup_plugin_terms class LookupModule(LookupBase): """ 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] """ def _lookup_variables(self, terms): results = [] for x in terms: intermediate = listify_lookup_plugin_terms(x, templar=self._templar) results.append(intermediate) return results def run(self, terms, variables=None, **kwargs): terms = self._lookup_variables(terms) my_list = terms[:] if len(my_list) == 0: raise AnsibleError("with_together requires at least one element in each list") return [self._flatten(x) for x in itertools.zip_longest(*my_list, fillvalue=None)]