Ansible Playbook error - Dict object has no attribute.

4,025 views
Skip to first unread message

Kishore Ponniah

unread,
Oct 22, 2018, 8:17:31 AM10/22/18
to Ansible Project
Hi, 

I am trying to create a Direct connect Gateway in AWS account using ansible. I have the main playbook and an account config yaml template. When I run the playbook I am getting an error 

fatal: [infrastructure]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'stacks'\n\nThe error appears to have been in '/home/ec2-user/environment/aws-rxgt-mgmt-platform/ansible/rxgt-ps-rxgtmgmt-playbook.yaml': line 10, column 5, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n  tasks:\n  - name: create rxgt-ps-mgmt-direct-connect-gateway stack\n    ^ here\n"}

I have attached the code for reference and error. can someone please help?


Thanks

Kishore Ponniah

unread,
Oct 22, 2018, 8:20:20 AM10/22/18
to Ansible Project
main playbook code

---
# This playbook builds Network infrastructure in all configured accounts
- name: Install/Update RXGT Mgmt account CF templates
hosts: infrastructure
tasks:

- name: Install/Update RXGT PS cross account CF templates
hosts: infrastructure
tasks:
- name: create rxgt-ps-mgmt-direct-connect-gateway stack
aws_direct_connect_gateway:
state: present
region: ""
aws_access_key: ""
aws_secret_key: ""
security_token: ""
template_parameters: "{{ rxgt_mgmt_account.account_config.stacks['rxgt-ps-mgmt-direct-connect-gateway'].params }}"
tags: "{{ global_tags | combine(rxgt_mgmt_account.account_config.stacks['rxgt-ps-mgmt-direct-connect-gateway'].override_tags, recursive=True) }}"
register: created_aws_direct_connect_gateway
tags:
rxgt-ps-mgmt-dxgw-deploy

- name: debug stack outputs
vars:
msg: "{{ account_config | to_nice_yaml }}"
debug:
msg: "{{ msg.split('\n') }}"
verbosity: 0
tags:
- 'never'
- 'debug'
- rxgt-ps-mgmt-dxgw-deploy

account_config code:

---
ansible_python_interpreter: "{{ lookup('env', 'VIRTUAL_ENV') }}/bin/python"
rxgt_mgmt_account:
deploy_accounts:
- xxxxxx

account_config:
xxxxxx:
id: xxxxxx
account_alias: xxxxxx
sts_role_arn: arn:aws:iam::xxxxxxxxxxx:role/xxxxx/xx/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
pass_role_arn: ""
regions:
- eu-west-1
stacks:
rxgt-ps-mgmt-direct-connect-gateway:
params:
name: mgmt-dxgw
amazon_asn: 65000
override_tags:
rx:billing:service-name: identity
rx:billing:environment-name: xxxxxxx

Vladimir Botka

unread,
Oct 22, 2018, 9:32:27 AM10/22/18
to Ansible Project

The indentation is wrong (line 10, column 5). Should be:

    tasks:

Kishore Ponniah

unread,
Oct 22, 2018, 9:37:27 AM10/22/18
to Ansible Project
I have corrected that. I am concerned if line 17 is correct

Thanks

Adrian Sebastian Dutu

unread,
Oct 22, 2018, 9:37:50 AM10/22/18
to Ansible Project
I think the indentation appears wrong just in the preview. I downloaded the file and the indentation is fine on line 10.
It seems this line is the issue: combine(rxgt_mgmt_account.account_config.stacks['rxgt-ps-mgmt-direct-connect-gateway'].override_tags, recursive=True) }}"
It says that dictionary has no key named stacks. Maybe try just printing that dict or do -vvv to see what keys that it actually has.

Kishore Ponniah

unread,
Oct 22, 2018, 11:09:37 AM10/22/18
to Ansible Project
I did -vvv and I don't see anything different. Same error and it gathered the facts. Not sure if my debug stack task is correct. 

Tony Chia

unread,
Oct 22, 2018, 12:06:42 PM10/22/18
to Ansible Project
It seems there is one level between account_config and stack.
Maybe try account_config.xxxxxx.stacks instead?

Kishore Ponniah

unread,
Oct 22, 2018, 1:38:03 PM10/22/18
to Ansible Project
ok, I used the below 

      template_parameters: "{{ rxgt_mgmt_account.account_config.rxgtmgmt.stacks['rxgt-ps-mgmt-direct-connect-gateway'].params }}"
      tags: "{{ global_tags | combine(rxgt_mgmt_account.account_config.rxgtmgmt.stacks['rxgt-ps-mgmt-direct-connect-gateway'].override_tags, recursive=True) }}"

TASK [create rxgt-ps-mgmt-direct-connect-gateway stack] ************************************************************************************************************
fatal: [infrastructure]: FAILED! => {"msg": "|combine expects dictionaries, got Undefined"}
        to retry, use: --limit @/home/ec2-user/.ansible-retry/site.retry

Kishore Ponniah

unread,
Oct 22, 2018, 2:04:18 PM10/22/18
to Ansible Project
I managed to sort out, there is no parameter called "template_parameter"

  - name: create rxgt-ps-mgmt-direct-connect-gateway stack
    aws_direct_connect_gateway:
      state: present
      region: ""
      aws_access_key: ""
      aws_secret_key: ""
      security_token: ""
      name: "{{ rxgt_mgmt_account.account_config.rxgtmgmt.stacks['rxgt-ps-mgmt-direct-connect-gateway'].params.name }}"
      amazon_asn: "{{ rxgt_mgmt_account.account_config.rxgtmgmt.stacks['rxgt-ps-mgmt-direct-connect-gateway'].params.amazon_asn }}"
    register: created_aws_direct_connect_gateway
    tags:
      rxgt-ps-mgmt-dxgw-deploy
Reply all
Reply to author
Forward
0 new messages