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

changing describe_parameters call to use paginator #45632

Merged
merged 2 commits into from Sep 14, 2018
Merged

changing describe_parameters call to use paginator #45632

merged 2 commits into from Sep 14, 2018

Conversation

eisjcormier
Copy link
Contributor

SUMMARY

updated create_update_parameter() to use a paginator for the describe_parameter method when updating an existing parameter. I ran into an issue where the parameter I needed to update was not in the first result set of items returned by: client.get_parameter(Name=args['Name'], WithDecryption=True)

See ADDITIONAL INFORMATION for details

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

aws_ssm_parameter_store

ANSIBLE VERSION
ansible 2.6.4
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/site-packages/ansible
  executable location = /bin/ansible
  python version = 2.7.5 (default, Aug  4 2017, 00:39:18) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)]

ADDITIONAL INFORMATION

I ran into an issue where the parameter I needed to update was not in the first result set of items returned by: client.get_parameter(Name=args['Name'], WithDecryption=True)
I got this error when running my playbook:


Result:
<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/ansible-tmp-1536863695.84-147938161401239 `" && echo ansible-tmp-1536863695.84-147938161401239="` echo /root/.ansible/tmp/ansible-tmp-1536863695.84-147938161401239 `" ) && sleep 0'
Using module file /usr/lib/python2.7/site-packages/ansible/modules/cloud/amazon/aws_ssm_parameter_store.py
<127.0.0.1> PUT /root/.ansible/tmp/ansible-local-30457dmHRd8/tmp_9kYoS TO /root/.ansible/tmp/ansible-tmp-1536863695.84-147938161401239/aws_ssm_parameter_store.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1536863695.84-147938161401239/ /root/.ansible/tmp/ansible-tmp-1536863695.84-147938161401239/aws_ssm_parameter_store.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python2 /root/.ansible/tmp/ansible-tmp-1536863695.84-147938161401239/aws_ssm_parameter_store.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1536863695.84-147938161401239/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_0pStDP/ansible_module_aws_ssm_parameter_store.py", line 253, in <module>
    main()
  File "/tmp/ansible_0pStDP/ansible_module_aws_ssm_parameter_store.py", line 248, in main
    (changed, response) = invocations[state](client, module)
  File "/tmp/ansible_0pStDP/ansible_module_aws_ssm_parameter_store.py", line 192, in create_update_parameter
    if describe_existing_parameter['Parameters'][0]['Description'] != args['Description']:
IndexError: list index out of range

fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/tmp/ansible_0pStDP/ansible_module_aws_ssm_parameter_store.py\", line 253, in <module>\n    main()\n  File \"/tmp/ansible_0pStDP/ansible_module_aws_ssm_parameter_store.py\", line 248, in main\n    (changed, response) = invocations[state](client, module)\n  File \"/tmp/ansible_0pStDP/ansible_module_aws_ssm_parameter_store.py\", line 192, in create_update_parameter\n    if describe_existing_parameter['Parameters'][0]['Description'] != args['Description']:\nIndexError: list index out of range\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE",
    "rc": 1
}

The call to client.get_parameter(Name=args['Name'], WithDecryption=True) was actually returning this:

 {u'NextToken': u'AAEAAYo5rAFED3zqXPRdM2barhRoPEy7XKiKyQseIg/NfpRoAAAAAFuai7PyhJdo0bspyIm/QCuI/KQWErCGt+O7i4bwVHyJXsX+Z0jYMdddl9TpkJwG+vxArVfXLlu+0rfdy14DbLbK8audCg4cJiThDTRdFhQLCHWptaOTIiblxoJnJfd5KT8yfXsFig/dVTcx9T8oYOFXKF6SdlJ4hlvDmzA/cdGUxTuLGqCXAj0OBmDXsH3jVRm57qEVqkWeTbXzWpZNJvQ6rsAK+UQQKJG4UlgNu3j/0iIlWjgRWr4fd3LaNjTmadFPXUW6sWw8o+tLR0j324YmVCg0s/rSo+2iXnSdh0GgPOAZfmVaBUvH2VkmYe+7yESYlUsYc7Bgzhd+BhE0Cj5h5atle5ipSiJa2/mdtwBJigg7lQiQg2tOfsCvzf9gyvpdqrNvdND37xktB6dOxu+tpUeaJDZ+joqGqdEWLTKE1jfA1ajLCjKXiP/gkUMNrZnXXx/++nmL3ohaWXdV0OfXDgzR2YxQSLTFCPhTm6TcPlK5ibhFYeaC8IX+TtsRTxJD8LMDB5lhbxwXNJO0gLm7LkSFsrTKbaiJhELgChQZBx20zX7t8XCm8pn/Zq23L7wigvnl4Ce0dIKMCqiNk7Vqls2U+90QnHK+X08ulPOS2tF4nzJ0MlTaLyYypWDlr0/Ktn/rp+kCHl1vrYOiwRJuqt8t2zrK+J5faOkleVV0Fx3g5Z4XPrpvYmt8ZlNPGE2zXQjk5insxzLFt+C7vj14xcvql4O2iAK5duFoTQE/L4/ZCw==', 'ResponseMetadata': {'RetryAttempts': 0, 'HTTPStatusCode': 200, 'RequestId': 'XXXXXXX', 'HTTPHeaders': {'x-amzn-requestid': 'XXXXXXX', 'date': 'Thu, 13 Sep 2018 16:09:22 GMT', 'content-length': '840', 'content-type': 'application/x-amz-json-1.1'}}, u'Parameters': []})

@ansibot
Copy link
Contributor

ansibot commented Sep 13, 2018

@ansibot
Copy link
Contributor

ansibot commented Sep 13, 2018

Hi @eisjcormier,

Thank you for the pullrequest, just so you are aware we have a dedicated Working Group for aws.
You can find other people interested in this in #ansible-aws on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

@ansibot ansibot added affects_2.8 This issue/PR affects Ansible v2.8 aws bug This issue/PR relates to a bug. cloud community_review In order to be merged, this PR must follow the community review workflow. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. new_contributor This PR is the first contribution by a new community member. small_patch support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. labels Sep 13, 2018
@samdoran samdoran removed the needs_triage Needs a first human triage before being processed. label Sep 13, 2018
@s-hertel
Copy link
Contributor

It's very strange that the parameters are an empty list for the first page!

@eisjcormier
Copy link
Contributor Author

Hi Sloane,
According to the boto3 docs: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ssm.html#SSM.Client.describe_parameters

If the service reaches an internal limit while processing the results, it stops the operation and returns the matching values up to that point and a NextToken

So it appears that limit is 50 parameters ( similar to how the UI displays parameters).

@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. support:core This issue/PR relates to code supported by the Ansible Engineering Team. and removed community_review In order to be merged, this PR must follow the community review workflow. support:community This issue/PR relates to code supported by the Ansible community. labels Sep 14, 2018
@s-hertel
Copy link
Contributor

Ah, I see. Thanks @eisjcormier, curiosity satiated. :-)

@s-hertel s-hertel merged commit 7aaa5da into ansible:devel Sep 14, 2018
@eisjcormier
Copy link
Contributor Author

Thanks Sloane!

@s-hertel
Copy link
Contributor

Thanks for fixing it! I'm going to open a backport PR so this can be included in 2.7.x as well.

s-hertel pushed a commit to s-hertel/ansible that referenced this pull request Sep 14, 2018
…45632)

Fix the service reaching an internal limit while processing the results and returning unexpected data
(cherry picked from commit 7aaa5da)
abadger pushed a commit that referenced this pull request Oct 11, 2018
…45666)

* [aws_ssm_parameter_store] use describe_parameters paginator (#45632)

Fix the service reaching an internal limit while processing the results and returning unexpected data
(cherry picked from commit 7aaa5da)

* changelog
@ansible ansible locked and limited conversation to collaborators Jul 22, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.8 This issue/PR affects Ansible v2.8 aws bug This issue/PR relates to a bug. cloud core_review In order to be merged, this PR must follow the core review workflow. module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member. small_patch support:core This issue/PR relates to code supported by the Ansible Engineering Team. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants