o nnh@sXddlmZdZdZdZddlZddlmZddlm Z ddl m Z Gd d d e Z dS) ) annotationsa name: lines author: Daniel Hokka Zakrisson (!UNKNOWN) version_added: "0.9" short_description: read lines from command description: - Run one or more commands and split the output into lines, returning them as a list options: _terms: description: command(s) to run required: True notes: - Like all lookups, this runs on the Ansible controller and is unaffected by other keywords such as 'become'. If you need to use different permissions, you must change the command or run Ansible as another user. - Alternatively, you can use a shell/command task that runs against localhost and registers the result. - The directory of the play is used as the current working directory. a - name: We could read the file directly, but this shows output from command ansible.builtin.debug: msg="{{ item }} is an output line from running cat on /etc/motd" with_lines: cat /etc/motd - name: More useful example of looping over a command result ansible.builtin.shell: "/usr/bin/frobnicate {{ item }}" with_lines: - "/usr/bin/frobnications_per_host --param {{ inventory_hostname }}" za _list: description: - lines of stdout from command type: list elements: str N) AnsibleError) LookupBaseto_textc@seZdZddZdS) LookupModulec Kspg}|D]1}tj||jdtjtjd}|\}}|jdkr-|dd|Dqt d||jf|S)NT)cwdshellstdinstdoutrcSsg|]}t|qSr).0lr r G/usr/local/lib/python3.10/dist-packages/ansible/plugins/lookup/lines.py ;sz$LookupModule.run..z#lookup_plugin.lines(%s) returned %d) subprocessPopen_loader get_basedirPIPE communicate returncodeextend splitlinesr) selfterms variableskwargsrettermpr stderrr r rrun4s  zLookupModule.runN)__name__ __module__ __qualname__r"r r r rr2s r) __future__r DOCUMENTATIONEXAMPLESRETURNransible.errorsransible.plugins.lookupr+ansible.module_utils.common.text.convertersrrr r r rs