【问题标题】:Loop for ansible arraysansible数组的循环
【发布时间】:2019-06-28 12:50:20
【问题描述】:

我正在使用 ansible 任务注册两个变量,其结果是-

"pathlist": [
        "/dir1/dir2/dir3",
        "/dir1/dir2/dir3/abc.txt",
        "/dir1/dir2/dir3/testme"
    ]

"pathexists": [
        true,
        true,
        false
    ]

我想将输出打印为 -

"/dir1/dir2/dir3" -- true
"/dir1/dir2/dir3/abc.txt" -- true
"/dir1/dir2/dir3/testme" -- false

我正在使用以下代码来打印最终结果- - 设置事实:
输出:“{{ item.0 }} -- {{ item.1 }}\n”
with_nested:
- “{{ 路径列表 }}” - “{{ pathexists }}”

  • 调试:var=输出

我想,我错过了一些东西。任何帮助都会非常有用。

【问题讨论】:

    标签: ansible


    【解决方案1】:

    with_together 就是你要找的东西

     tasks:
       - debug: msg="{{ item.0 }} -- {{ item.1 }}"
         with_together:
           - "{{ pathlist }}"
           - "{{ pathexists }}"
    

    给予:

        "msg": "/dir1/dir2/dir3 -- True"
        "msg": "/dir1/dir2/dir3/abc.txt -- True"
        "msg": "/dir1/dir2/dir3/testme -- False"
    

    【讨论】:

      猜你喜欢
      • 2021-09-14
      • 2021-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-12
      • 1970-01-01
      • 1970-01-01
      • 2018-11-02
      相关资源
      最近更新 更多