Python 条件检查dict对象';没有可解释错误的属性

Python 条件检查dict对象';没有可解释错误的属性,python,amazon-ec2,ansible,jinja2,Python,Amazon Ec2,Ansible,Jinja2,我有一个剧本,在美国东部1号中没有发行,但在aws的ap东南1号中有发行。这是剧本中失败的部分 - hosts: "tag_deployment_group_{{ env }}_{{ app }}" gather_facts: false remote_user: root tasks: - name: "wait for instances to be reachable" wait_for_connection: delay: 60 timeout:

我有一个剧本,在美国东部1号中没有发行,但在aws的ap东南1号中有发行。这是剧本中失败的部分

- hosts: "tag_deployment_group_{{ env }}_{{ app }}"
  gather_facts: false
  remote_user: root
  tasks:
    - name: "wait for instances to be reachable"
  wait_for_connection:
    delay: 60
    timeout: 500
- ec2_remote_facts:
    region: ap-southeast-1
    aws_access_key: "{{ aws_access_key }}"
    aws_secret_key: "{{ aws_secret_key }}"
    filters:
      "tag:Env": "{{ env }}"
  register: instance_facts
- add_host:
    name: "{{ item.tags.Name }}"
    ansible_host: "{{ item.private_ip_address }}"
    group: "{{ env }}_{{app}}"
  with_items: "{{ instance_facts.instances }}"
- name: "copy cron script"
  copy: src=/etc/ansible/files/delete.sh dest=/root/scripts/delete.sh
  when: item.tags.app_type == 'platform'
  with_items: "{{ instance_facts.instances }}"
我得到的错误如下

"failed": true, 
"msg": "The conditional check 'item.tags.app_type == 'platform'' 
failed. The error was: error while evaluating conditional 
(item.tags.app_type == 'platform'): 'dict object' has no attribute 
'app_type'\n\nThe error appears to have been 
ts.yml': line 80, column 7, but may\nbe elsewhere in the file depending 
on the exact syntax problem.\n\nThe offending line appears to be:\n\n      
with_items: \"{{ instance_facts.instances }}\"\n    - name: \"copy cron 
script\"\n      ^ here\n"

显然,实例缺少
app\u type
标记


另外,我怀疑你的剧本中有设计缺陷——如果你希望
delete.sh
脚本出现在带有标签
app\u type
==“platform”的实例上,那么你的剧本就错了。

不太确定,我把它改成“platbook”后,它实际上开始工作了,当时:已定义item.tags.app_类型,并且item.tags.app_类型中的“平台”已定义“```来自您以前的帖子。但是,剧本的意图是在“app\u type==”platform“的情况下复制脚本。请您解释一下。一般来说,您应该在不同的重头戏中运行
add_host
和该主机的任务。请参见“感谢澄清”。我将以这种方式实施