条件检查dict对象'没有属性ansible错误

时间:2017-12-09 05:29:40

标签: python amazon-ec2 ansible jinja2

我有一个在us-east-1中没有问题的剧本,但在aws的ap-southeast-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"

1 个答案:

答案 0 :(得分:1)

实例上显然缺少app_type标记。

P.S。但是我怀疑你的剧本中有一个设计缺陷 - 如果你希望delete.sh脚本出现在标记为app_type ==' platform' ,那么你的电台是错的。