How to store command output into array in Ansible?

前端 未结 3 594
长情又很酷
长情又很酷 2020-12-31 21:51

Essentially, I want to be able to handle \"wildcard filenames\" in Linux using ansible. In essence, this means using the ls command with part of a filename followed by an \

3条回答
  •  别那么骄傲
    2020-12-31 22:55

    annoying.stdout_lines is already a list.

    From doc of stdout_lines

    When stdout is returned, Ansible always provides a list of strings, each containing one item per line from the original output.

    To assign the list to another variable do:

        ..
          register: annoying
        - set_fact:
            varName: "{{annoying.stdout_lines}}"
        # print first element on the list
        - debug: msg="{{varName | first}}"
    

提交回复
热议问题