【发布时间】:2025-12-12 09:25:02
【问题描述】:
我有一本在 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"
【问题讨论】:
-
不太确定,请看这里
标签: python amazon-ec2 ansible jinja2