首页 > 解决方案 > regex_findall 中的 with_items 问题

问题描述

我是论坛的新手,如果我描述错误,我真的很抱歉。

我不知道如何在正则表达式中使用 itam:

这是变量 search_01 的输出

ok: [sample_host] => {

    "msg": [
        "text 01 \n",
        "text 02 \n",
        "text 03 \n",
        "text 04 \n""
    ]

这是变量 search_02 的输出

ok: [sample_host] => {

    "msg": [
        "10"
        "03"
        "08"
    ]

这是我的代码

 - name: "Sample"
   set_fact:    
     find_variable: "{{ search_01 | regex_findall(item) }}"
   with_items: "{{ search_02 }}"

输出:

TASK [Sample TASK] ****************************************************************************************************************************
fatal: [sample_host]: FAILED! => {"msg": "Unexpected templating type error occurred on ({{ search_01 | regex_findall(item) }}): expected string or buffer"}

知道为什么它不起作用吗?或者也许我应该使用不同的解决方案?

标签: ansible

解决方案


好的,我找到了答案:

  - name: "Sample"
    set_fact:
      find_variable: "{{ search_01 | string | regex_findall(item) }}"
    when: 'item in (search_01 | string)'
    with_items: "{{ search_02 }}"


推荐阅读