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

[aws_s3_cors] module not working with ansible 2.10.3 #304

Closed
m-stojanovic opened this issue Nov 20, 2020 · 7 comments
Closed

[aws_s3_cors] module not working with ansible 2.10.3 #304

m-stojanovic opened this issue Nov 20, 2020 · 7 comments
Labels
bug This issue/PR relates to a bug module module plugins plugin (any type) python3 traceback

Comments

@m-stojanovic
Copy link

m-stojanovic commented Nov 20, 2020

SUMMARY

I have 2 machines. On first I have updated Ansible to 2.10.3, the second is left at 2.9.9.
Ansible aws_s3_cors module does not work with Ansible 2.10.3.
On the first machine which has ansible 2.10.3 and boto3 latest version 1.16.22 I did not have

ISSUE TYPE
  • Bug Report
COMPONENT NAME

aws_s3_cors

ANSIBLE VERSION
Non working scenario:
ansible 2.10.3
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/home/mstojanovic/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/mstojanovic/.local/lib/python3.8/site-packages/ansible
  executable location = /home/mstojanovic/.local/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]

Working scenario:
ansible 2.9.9
  config file = None
  configured module search path = ['/home/milos/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/milos/.local/lib/python3.8/site-packages/ansible
  executable location = /home/milos/.local/bin/ansible
  python version = 3.8.5 (default, Jul 28 2020, 12:59:40) [GCC 9.3.0]
CONFIGURATION
DEFAULT_VAULT_PASSWORD_FILE(/etc/ansible/ansible.cfg) = /home/mstojanovic/.ansible_vault
INTERPRETER_PYTHON(env: ANSIBLE_PYTHON_INTERPRETER) = auto_silent
OS / ENVIRONMENT

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.1 LTS
Release: 20.04
Codename: focal

STEPS TO REPRODUCE

Run the playbook given in the example with your own keys.yml file that contains information about the AWS account you want to run the playbook for.

username-PC-$ ansible-playbook s3.yml --extra-vars "name=test dev_environment=stage"
- hosts: localhost
  gather_facts: yes
  vars_files:
    - keys.yml
  tasks:
    # Create required S3 buckets #
    - name: Create S3 octopus-server bucket
      s3_bucket:
        aws_access_key: "{{ AWS_ACCESS_KEY_ID }}"
        aws_secret_key: "{{ AWS_SECRET_ACCESS_KEY }}"
        region: "{{ AWS_REGION }}"
        name: "{{ name}}-{{ dev_environment }}-server"
        state: present
        versioning: no
        tags:
          Name: "{{ name }}-{{ dev_environment }}-server"
          user:Client: "{{ name }}"
          user:Environment: "{{ dev_environment }}"
        purge_tags: yes
      register: s3_debug

    - name: debug S3 var
      debug:
        var: s3_debug

    - name: Apply CORS rules to server bucket
      aws_s3_cors:
        aws_access_key: "{{ AWS_ACCESS_KEY_ID }}"
        aws_secret_key: "{{ AWS_SECRET_ACCESS_KEY }}"
        region: "{{ AWS_REGION }}"
        name: "{{ name}}-{{ dev_environment }}-octopus-server"
        state: present
        rules:
          - allowed_origins: #["*"]
              - "*"
            allowed_methods: #["GET", "POST", "PUT", "DELETE"]
              - GET
              - POST
              - PUT
              - DELETE
            allowed_headers: #["*"]
              - "*"
            expose_headers: #["ETag"]
              - ETag
            max_age_seconds: 3000
      register: s3_cors

    - name: debug S3 var
      debug:
        var: s3_cors
EXPECTED RESULTS

To create Cors rules for created S3 bucket with aws_s3_cors ansible module.
Successfully created with ansible 2.9.9. Example on the screenshot
image

ACTUAL RESULTS

Failed with error for ansible 2.10.3

TASK [Apply CORS rules to octopus-server bucket] ********************************************************************************************************************************************************************
An exception occurred during task execution. To see the full traceback, use -vvv. The error was: Invalid type for parameter CORSConfiguration.CORSRules[0], value: {'allowed_origins': ['*'], 'allowed_methods': ['GET', 'POST', 'PUT', 'DELETE'], 'allowed_headers': ['*'], 'expose_headers': ['ETag'], 'max_age_seconds': 3000}, type: <class 'str'>, valid types: <class 'dict'>
[WARNING]: The value "rules: {'allowed_origins': ['*'], 'allowed_methods': ['GET', 'POST', 'PUT', 'DELETE'], 'allowed_headers': ['*'], 'expose_headers': ['ETag'], 'max_age_seconds': 3000}" (type dict) was
converted to "rules: "{'allowed_origins': ['*'], 'allowed_methods': ['GET', 'POST', 'PUT', 'DELETE'], 'allowed_headers': ['*'], 'expose_headers': ['ETag'], 'max_age_seconds': 3000}"" (type string). If this does
not look like what you expect, quote the entire value to ensure it does not change.
fatal: [localhost]: FAILED! => {"boto3_version": "1.16.22", "botocore_version": "1.19.22", "changed": false, "msg": "Unable to update CORS for bucket test-stage-octopus-server: Parameter validation failed:\nInvalid type for parameter CORSConfiguration.CORSRules[0], value: {'allowed_origins': ['*'], 'allowed_methods': ['GET', 'POST', 'PUT', 'DELETE'], 'allowed_headers': ['*'], 'expose_headers': ['ETag'], 'max_age_seconds': 3000}, type: <class 'str'>, valid types: <class 'dict'>"}

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

<127.0.0.1> ESTABLISH LOCAL CONNECTION FOR USER: mstojanovic
<127.0.0.1> EXEC /bin/sh -c 'echo ~mstojanovic && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo /home/mstojanovic/.ansible/tmp `"&& mkdir "` echo /home/mstojanovic/.ansible/tmp/ansible-tmp-1605878276.015872-25852-224844474256545 `" && echo ansible-tmp-1605878276.015872-25852-224844474256545="` echo /home/mstojanovic/.ansible/tmp/ansible-tmp-1605878276.015872-25852-224844474256545 `" ) && sleep 0'
redirecting (type: modules) ansible.builtin.aws_s3_cors to community.aws.aws_s3_cors
Using module file /home/mstojanovic/.local/lib/python3.8/site-packages/ansible_collections/community/aws/plugins/modules/aws_s3_cors.py
<127.0.0.1> PUT /home/mstojanovic/.ansible/tmp/ansible-local-25609uku2qz8u/tmp_c3zbrw_ TO /home/mstojanovic/.ansible/tmp/ansible-tmp-1605878276.015872-25852-224844474256545/AnsiballZ_aws_s3_cors.py
<127.0.0.1> EXEC /bin/sh -c 'chmod u+x /home/mstojanovic/.ansible/tmp/ansible-tmp-1605878276.015872-25852-224844474256545/ /home/mstojanovic/.ansible/tmp/ansible-tmp-1605878276.015872-25852-224844474256545/AnsiballZ_aws_s3_cors.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c '/usr/bin/python3 /home/mstojanovic/.ansible/tmp/ansible-tmp-1605878276.015872-25852-224844474256545/AnsiballZ_aws_s3_cors.py && sleep 0'
<127.0.0.1> EXEC /bin/sh -c 'rm -f -r /home/mstojanovic/.ansible/tmp/ansible-tmp-1605878276.015872-25852-224844474256545/ > /dev/null 2>&1 && sleep 0'
The full traceback is:
Traceback (most recent call last):
  File "/tmp/ansible_aws_s3_cors_payload_x26wanny/ansible_aws_s3_cors_payload.zip/ansible_collections/community/aws/plugins/modules/aws_s3_cors.py", line 125, in create_or_update_bucket_cors
  File "/home/mstojanovic/.local/lib/python3.8/site-packages/botocore/client.py", line 357, in _api_call
    return self._make_api_call(operation_name, kwargs)
  File "/home/mstojanovic/.local/lib/python3.8/site-packages/botocore/client.py", line 648, in _make_api_call
    request_dict = self._convert_to_request_dict(
  File "/home/mstojanovic/.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/mstojanovic/.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 CORSConfiguration.CORSRules[0], value: {'allowed_origins': ['*'], 'allowed_methods': ['GET', 'POST', 'PUT', 'DELETE'], 'allowed_headers': ['*'], 'expose_headers': ['ETag'], 'max_age_seconds': 3000}, type: <class 'str'>, valid types: <class 'dict'>
[WARNING]: The value "rules: {'allowed_origins': ['*'], 'allowed_methods': ['GET', 'POST', 'PUT', 'DELETE'], 'allowed_headers': ['*'], 'expose_headers': ['ETag'], 'max_age_seconds': 3000}" (type dict) was
converted to "rules: "{'allowed_origins': ['*'], 'allowed_methods': ['GET', 'POST', 'PUT', 'DELETE'], 'allowed_headers': ['*'], 'expose_headers': ['ETag'], 'max_age_seconds': 3000}"" (type string). If this does
not look like what you expect, quote the entire value to ensure it does not change.
failed: [localhost] (item=test-stage-octopus-server) => {
    "ansible_loop_var": "item",
    "boto3_version": "1.16.22",
    "botocore_version": "1.19.22",
    "changed": false,
    "invocation": {
        "module_args": {
            "aws_access_key": "XXXXXXXXXXXXXXX",
            "aws_ca_bundle": null,
            "aws_config": null,
            "aws_secret_key": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
            "debug_botocore_endpoint_logs": false,
            "ec2_url": null,
            "name": "test-stage-octopus-server",
            "profile": null,
            "region": "us-east-1",
            "rules": [
                "{'allowed_origins': ['*'], 'allowed_methods': ['GET', 'POST', 'PUT', 'DELETE'], 'allowed_headers': ['*'], 'expose_headers': ['ETag'], 'max_age_seconds': 3000}"
            ],
            "security_token": null,
            "state": "present",
            "validate_certs": true
        }
    },
    "item": "test-stage-octopus-server",
    "msg": "Unable to update CORS for bucket test-stage-octopus-server: Parameter validation failed:\nInvalid type for parameter CORSConfiguration.CORSRules[0], value: {'allowed_origins': ['*'], 'allowed_methods': ['GET', 'POST', 'PUT', 'DELETE'], 'allowed_headers': ['*'], 'expose_headers': ['ETag'], 'max_age_seconds': 3000}, type: <class 'str'>, valid types: <class 'dict'>"
}

@fayaaz
Copy link

fayaaz commented Nov 24, 2020

#303

@m-stojanovic
Copy link
Author

Hi @fayaaz , when will this fix be applied? in Ansible 2.10.4 ?

@fayaaz
Copy link

fayaaz commented Nov 25, 2020

Hi @m-stojanovic I am not a maintainer of this repository so I could not tell you.

@m-stojanovic
Copy link
Author

Thanks for info @fayaaz !

@ansibullbot
Copy link

@ansibullbot ansibullbot added bug This issue/PR relates to a bug module module plugins plugin (any type) python3 traceback labels Jan 13, 2021
@alinabuzachis
Copy link
Contributor

Hi @m-stojanovic, thank you for your contribution. This seems to be a duplicate of #269.

@tremble
Copy link
Contributor

tremble commented Mar 14, 2021

This issue was fixed by #408 and should be available in v1.4.0 of this collection (Ansible 2.10.7)

@tremble tremble closed this as completed Mar 14, 2021
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 module module plugins plugin (any type) python3 traceback
Projects
None yet
Development

No branches or pull requests

6 participants