与_项注册的Ansible变量,如何使用此变量?
我有这样一个场景,我需要使用两个文件与_项注册的Ansible变量,如何使用此变量?,ansible,ansible-2.x,Ansible,Ansible 2.x,我有这样一个场景,我需要使用两个文件a.bin,B.bin,首先查看文件目录,如果找不到,直接从服务器下载 - name: Send A.bin and B.bin copy: src={{item}}.bin dest=/opt/ register: is_exist failed_when: False with_items: - A - B - name: Download from a server A.bin, B.bin shell: wget
a.bin,B.bin
,首先查看文件
目录,如果找不到,直接从服务器下载
- name: Send A.bin and B.bin
copy: src={{item}}.bin dest=/opt/
register: is_exist
failed_when: False
with_items:
- A
- B
- name: Download from a server A.bin, B.bin
shell: wget -P /opt/{{item.item}} {{base_url}}{{item.item}}.bin
when: item.item.exception is defined
with_items:
- is_exist.results
但这会产生一个错误:
The conditional check 'item.item.exception is defined' failed. The error was: error while evaluating conditional (item.item.exception is defined): 'ansible.utils.unsafe_proxy.AnsibleUnsafeText object' has no attribute 'item'
我该怎么办?我建议目视检查
is\u exist
变量的结构
- debug: msg="{{ is_exist }}"
然后,如果item.item.exception
是预期的变量名,则在测试其异常
键之前,始终检查item.item
是否定义为避免没有属性“item”
:
when: item.item is defined and item.item.exception is defined