python - 无法解决阻塞和救援中的错误
问题描述
我已经用块和救援方法编写了一个用于错误处理的代码。我已经给出了块中的条件,所以当它满足时它会导入我在块中编写的剧本。
并且对于 when 条件下的值,我在它下面给出了 with_items。对齐,一切都很好。但我在 with_items 上遇到了错误。下面是我写的任务部分
任务:
- name: including the user_list
include_vars: Users.yml
no_log: 'yes'
- name: user validating using block
block:
- import_playbook: CIname.yml
when: '"{{ CI_name }}" == item.ci_name and "{{ username }}" == item.username'
with_items: "{{ user_list }}"
rescue:
- name: Update the work notes of the incident when block fails
always:
- name: Post the status back to ServiceNow
我刚开始的错误是:
ERROR! 'with_items' is not a valid attribute for a Play be elsewhere in the file depending on the exact syntax problem.
解决方案
在 Ansible 中循环块是不可能的。我认为您要实现的是import_playbook
模块上的循环,应该可以这样:
- name: user validating using block
block:
- import_playbook: CIname.yml
when: CI_name == item.ci_name and username == item.username
with_items: "{{ user_list }}"
rescue:
- ....
always:
- ....
推荐阅读
- java - 图片 url 更改后 RecyclerView 上的图片未更新
- android - 最佳图像压缩库
- python - 与 pandas read_csv() 相比,加载 1 000 000+ 行的 1 列更有效的方法是什么?
- regex - 从名称字段中提取首字母,在每个首字母之后添加句点
- javascript - javascript中是否有可能在没有加号的情况下增加变量?
- python-2.7 - AWS IAM Python 脚本 - 将新用户添加到现有组
- regex - 正则表达式:选择最后一个下划线和点之间的所有文本
- php - 当我通过 DatabaseSeeder 调用它时找不到 Laravel Seeder 类
- c# - 为返回多个表的存储过程创建强类型数据集
- java - 我如何从其他类中获取方法结果?