我已经用代码块和救援方法编写了一个错误处理代码。我在块中给出了when条件,因此当它满足时,它将导入我在Block内编写的剧本。
对于条件条件下的值,我在下面给出了with_items.alignment和一切都很好。但是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.
答案 0 :(得分:1)
在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:
- ....