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

[stable-5] lookup plugins - raise correct error #1534

Conversation

tremble
Copy link
Contributor

@tremble tremble commented May 9, 2023

SUMMARY

Lookup plugins are currently raising "AnsibleError" this is in turn leading to a surprising error. Our tests didn't catch this because we expected an error (just a clean error) and our error message was still in there.

fixes: #1528

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

aws_ssm

ADDITIONAL INFORMATION
TASK [lookup_aws_ssm : lookup a missing key (error)] ***************************
task path: /root/ansible_collections/amazon/aws/tests/output/.tmp/integration/lookup_aws_ssm-uhhi4kie-ÅÑŚÌβŁÈ/tests/integration/targets/lookup_aws_ssm/tasks/main.yml:43
AWS_ssm name lookup term: ['/ansible-test-32065799-mchappel/Simple']
exception during Jinja2 execution: Traceback (most recent call last):
  File "/root/ansible_collections/amazon/aws/plugins/lookup/aws_ssm.py", line 272, in get_parameter_value
    response = client.get_parameter(**ssm_dict)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/botocore/client.py", line 386, in _api_call
    return self._make_api_call(operation_name, kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/botocore/client.py", line 705, in _make_api_call
    raise error_class(parsed_response, operation_name)
botocore.errorfactory.ParameterNotFound: An error occurred (ParameterNotFound) when calling the GetParameter operation: 

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/ansible/lib/ansible/template/__init__.py", line 831, in _lookup
    ran = instance.run(loop_terms, variables=self._available_variables, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ansible_collections/amazon/aws/plugins/lookup/aws_ssm.py", line 241, in run
    ret.append(self.get_parameter_value(client, ssm_dict, term, on_missing.lower(), on_denied.lower()))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/root/ansible_collections/amazon/aws/plugins/lookup/aws_ssm.py", line 276, in get_parameter_value
    raise AnsibleError("Failed to find SSM parameter %s (ResourceNotFound)" % term)
ansible.errors.AnsibleError: Failed to find SSM parameter /ansible-test-32065799-mchappel/Simple (ResourceNotFound)
fatal: [testhost]: FAILED! => {
    "msg": "An unhandled exception occurred while running the lookup plugin 'amazon.aws.aws_ssm'. Error was a <class 'ansible.errors.AnsibleError'>, original message: Failed to find SSM parameter /ansible-test-32065799-mchappel/Simple (ResourceNotFound). Failed to find SSM parameter /ansible-test-32065799-mchappel/Simple (ResourceNotFound)"
}
...ignoring

Direct to stable-5 as the issue was fixed during the refactor work in main.

@tremble tremble requested a review from alinabuzachis May 9, 2023 08:12
@tremble tremble marked this pull request as ready for review May 9, 2023 08:12
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded.
https://ansible.softwarefactory-project.io/zuul/buildset/40ae9f8a1fd343bba6823cd00728f464

✔️ ansible-galaxy-importer SUCCESS in 4m 35s
✔️ build-ansible-collection SUCCESS in 12m 30s
✔️ ansible-test-splitter SUCCESS in 4m 45s
✔️ integration-amazon.aws-1 SUCCESS in 6m 12s
✔️ integration-amazon.aws-2 SUCCESS in 5m 32s
✔️ integration-amazon.aws-3 SUCCESS in 7m 26s
✔️ integration-amazon.aws-4 SUCCESS in 6m 34s
Skipped 40 jobs

@tremble tremble added the mergeit Merge the PR (SoftwareFactory) label May 9, 2023
@softwarefactory-project-zuul
Copy link
Contributor

Build succeeded (gate pipeline).
https://ansible.softwarefactory-project.io/zuul/buildset/d2438a92b8d040f18e11f7cdfa50b1d9

✔️ ansible-galaxy-importer SUCCESS in 4m 29s
✔️ build-ansible-collection SUCCESS in 13m 06s
✔️ ansible-test-splitter SUCCESS in 4m 48s
✔️ integration-amazon.aws-1 SUCCESS in 5m 35s
✔️ integration-amazon.aws-2 SUCCESS in 5m 39s
✔️ integration-amazon.aws-3 SUCCESS in 5m 40s
✔️ integration-amazon.aws-4 SUCCESS in 6m 57s
Skipped 40 jobs

@softwarefactory-project-zuul softwarefactory-project-zuul bot merged commit 234a776 into ansible-collections:stable-5 May 9, 2023
@tremble tremble deleted the lookup/errors branch September 27, 2023 07:00
abikouo pushed a commit to abikouo/amazon.aws that referenced this pull request Oct 24, 2023
* fix pip command
* fix formal name of fqcn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mergeit Merge the PR (SoftwareFactory)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants