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

croc cloud - ec2 key patch #60929

Merged
merged 1 commit into from
Jan 31, 2020
Merged

croc cloud - ec2 key patch #60929

merged 1 commit into from
Jan 31, 2020

Conversation

Maunty
Copy link
Contributor

@Maunty Maunty commented Aug 20, 2019

SUMMARY

This patch fixes "IndexError: list index out of range" error for https://console.cloud.croc.ru.
When key pair is new, croc return dict with an empty list for key KeyPairs that causes ansible to crush.

ISSUE TYPE
  • Bugfix Pull Request
COMPONENT NAME

ec2_key

ADDITIONAL INFORMATION

<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: user
<127.0.0.1> EXEC /bin/sh -c 'echo ~user && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607 `" && echo ansible-tmp-1566293632.1787608-45601675593607="` echo /home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607 `" ) && sleep 0'
Using module file /home/user/.local/lib/python3.6/site-packages/ansible/modules/cloud/amazon/ec2_key.py
<127.0.0.1> PUT /home/user/.ansible/tmp/ansible-local-31974wpvc25aa/tmpi1h7fvmx TO /home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/AnsiballZ_ec2_key.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/ /home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/AnsiballZ_ec2_key.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/AnsiballZ_ec2_key.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/AnsiballZ_ec2_key.py", line 114, in <module>
    _ansiballz_main()
  File "/home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/AnsiballZ_ec2_key.py", line 106, in _ansiballz_main
    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)
  File "/home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/AnsiballZ_ec2_key.py", line 49, in invoke_module
    imp.load_module('__main__', mod, module, MOD_DESC)
  File "/usr/lib/python3.6/imp.py", line 235, in load_module
    return load_source(name, filename, file)
  File "/usr/lib/python3.6/imp.py", line 170, in load_source
    module = _exec(spec, sys.modules[name])
  File "<frozen importlib._bootstrap>", line 618, in _exec
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/tmp/ansible_ec2_key_payload_g82c75ow/__main__.py", line 277, in <module>
  File "/tmp/ansible_ec2_key_payload_g82c75ow/__main__.py", line 273, in main
  File "/tmp/ansible_ec2_key_payload_g82c75ow/__main__.py", line 191, in create_key_pair
  File "/tmp/ansible_ec2_key_payload_g82c75ow/__main__.py", line 181, in find_key_pair
IndexError: list index out of range

fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "Traceback (most recent call last):\n  File \"/home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/AnsiballZ_ec2_key.py\", line 114, in <module>\n    _ansiballz_main()\n  File \"/home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/AnsiballZ_ec2_key.py\", line 106, in _ansiballz_main\n    invoke_module(zipped_mod, temp_path, ANSIBALLZ_PARAMS)\n  File \"/home/user/.ansible/tmp/ansible-tmp-1566293632.1787608-45601675593607/AnsiballZ_ec2_key.py\", line 49, in invoke_module\n    imp.load_module('__main__', mod, module, MOD_DESC)\n  File \"/usr/lib/python3.6/imp.py\", line 235, in load_module\n    return load_source(name, filename, file)\n  File \"/usr/lib/python3.6/imp.py\", line 170, in load_source\n    module = _exec(spec, sys.modules[name])\n  File \"<frozen importlib._bootstrap>\", line 618, in _exec\n  File \"<frozen importlib._bootstrap_external>\", line 678, in exec_module\n  File \"<frozen importlib._bootstrap>\", line 219, in _call_with_frames_removed\n  File \"/tmp/ansible_ec2_key_payload_g82c75ow/__main__.py\", line 277, in <module>\n  File \"/tmp/ansible_ec2_key_payload_g82c75ow/__main__.py\", line 273, in main\n  File \"/tmp/ansible_ec2_key_payload_g82c75ow/__main__.py\", line 191, in create_key_pair\n  File \"/tmp/ansible_ec2_key_payload_g82c75ow/__main__.py\", line 181, in find_key_pair\nIndexError: list index out of range\n",
    "module_stdout": "",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 1
}

PLAY RECAP *************************************************************************************************************************************************************************************************
localhost                  : ok=1    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0   



with a breakpoint 
fatal: [localhost]: FAILED! => {
    "changed": false,
    "module_stderr": "",
    "module_stdout": "{'KeyPairs': [], 'ResponseMetadata': {'RequestId': 'af8d02da-855f-43d5-9521-4192a37dda6a', 'HTTPStatusCode': 200, 'HTTPHeaders': {'server': 'nginx', 'date': 'Tue, 20 Aug 2019 09:34:17 GMT', 'content-type': 'text/xml', 'transfer-encoding': 'chunked', 'connection': 'close'}, 'RetryAttempts': 0}}\n",
    "msg": "MODULE FAILURE\nSee stdout/stderr for the exact error",
    "rc": 0
}


anfter fix

TASK [ec2_key] *********************************************************************************************************************************************************************************************
task path: /home/user/Documents/ansible_tests/croc/test.yml:3
<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: user
<127.0.0.1> EXEC /bin/sh -c 'echo ~user && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/user/.ansible/tmp/ansible-tmp-1566293908.6296523-226074249381502 `" && echo ansible-tmp-1566293908.6296523-226074249381502="` echo /home/user/.ansible/tmp/ansible-tmp-1566293908.6296523-226074249381502 `" ) && sleep 0'
Using module file /home/user/.local/lib/python3.6/site-packages/ansible/modules/cloud/amazon/ec2_key.py
<127.0.0.1> PUT /home/user/.ansible/tmp/ansible-local-32412l5m0h6a5/tmp6knlhn03 TO /home/user/.ansible/tmp/ansible-tmp-1566293908.6296523-226074249381502/AnsiballZ_ec2_key.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/user/.ansible/tmp/ansible-tmp-1566293908.6296523-226074249381502/ /home/user/.ansible/tmp/ansible-tmp-1566293908.6296523-226074249381502/AnsiballZ_ec2_key.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/user/.ansible/tmp/ansible-tmp-1566293908.6296523-226074249381502/AnsiballZ_ec2_key.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/user/.ansible/tmp/ansible-tmp-1566293908.6296523-226074249381502/ > /dev/null 2>&1 && sleep 0'
changed: [localhost] => {
    "changed": true,
    "invocation": {
        "module_args": {
            "aws_access_key": null,
            "aws_secret_key": null,
            "debug_botocore_endpoint_logs": false,
            "ec2_url": null,
            "force": true,
            "key_material": null,
            "name": "test",
            "profile": null,
            "region": "bla-bla",
            "security_token": null,
            "state": "present",
            "validate_certs": true,
            "wait": false,
            "wait_timeout": 300
        }
    },
    "key": {
        "fingerprint": "someid",
        "name": "test",
        "private_key": "somedata"
    },
    "msg": "key pair created"
}

TASK [debug] ***********************************************************************************************************************************************************************************************
task path: /home/user/Documents/ansible_tests/croc/test.yml:7
ok: [localhost] => {
    "ec2": {
        "changed": true,
        "failed": false,
        "key": {
            "fingerprint": "someid",
            "name": "test",
            "private_key": "somedata"
        },
        "msg": "key pair created"
    }




This patch fixes "IndexError: list index out of range" error for https://console.cloud.croc.ru.
When key pair is new, croc return dict with an empty list for key KeyPairs that causes ansible to crush.
@ansibot
Copy link
Contributor

ansibot commented Aug 20, 2019

@ansibot
Copy link
Contributor

ansibot commented Aug 20, 2019

@Maunty, 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.9 This issue/PR affects Ansible v2.9 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. python3 small_patch support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback. labels Aug 20, 2019
@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Aug 29, 2019
@ansibot
Copy link
Contributor

ansibot commented Jan 29, 2020

@Maunty
Copy link
Contributor Author

Maunty commented Jan 30, 2020

A little bit more information. Croc is an aws e2c api compatible cloud(almost compatible :) ). So by changing endpoint it is possible to use aws modules with it. But sometimes it needs a little help like in this case.

@tremble
Copy link
Contributor

tremble commented Jan 30, 2020

I don't have access to Croc to test this, but the change looks small, noninvasive and doesn't appear to break things for AWS so:

LGTM

@ansibot ansibot removed the needs_triage Needs a first human triage before being processed. label Jan 30, 2020
Copy link
Contributor

@jillr jillr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, thanks very much for this patch @Maunty!

rebuild_merge

@ansibot ansibot added shipit This PR is ready to be merged by Core automerge This PR was automatically merged by ansibot. and removed community_review In order to be merged, this PR must follow the community review workflow. stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Jan 31, 2020
@ansibot ansibot merged commit ef1fd19 into ansible:devel Jan 31, 2020
@ansible ansible locked and limited conversation to collaborators Mar 2, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 automerge This PR was automatically merged by ansibot. aws bug This issue/PR relates to a bug. cloud module This issue/PR relates to a module. new_contributor This PR is the first contribution by a new community member. python3 shipit This PR is ready to be merged by Core small_patch support:community This issue/PR relates to code supported by the Ansible community. traceback This issue/PR includes a traceback.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants