ansible - 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"}
知道为什么它不起作用吗?或者也许我应该使用不同的解决方案?
解决方案
好的,我找到了答案:
- name: "Sample"
set_fact:
find_variable: "{{ search_01 | string | regex_findall(item) }}"
when: 'item in (search_01 | string)'
with_items: "{{ search_02 }}"
推荐阅读
- maven - maven-surefire-plugin 在 gitlab-ci 上使用 OpenJDK 17 失败
- angular - 带有 Nginx 的 AWS 负载均衡器背后的 Angular:拒绝的 MIME 类型
- snowflake-cloud-data-platform - 一周第一天的值
- node.js - 持久化通过渲染发送到 Pug 模板的数据
- r - 从 sum() 和 '+' 获得不同的结果
- iphone - Xcode 13 中的 Interface Builder 缺少 iPhone 模拟器
- kotlin - 检查用户是否已经使用 Kotlin 使用 google 帐户登录会导致空指针异常
- javascript - javascript中的数组赋值问题
- python - 编写包时应该如何避免重复导入?
- java - 如何获得地图
> 来自 Java 8 中的流