Python 无法解决阻塞和救援中的错误
我已经用ansible编写了一个代码,其中包含了用于错误处理的block和rescue方法。我在块中给出了when条件,所以当它满足时,它将导入我在块中编写的剧本 对于when条件下的值,我给出了它下面的_项。对齐,一切都好。但是我在这些项目上遇到了错误。下面是我写的任务部分 任务:Python 无法解决阻塞和救援中的错误,python,ansible,Python,Ansible,我已经用ansible编写了一个代码,其中包含了用于错误处理的block和rescue方法。我在块中给出了when条件,所以当它满足时,它将导入我在块中编写的剧本 对于when条件下的值,我给出了它下面的_项。对齐,一切都好。但是我在这些项目上遇到了错误。下面是我写的任务部分 任务: - name: including the user_list include_vars: Users.yml no_log: 'yes' - name: user validating u
- 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
我得到的错误是:
错误with_items'不是播放的有效属性。根据确切的语法问题,它可能位于文件的其他位置。
在Ansible中不可能在块上循环。我认为您试图实现的是import\u 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:
- ....