ansible - 我尝试在 when 语句中使用“with_items”但失败了
问题描述
- hosts: 22rrvgndns01
gather_facts: no
vars_files:
- /etc/ansible/dnschange/dns_resource_record.yml
tasks:
- shell: grep "{{item.name}}" check_result.txt
args:
chdir: /cluster/dnschange
when: "{{item.action}}" is match("delete")
with_items: "{{resource_record}}"
这是资源记录:
- resource_record:
- name: test.201.apn.epc.mnc002.mcc505.3gppnetwork.org
record_type: naptr
action: create
view: MME
ttl: 300
order: 100
preference: 999
flags: s
service: x-3gpp-pgw:x-gn:x-gp:x-s5-gtp
replacement: wip-ows-pgw-e-NSW.node.epc.mnc002.mcc505.3gppnetwork.org
执行脚本时出现错误
违规行似乎是:
chdir: /cluster/dnschange
when: "{{item.action}}" is match("delete")
^ here
我可能是错的,但这看起来可能是缺少引号的问题。当它们开始一个值时,总是引用模板表达式括号。例如:
with_items:
- {{ foo }}
应该写成:
with_items:
- "{{ foo }}"
谁能帮我吗?
解决方案
我猜你的缩进是错误的,并且在什么情况下会改变。你可以尝试如下
- shell: grep "{{item.name}}" check_result.txt
args:
chdir: /cluster/dnschange
when: item.action == 'delete'
with_items: "{{resource_record}}"
推荐阅读
- javascript - 使用 AJV 针对 JSON 模式的 API 验证响应期间的错误输出
- amazon-web-services - Amazon CodeCommit 凭证帮助程序 - 找不到命令
- javascript - 等价于 image/png;base64 用于 excel 文件流
- reactjs - 如何使用 Spring MVC 和 React 作为前端服务器?
- visual-c++ - VS 编译器是否提供了一个宏变量来判断浮点模型是否精确?
- sql - 使用循环的sql过程打印错误结果
- dialogflow-es - agent.add(conv) 在 dialogflow-fulfillment-library 中不起作用?
- swift - 为什么这个函数没有返回任何东西?
- php - 如何在同一页面中使用 html 和 php 在下拉的选择更改事件的输入字段中从数据库中获取选定的数据
- arrays - 使用 mongodb 的 java 驱动程序从集合中获取数组字段