Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ecs_service load_balancers not working with container port #265

Closed
Lennon95 opened this issue Oct 15, 2020 · 4 comments · Fixed by #286
Closed

ecs_service load_balancers not working with container port #265

Lennon95 opened this issue Oct 15, 2020 · 4 comments · Fixed by #286

Comments

@Lennon95
Copy link

SUMMARY

The ecs_service module doesn't work as expected when a load balancer is defined with a container port.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ecs_service.py

ANSIBLE VERSION
v2.10.1
OS / ENVIRONMENT

Docker inside alpine image.

STEPS TO REPRODUCE

Just execute the following task and it should fail.

- name: "Criando/atualizando serviço {{ service.name }}" 
  community.aws.ecs_service:
    aws_access_key: "{{ ec2_access_key }}"
    aws_secret_key: "{{ ec2_secret_key }}"
    state: present
    force_new_deployment: yes
    name: "{{ service.name }}"
    cluster: "{{ service.cluster }}"
    region: "{{ service.region }}"
    task_definition: "{{ service.task }}"
    desired_count: 1 #service.desired_count
    launch_type: "{{ service.launch_type }}"
    load_balancers:
      - targetGroupArn: "{{ service.alb_arn_tg }}"
        containerName: "{{ service.http_container }}"
        containerPort: 80 
    network_configuration:
      subnets:
      - "{{ service.subnet  }}"
      security_groups:
      - "{{ service.security_group }}"

My var file is here, in case you're wondering:

  name: "Service_Site_Plataforma"
  cluster: "openbox-plataforma"
  region: "us-east-1"
  task: "openbox-plataforma-prod:11"
  desired_count: 1
  launch_type: "FARGATE"
  alb_arn_tg: "arn:aws:elasticloadbalancing:us-east-1:880610698981:targetgroup/ECS-site/5f7722edab69f6a3"
  http_container: "nginx-server"
  http_container_port: 80
  vpc: "vpc-0813fd6181f0580a4" 
  subnet: "subnet-051274368a7c79e66"
  security_group: "sg-08e8273b3b2959ada"
EXPECTED RESULTS

It should work.

ACTUAL RESULTS

It fails with the following error message:

TASK [ecs-services : Criando/atualizando serviço Service_Site_Plataforma] ******

task path: /ansible/roles/ecs-services/tasks/ecs-service.yml:1

<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: root

<127.0.0.1> EXEC /bin/sh -c 'echo ~root && sleep 0'

<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /root/.ansible/tmp `"&& mkdir "` echo /root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260 `" && echo ansible-tmp-1602784189.4565227-171-150065538834260="` echo /root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260 `" ) && sleep 0'

Using module file /root/.ansible/collections/ansible_collections/community/aws/plugins/modules/ecs_service.py

<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-178n3qw9g/tmpg7h1z76m TO /root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/AnsiballZ_ecs_service.py

<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/ /root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/AnsiballZ_ecs_service.py && sleep 0'

<127.0.0.1> EXEC /bin/sh -c '/usr/local/bin/python /root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/AnsiballZ_ecs_service.py && sleep 0'

<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/ > /dev/null 2>&1 && sleep 0'

The full traceback is:

Traceback (most recent call last):

  File "/root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/AnsiballZ_ecs_service.py", line 102, in <module>

    _ansiballz_main()

  File "/root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/AnsiballZ_ecs_service.py", line 94, in _ansiballz_main

    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)

  File "/root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/AnsiballZ_ecs_service.py", line 40, in invoke_module

    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.ecs_service', init_globals=None, run_name='__main__', alter_sys=True)

  File "/usr/local/lib/python3.6/runpy.py", line 205, in run_module

    return _run_module_code(code, init_globals, run_name, mod_spec)

  File "/usr/local/lib/python3.6/runpy.py", line 96, in _run_module_code

    mod_name, mod_spec, pkg_name, script_name)

  File "/usr/local/lib/python3.6/runpy.py", line 85, in _run_code

    exec(code, run_globals)

  File "/tmp/ansible_community.aws.ecs_service_payload_a3wwyvdm/ansible_community.aws.ecs_service_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_service.py", line 860, in <module>

  File "/tmp/ansible_community.aws.ecs_service_payload_a3wwyvdm/ansible_community.aws.ecs_service_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_service.py", line 754, in main

TypeError: string indices must be integers

fatal: [localhost]: FAILED! => {

    "changed": false,

    "module_stderr": "Traceback (most recent call last):\n  File \"/root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/AnsiballZ_ecs_service.py\", line 102, in <module>\n    _ansiballz_main()\n  File \"/root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/AnsiballZ_ecs_service.py\", line 94, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/root/.ansible/tmp/ansible-tmp-1602784189.4565227-171-150065538834260/AnsiballZ_ecs_service.py\", line 40, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.ecs_service', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/local/lib/python3.6/runpy.py\", line 205, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/local/lib/python3.6/runpy.py\", line 96, in _run_module_code\n    mod_name, mod_spec, pkg_name, script_name)\n  File \"/usr/local/lib/python3.6/runpy.py\", line 85, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_community.aws.ecs_service_payload_a3wwyvdm/ansible_community.aws.ecs_service_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_service.py\", line 860, in <module>\n  File \"/tmp/ansible_community.aws.ecs_service_payload_a3wwyvdm/ansible_community.aws.ecs_service_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_service.py\", line 754, in main\nTypeError: string indices must be integers\n",

    "module_stdout": "",

    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",

    "rc": 1

}
@markuman
Copy link
Member

somewhere is a type error

TypeError: string indices must be integers

So somehwere you're refering to a position of an array? But I cannot find it adhoc.
Basically we do the same all day...

    - name: update or create ecs service for
      ecs_service:
        state: present
        region: "{{ region }}"
        name: "{{ SERVICE }}"
        cluster: "{{ CLUSTER }}"
        task_definition: "{{ TASK_NAME }}:{{ output.taskdefinition.revision }}"
        desired_count: "{{ DESIRED_COUNT }}"
        launch_type: EC2
        load_balancers:
           - targetGroupArn: "{{ tg.target_groups[0].target_group_arn }}"
              containerName: website
              containerPort: 80
        deployment_configuration:
          minimum_healthy_percent: 50

@markuman
Copy link
Member

#264

@markuman
Copy link
Member

same error. element type is wrong for load _balancers.

@markuman
Copy link
Member

@Lennon95 as a workaround, you can use community.aws collection 1.0.0. The error was introduced later.

tremble pushed a commit that referenced this issue Nov 12, 2020
* #265 fix element type for load_balancers in ecs_service
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this issue Jul 19, 2021
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this issue Jul 19, 2021
danielcotton pushed a commit to danielcotton/community.aws that referenced this issue Nov 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants