Ansible community.aws.ecs_taskdefinition fails with `AttributeError: 'str' object has no attribute 'get'`

464 views Asked by At

I have the following Ansible setup with default configs:

ansible 2.10.3  config file = None
  configured module search path = ['/Users/kagarlickij/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/Cellar/ansible/2.10.3_1/libexec/lib/python3.9/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 3.9.0 (default, Nov 30 2020, 15:22:45) [Clang 12.0.0 (clang-1200.0.32.27)]

However I managed to reproduce issue with Python 3.6 and 2.7 in Docker

My Ansible role is the following:

---

- name: Create task definition
  ecs_taskdefinition:
    family: nginx
    containers:
    - name: nginx
      essential: true
      image: "nginx"
      environment:
        - name: "PORT"
          value: "8080"
    launch_type: FARGATE
    cpu: 512
    memory: 1GB
    state: present
    network_mode: awsvpc

..it's taken from "official" module's example - https://docs.ansible.com/ansible/latest/collections/community/aws/ecs_taskdefinition_module.html#examples

The problem is that execution ansible-playbook --connection=local ./ansible/prowler-fargate.yml

..fails with error: An exception occurred during task execution. To see the full traceback, use -vvv. The error was: AttributeError: 'str' object has no attribute 'get'

-vvv output:

<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /Users/kagarlickij/.ansible/tmp/ansible-tmp-1607191378.7803059-92712-125949682076654/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/Users/kagarlickij/.ansible/tmp/ansible-tmp-1607191378.7803059-92712-125949682076654/AnsiballZ_ecs_taskdefinition.py", line 102, in <module>
    _ansiballz_main()
  File "/Users/kagarlickij/.ansible/tmp/ansible-tmp-1607191378.7803059-92712-125949682076654/AnsiballZ_ecs_taskdefinition.py", line 94, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/Users/kagarlickij/.ansible/tmp/ansible-tmp-1607191378.7803059-92712-125949682076654/AnsiballZ_ecs_taskdefinition.py", line 40, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.ecs_taskdefinition', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/local/Cellar/[email protected]/3.9.0_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 210, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/local/Cellar/[email protected]/3.9.0_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/local/Cellar/[email protected]/3.9.0_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/var/folders/bz/pqkg_1bj7tz6q3hr6s1tzkvh0000gn/T/ansible_ecs_taskdefinition_payload_to2ropfx/ansible_ecs_taskdefinition_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_taskdefinition.py", line 517, in <module>
  File "/var/folders/bz/pqkg_1bj7tz6q3hr6s1tzkvh0000gn/T/ansible_ecs_taskdefinition_payload_to2ropfx/ansible_ecs_taskdefinition_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_taskdefinition.py", line 353, in main
AttributeError: 'str' object has no attribute 'get'
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/Users/kagarlickij/.ansible/tmp/ansible-tmp-1607191378.7803059-92712-125949682076654/AnsiballZ_ecs_taskdefinition.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/Users/kagarlickij/.ansible/tmp/ansible-tmp-1607191378.7803059-92712-125949682076654/AnsiballZ_ecs_taskdefinition.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/Users/kagarlickij/.ansible/tmp/ansible-tmp-1607191378.7803059-92712-125949682076654/AnsiballZ_ecs_taskdefinition.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.ecs_taskdefinition', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/local/Cellar/[email protected]/3.9.0_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 210, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/local/Cellar/[email protected]/3.9.0_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/local/Cellar/[email protected]/3.9.0_3/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/var/folders/bz/pqkg_1bj7tz6q3hr6s1tzkvh0000gn/T/ansible_ecs_taskdefinition_payload_to2ropfx/ansible_ecs_taskdefinition_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_taskdefinition.py\", line 517, in <module>\n  File \"/var/folders/bz/pqkg_1bj7tz6q3hr6s1tzkvh0000gn/T/ansible_ecs_taskdefinition_payload_to2ropfx/ansible_ecs_taskdefinition_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_taskdefinition.py\", line 353, in main\nAttributeError: 'str' object has no attribute 'get'\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

Code is fine - it's fully functional when executed on Jenkins server, just cant make it work on my mac and any Docker container

Nearby module is working fine with the following code:

---

- name: RUN a task on Fargate
  ecs_task:
    aws_access_key: "{{ aws_access_key }}"
    aws_secret_key: "{{ aws_secret_key }}"
    region: "{{ aws_region }}"
    operation: run
    cluster: "{{ cluster_name }}"
    task_definition: "{{ task_definition_name }}"
    count: 1
    started_by: ansible_user
    launch_type: FARGATE
    network_configuration:
      subnets:
      - "{{ subnet_id }}"
      security_groups:
      - "{{ security_group_id }}"
  register: task_output

Any ideas why that issue is happening and how to get rid of it?

0

There are 0 answers