首页 > 解决方案 > Ansible ec2_vpc_route_table 剧本错误是:“dict object”没有属性子网

问题描述

我为以前的承包商继承了一个以前工作的 Ansible,我收到一条错误消息,它不会引导我朝着正确的方向前进。我已经尝试搜索了几天,没有任何乐趣,我的同事也无法弄清楚。

有问题的 Ansible 是:-

- name: Routes | Set up NAT-protected route table
  ec2_vpc_route_table:
    vpc_id: "{{ ec2_vpc_net_reg.vpc.id }}"
    region: "{{ vpc_region }}"
    tags:
      Name: "Internal {{ item.subnet_id }}"
    subnets:
      - "{{ az_to_private_sub[public_subnets_to_az[item.subnet_id]] }}"
      - "{{ az_to_private_data_sub[public_subnets_to_az[item.subnet_id]] }}"
    routes:
      - dest: 0.0.0.0/0
        gateway_id: "{{ item.nat_gateway_id }}"
  loop: "{{ existing_nat_gateways.result|flatten(levels=1) }}"
  #with_items: "{{ existing_nat_gateways.result }}"
  register: nat_route_table
  retry: 2
  delay: 10

错误信息是:-

fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute u'subnet-0facefaceface9'\n\nThe error appears to have been in '/cup/core-kubernetes-linux/ansible/roles/aws_vpc/tasks/routes.yml': line 62, column 3, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n- name: Routes | Set up NAT-protected route table\n  ^ here\n"}

我尝试为 az_to_private_sub 和 public_subnet_to_az 添加额外的调试,这些看起来不错。我试过阅读文档

谁能建议我接下来应该看哪里?

谢谢!

标签: amazon-web-servicesansible

解决方案


After speaking to a different colleague, they pointed out that the version which works uses Ansible 2.5.5 and I was trying with 2.5.1 also the boto python libraries need to be using the correct version.


推荐阅读