簡體   English   中英

stdout_lines中的Ansible搜索字符串,以后將用戶作為變量

[英]Ansible search string in stdout_lines and user later as variable

我在stdout_lines中有下面的ansible輸出

    "test.stdout_lines": [
        "Get VM Power State Script",
        "Loading vmware.vimautomation.core",
        "",
        "Attempting to connect to server1. Please wait.",
        "",
        "Connected to server1",
        "\tGathering VM Info...",
        "",
        "Attempting to connect to serevr2. Please wait.",
        "",
        "Connected to server2.",
        "\tGathering VM Info...",
        "File Exported to D:\\Scripts\\Exports\\VM_State_201907151824.csv . Please verify the content",
        "",
        "Complete."

我想將文件位置存儲在輸出的最后一行作為變量,即位置:-D:\\ Scripts \\ Exports \\ VM_State_201907151824.csv。 如何做呢?

這對您有用嗎?

{{ test.stdout_lines | join(' ') | regex_replace( '^.*File Exported to (.*) \. Please .*$', '\\1') }}

試試下面

- name: Get the file_path
  set_fact:
    file_path: "{{ test.stdout_lines | select('match', 'File Exported to.+') | list | regex_replace( '^.*File Exported to (.*) \\. Please .*$', '\\1') }}"
- name: debug
  debug:
    msg: "{{ file_path }}"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM