I am trying to understand the error message “ERROR! ‘unicode object’ has no attribute ‘subnets’”
As shown as an example at https://docs.ansible.com/ansible/ec2_vpc_subnet_facts_module.html
My Code:
— # EC2 VPC
- hosts: localhost
vars:
aws_access_key: “{{ aws.aws_access_key }}”
aws_secret_key: “{{ aws.aws_secret_key }}”
cidr_block: 10.250.0.0/24
vpc_name: Testing
region: us-west-2
vpc_id: vpc-b8599ade
connection: local
gather_facts: no
vars_files:
- group_vars/account.yml
tasks:
-
name: Get Subnet Facts
ec2_vpc_subnet_facts:
aws_access_key: “{{ aws_access_key }}”
aws_secret_key: “{{ aws_secret_key }}”
region: “{{ region }}”
filters:
vpc-id: “{{ vpc_id }}”
register: subnet_facts -
set_fact:
subnet_ids: “{{ subnet_facts|map(attribute=‘subnets.0.id’)|list }}”
The results:
steven@playbooks$ ansible-playbook myplay.yml
PLAY ***************************************************************************
TASK [Get Subnet Facts] ********************************************************
ok: [localhost]
TASK [set_fact] ****************************************************************
fatal: [localhost]: FAILED! => {“failed”: true, “msg”: “ERROR! ‘unicode object’ has no attribute ‘subnets’”}
PLAY RECAP *********************************************************************
localhost : ok=1 changed=0 unreachable=0 failed=1