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

Parameter validation logic in ecs_task does not work as intended #401

Closed
mjmayer opened this issue Feb 9, 2021 · 2 comments · Fixed by #402
Closed

Parameter validation logic in ecs_task does not work as intended #401

mjmayer opened this issue Feb 9, 2021 · 2 comments · Fixed by #402
Labels
bug This issue/PR relates to a bug has_pr module module needs_triage plugins plugin (any type) python3 traceback

Comments

@mjmayer
Copy link
Contributor

mjmayer commented Feb 9, 2021

SUMMARY

ecs_task attempts to validate parameters using an and statement.

For example:

if 'task_definition' not in module.params and module.params['task_definition'] is None:
    module.fail_json(msg="To stop a task, a task definition must be specified")

This will not evaluate to true even if task_definition not provided because module.params['task_definiton'] = None by default. Which means the condition 'task_definition' not in module.params is always false.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

ecs_task

ANSIBLE VERSION
ansible 2.10.3
  config file = None
  configured module search path = ['/home/mjmayer/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mjmayer/.local/lib/python3.8/site-packages/ansible
  executable location = /home/mjmayer/.local/bin/ansible
  python version = 3.8.6 (default, Sep 25 2020, 09:36:53) [GCC 10.2.0]
CONFIGURATION

OS / ENVIRONMENT

N/A

STEPS TO REPRODUCE
    - name: stop running tasks
      ecs_task:
        operation: stop
        cluster: "{{ cluster_name }}"
        task: "{{ ecs_task }}"
        aws_access_key: "{{ aws_key }}"
        aws_secret_key: "{{ aws_secret }}"
        region: "{{ region }}"
EXPECTED RESULTS

Error indicatin that the task_definition parameter is missing.

ACTUAL RESULTS
The full traceback is:
Traceback (most recent call last):
  File "/home/mjmayer/.ansible/tmp/ansible-tmp-1612908699.9970727-2470578-69922562765386/AnsiballZ_ecs_task.py", line 249, in <module>
    _ansiballz_main()
  File "/home/mjmayer/.ansible/tmp/ansible-tmp-1612908699.9970727-2470578-69922562765386/AnsiballZ_ecs_task.py", line 239, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/mjmayer/.ansible/tmp/ansible-tmp-1612908699.9970727-2470578-69922562765386/AnsiballZ_ecs_task.py", line 110, in invoke_module
    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.ecs_task', init_globals=None, run_name='__main__', alter_sys=True)
  File "/usr/lib/python3.8/runpy.py", line 207, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/usr/lib/python3.8/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/tmp/ansible_ecs_task_payload_1abc2nbk/ansible_ecs_task_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_task.py", line 443, in <module>
  File "/tmp/ansible_ecs_task_payload_1abc2nbk/ansible_ecs_task_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_task.py", line 390, in main
  File "/tmp/ansible_ecs_task_payload_1abc2nbk/ansible_ecs_task_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_task.py", line 251, in list_tasks
  File "/home/mjmayer/.local/lib/python3.8/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/mjmayer/.local/lib/python3.8/site-packages/botocore/client.py", line 648, in _make_api_call
    request_dict = self._convert_to_request_dict(
  File "/home/mjmayer/.local/lib/python3.8/site-packages/botocore/client.py", line 696, in _convert_to_request_dict
    request_dict = self._serializer.serialize_to_request(
  File "/home/mjmayer/.local/lib/python3.8/site-packages/botocore/validate.py", line 297, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Invalid type for parameter family, value: None, type: <class 'NoneType'>, valid types: <class 'str'>
failed: [localhost] (item=arn:aws:ecs:us-west-2:989838493125:task/ait-ecs_cluster-np/b7fa41f566ed47a895035b9536bc88a7) => {
    "ansible_loop_var": "item",
    "changed": false,
    "item": "arn:aws:ecs:us-west-2:989838493125:task/ait-ecs_cluster-np/b7fa41f566ed47a895035b9536bc88a7",
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/mjmayer/.ansible/tmp/ansible-tmp-1612908699.9970727-2470578-69922562765386/AnsiballZ_ecs_task.py\", line 249, in <module>\n    _ansiballz_main()\n  File \"/home/mjmayer/.ansible/tmp/ansible-tmp-1612908699.9970727-2470578-69922562765386/AnsiballZ_ecs_task.py\", line 239, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/mjmayer/.ansible/tmp/ansible-tmp-1612908699.9970727-2470578-69922562765386/AnsiballZ_ecs_task.py\", line 110, in invoke_module\n    runpy.run_module(mod_name='ansible_collections.community.aws.plugins.modules.ecs_task', init_globals=None, run_name='__main__', alter_sys=True)\n  File \"/usr/lib/python3.8/runpy.py\", line 207, in run_module\n    return _run_module_code(code, init_globals, run_name, mod_spec)\n  File \"/usr/lib/python3.8/runpy.py\", line 97, in _run_module_code\n    _run_code(code, mod_globals, init_globals,\n  File \"/usr/lib/python3.8/runpy.py\", line 87, in _run_code\n    exec(code, run_globals)\n  File \"/tmp/ansible_ecs_task_payload_1abc2nbk/ansible_ecs_task_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_task.py\", line 443, in <module>\n  File \"/tmp/ansible_ecs_task_payload_1abc2nbk/ansible_ecs_task_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_task.py\", line 390, in main\n  File \"/tmp/ansible_ecs_task_payload_1abc2nbk/ansible_ecs_task_payload.zip/ansible_collections/community/aws/plugins/modules/ecs_task.py\", line 251, in list_tasks\n  File \"/home/mjmayer/.local/lib/python3.8/site-packages/botocore/client.py\", line 357, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n  File \"/home/mjmayer/.local/lib/python3.8/site-packages/botocore/client.py\", line 648, in _make_api_call\n    request_dict = self._convert_to_request_dict(\n  File \"/home/mjmayer/.local/lib/python3.8/site-packages/botocore/client.py\", line 696, in _convert_to_request_dict\n    request_dict = self._serializer.serialize_to_request(\n  File \"/home/mjmayer/.local/lib/python3.8/site-packages/botocore/validate.py\", line 297, in serialize_to_request\n    raise ParamValidationError(report=report.generate_report())\nbotocore.exceptions.ParamValidationError: Parameter validation failed:\nInvalid type for parameter family, value: None, type: <class 'NoneType'>, valid types: <class 'str'>\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}
@ansibullbot
Copy link

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug has_pr module module needs_triage plugins plugin (any type) python3 traceback labels Feb 9, 2021
alinabuzachis pushed a commit to alinabuzachis/community.aws that referenced this issue May 25, 2022
Add template for a CI issue

SUMMARY
As suggested by @goneri
ISSUE TYPE

Feature Pull Request

COMPONENT NAME
.github/
ADDITIONAL INFORMATION

Reviewed-by: Alina Buzachis <None>
Reviewed-by: Gonéri Le Bouder <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue/PR relates to a bug has_pr module module needs_triage plugins plugin (any type) python3 traceback
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants