From f4fa3314c41673c0ea35dbc4af8fd5ce43fcee9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20L=C3=A9one?= Date: Fri, 9 Nov 2018 17:16:53 +0100 Subject: [PATCH] Add support for Scaleway object storage (#46353) --- .../rst/scenario_guides/guide_scaleway.rst | 49 ++++++++++ .../roles/scaleway_s3/defaults/main.yml | 4 + .../legacy/roles/scaleway_s3/tasks/aws_s3.yml | 19 ++++ .../roles/scaleway_s3/tasks/aws_s3_create.yml | 69 ++++++++++++++ .../roles/scaleway_s3/tasks/aws_s3_delete.yml | 69 ++++++++++++++ .../roles/scaleway_s3/tasks/aws_s3_delobj.yml | 73 +++++++++++++++ .../roles/scaleway_s3/tasks/aws_s3_get.yml | 31 +++++++ .../roles/scaleway_s3/tasks/aws_s3_getstr.yml | 23 +++++ .../roles/scaleway_s3/tasks/aws_s3_geturl.yml | 23 +++++ .../roles/scaleway_s3/tasks/aws_s3_list.yml | 22 +++++ .../roles/scaleway_s3/tasks/aws_s3_put.yml | 50 +++++++++++ test/legacy/roles/scaleway_s3/tasks/main.yml | 12 +++ .../roles/scaleway_s3/tasks/s3_bucket.yml | 90 +++++++++++++++++++ test/legacy/scaleway.yml | 1 + 14 files changed, 535 insertions(+) create mode 100644 test/legacy/roles/scaleway_s3/defaults/main.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/aws_s3.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/aws_s3_create.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/aws_s3_delete.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/aws_s3_delobj.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/aws_s3_get.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/aws_s3_getstr.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/aws_s3_geturl.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/aws_s3_list.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/aws_s3_put.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/main.yml create mode 100644 test/legacy/roles/scaleway_s3/tasks/s3_bucket.yml diff --git a/docs/docsite/rst/scenario_guides/guide_scaleway.rst b/docs/docsite/rst/scenario_guides/guide_scaleway.rst index 5859268890e..1cc2d625879 100644 --- a/docs/docsite/rst/scenario_guides/guide_scaleway.rst +++ b/docs/docsite/rst/scenario_guides/guide_scaleway.rst @@ -242,3 +242,52 @@ As you can see, we get different groups of hosts. In case a filter parameter is not defined, the plugin supposes all values possible are wanted. This means that for each tag that exists on your Scaleway compute nodes, a group based on each tag will be created. + +Scaleway S3 object storage +========================== + +`Object Storage `_ allows you to store any kind of objects (documents, images, videos, etc.). +As the Scaleway API is S3 compatible, Ansible supports it natively through the modules: :ref:`s3_bucket_module`, :ref:`aws_s3_module`. + +You can find many examples in ``./test/legacy/roles/scaleway_s3`` + +.. code-block:: yaml + + - hosts: myserver + vars: + scaleway_region: nl-ams + s3_url: https://s3.nl-ams.scw.cloud + environment: + # AWS_ACCESS_KEY matches your scaleway organization id available at https://cloud.scaleway.com/#/account + AWS_ACCESS_KEY: 00000000-1111-2222-3333-444444444444 + # AWS_SECRET_KEY matches a secret token that you can retrieve at https://cloud.scaleway.com/#/credentials + AWS_SECRET_KEY: aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee + module_defaults: + group/aws: + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + tasks: + # use a fact instead of a variable, otherwise template is evaluate each time variable is used + - set_fact: + bucket_name: "{{ 99999999 | random | to_uuid }}" + + # "requester_pays:" is mandatory because Scaleway doesn't implement related API + # another way is to use aws_s3 and "mode: create" ! + - s3_bucket: + name: '{{ bucket_name }}' + requester_pays: + + - name: Another way to create the bucket + aws_s3: + bucket: '{{ bucket_name }}' + mode: create + encrypt: false + register: bucket_creation_check + + - name: add something in the bucket + aws_s3: + mode: put + bucket: '{{ bucket_name }}' + src: /tmp/test.txt # needs to be created before + object: test.txt + encrypt: false # server side encryption must be disabled diff --git a/test/legacy/roles/scaleway_s3/defaults/main.yml b/test/legacy/roles/scaleway_s3/defaults/main.yml new file mode 100644 index 00000000000..b5178923ee3 --- /dev/null +++ b/test/legacy/roles/scaleway_s3/defaults/main.yml @@ -0,0 +1,4 @@ +--- +scaleway_region: nl-ams +endpoint: s3.nl-ams.scw.cloud +s3_url: https://s3.nl-ams.scw.cloud diff --git a/test/legacy/roles/scaleway_s3/tasks/aws_s3.yml b/test/legacy/roles/scaleway_s3/tasks/aws_s3.yml new file mode 100644 index 00000000000..6b6042f58d9 --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/aws_s3.yml @@ -0,0 +1,19 @@ +- name: Create a local file + tempfile: + state: file + suffix: temp + delegate_to: localhost + register: tempfile + +- import_tasks: aws_s3_create.yml + +- import_tasks: aws_s3_put.yml +- import_tasks: aws_s3_get.yml + +- import_tasks: aws_s3_getstr.yml +- import_tasks: aws_s3_geturl.yml +- import_tasks: aws_s3_list.yml + +- import_tasks: aws_s3_delobj.yml + +- import_tasks: aws_s3_delete.yml diff --git a/test/legacy/roles/scaleway_s3/tasks/aws_s3_create.yml b/test/legacy/roles/scaleway_s3/tasks/aws_s3_create.yml new file mode 100644 index 00000000000..b04f7d2c8fc --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/aws_s3_create.yml @@ -0,0 +1,69 @@ +- name: Create s3 bucket (Check) + check_mode: yes + aws_s3: + bucket: '{{ bucket_name }}' + mode: create + region: '{{ scaleway_region }}' + s3_url: '{{ s3_url }}' + encrypt: false + register: bucket_creation_check + +- name: Show bucket_creation_check + debug: + var: bucket_creation_check + +- name: bucket_creation_check is success + assert: + that: + - bucket_creation_check is success + +- name: bucket_creation_check is changed + assert: + that: + - bucket_creation_check is changed + +- name: Create s3 bucket + aws_s3: + bucket: '{{ bucket_name }}' + mode: create + region: '{{ scaleway_region }}' + s3_url: '{{ s3_url }}' + encrypt: false + register: bucket_creation + +- name: Show bucket_creation + debug: + var: bucket_creation + +- name: bucket_creation is success + assert: + that: + - bucket_creation is success + +- name: bucket_creation is changed + assert: + that: + - bucket_creation is changed + +- name: Create s3 bucket (Confirmation) + aws_s3: + bucket: '{{ bucket_name }}' + mode: create + region: '{{ scaleway_region }}' + s3_url: '{{ s3_url }}' + encrypt: false + register: bucket_creation_confirmation + +- name: Show bucket_creation_confirmation + debug: + var: bucket_creation_confirmation + +- name: bucket_creation_confirmation is success + assert: + that: + - bucket_creation_confirmation is success + +- name: bucket_creation_confirmation is not changed + assert: + that: + - bucket_creation_confirmation is not changed diff --git a/test/legacy/roles/scaleway_s3/tasks/aws_s3_delete.yml b/test/legacy/roles/scaleway_s3/tasks/aws_s3_delete.yml new file mode 100644 index 00000000000..09229e7a654 --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/aws_s3_delete.yml @@ -0,0 +1,69 @@ +- name: Delete s3 bucket (Check) + check_mode: yes + aws_s3: + bucket: '{{ bucket_name }}' + mode: delete + region: '{{ scaleway_region }}' + s3_url: '{{ s3_url }}' + encrypt: false + register: bucket_deletion_check + +- name: Show bucket_deletion_check + debug: + var: bucket_deletion_check + +- name: bucket_deletion_check is success + assert: + that: + - bucket_deletion_check is success + +- name: bucket_deletion_check is changed + assert: + that: + - bucket_deletion_check is changed + +- name: Delete s3 bucket + aws_s3: + bucket: '{{ bucket_name }}' + mode: delete + region: '{{ scaleway_region }}' + s3_url: '{{ s3_url }}' + encrypt: false + register: bucket_creation + +- name: Show bucket_creation + debug: + var: bucket_creation + +- name: bucket_creation is success + assert: + that: + - bucket_creation is success + +- name: bucket_creation is changed + assert: + that: + - bucket_creation is changed + +- name: Delete s3 bucket (Confirmation) + aws_s3: + bucket: '{{ bucket_name }}' + mode: delete + region: '{{ scaleway_region }}' + s3_url: '{{ s3_url }}' + encrypt: false + register: bucket_creation_confirmation + +- name: Show bucket_creation_confirmation + debug: + var: bucket_creation_confirmation + +- name: bucket_creation_confirmation is success + assert: + that: + - bucket_creation_confirmation is success + +- name: bucket_creation_confirmation is not changed + assert: + that: + - bucket_creation_confirmation is not changed diff --git a/test/legacy/roles/scaleway_s3/tasks/aws_s3_delobj.yml b/test/legacy/roles/scaleway_s3/tasks/aws_s3_delobj.yml new file mode 100644 index 00000000000..72d04a72fa0 --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/aws_s3_delobj.yml @@ -0,0 +1,73 @@ +- name: Delete an object (Check) + check_mode: yes + aws_s3: + mode: delobj + bucket: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + object: test.txt + encrypt: false + register: delobj_check_task + +- name: Show delobj_check_task + debug: + var: delobj_check_task + +- name: delobj_check_task is success + assert: + that: + - delobj_check_task is success + +- name: delobj_check_task is changed + assert: + that: + - delobj_check_task is changed + +- name: Delete an object + aws_s3: + mode: delobj + bucket: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + object: test.txt + encrypt: false + register: delobj_task + +- name: Show delobj_task + debug: + var: delobj_task + +- name: delobj_task is success + assert: + that: + - delobj_task is success + +- name: delobj_task is changed + assert: + that: + - delobj_task is changed + + +- name: Delete an object (Confirmation) + aws_s3: + mode: delobj + bucket: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + object: test.txt + encrypt: false + register: delobj_confirmation_task + +- name: Show delobj_confirmation_task + debug: + var: delobj_confirmation_task + +- name: delobj_confirmation_task is success + assert: + that: + - delobj_confirmation_task is success + +- name: delobj_confirmation_task is changed + assert: + that: + - delobj_confirmation_task is changed diff --git a/test/legacy/roles/scaleway_s3/tasks/aws_s3_get.yml b/test/legacy/roles/scaleway_s3/tasks/aws_s3_get.yml new file mode 100644 index 00000000000..5bc95ad9d33 --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/aws_s3_get.yml @@ -0,0 +1,31 @@ +- name: Create a destination local file + tempfile: + state: file + suffix: temp + delegate_to: localhost + register: tempfile_dst + +- name: Get from bucket + aws_s3: + mode: get + bucket: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + object: test.txt + dest: '{{ tempfile_dst.path }}' + encrypt: false + register: get_task + +- name: Show get_task + debug: + var: get_task + +- name: get_task is success + assert: + that: + - get_task is success + +- name: get_task is changed + assert: + that: + - get_task is changed diff --git a/test/legacy/roles/scaleway_s3/tasks/aws_s3_getstr.yml b/test/legacy/roles/scaleway_s3/tasks/aws_s3_getstr.yml new file mode 100644 index 00000000000..0555f984d82 --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/aws_s3_getstr.yml @@ -0,0 +1,23 @@ +- name: Get str from bucket + aws_s3: + mode: getstr + bucket: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + encrypt: false + object: test.txt + register: getstr_task + +- name: Show getstr_task + debug: + var: getstr_task + +- name: getstr_task is success + assert: + that: + - getstr_task is success + +- name: getstr_task is changed + assert: + that: + - getstr_task is changed diff --git a/test/legacy/roles/scaleway_s3/tasks/aws_s3_geturl.yml b/test/legacy/roles/scaleway_s3/tasks/aws_s3_geturl.yml new file mode 100644 index 00000000000..b1ba4db05f7 --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/aws_s3_geturl.yml @@ -0,0 +1,23 @@ +- name: Get url from bucket + aws_s3: + mode: geturl + bucket: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + object: test.txt + encrypt: false + register: geturl_task + +- name: Show geturl_task + debug: + var: geturl_task + +- name: geturl_task is success + assert: + that: + - geturl_task is success + +- name: geturl_task is changed + assert: + that: + - geturl_task is changed diff --git a/test/legacy/roles/scaleway_s3/tasks/aws_s3_list.yml b/test/legacy/roles/scaleway_s3/tasks/aws_s3_list.yml new file mode 100644 index 00000000000..0043e1708bb --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/aws_s3_list.yml @@ -0,0 +1,22 @@ +- name: List bucket + aws_s3: + mode: list + bucket: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + encrypt: false + register: list_task + +- name: Show list_task + debug: + var: list_task + +- name: list_task is success + assert: + that: + - list_task is success + +- name: list_task is not changed + assert: + that: + - list_task is not changed diff --git a/test/legacy/roles/scaleway_s3/tasks/aws_s3_put.yml b/test/legacy/roles/scaleway_s3/tasks/aws_s3_put.yml new file mode 100644 index 00000000000..71a5e114fbd --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/aws_s3_put.yml @@ -0,0 +1,50 @@ +- name: Put an object (Check) + check_mode: yes + aws_s3: + mode: put + bucket: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + src: '{{ tempfile.path }}' + object: test.txt + encrypt: false + register: put_check_task + +- name: Show put_check_task + debug: + var: put_check_task + +- name: put_check_task is success + assert: + that: + - put_check_task is success + +- name: put_check_task is changed + assert: + that: + - put_check_task is changed + +- name: Put an object + aws_s3: + mode: put + bucket: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + src: '{{ tempfile.path }}' + object: test.txt + encrypt: false + register: put_task + +- name: Show put_task + debug: + var: put_task + +- name: put_task is success + assert: + that: + - put_task is success + +- name: put_task is changed + assert: + that: + - put_task is changed diff --git a/test/legacy/roles/scaleway_s3/tasks/main.yml b/test/legacy/roles/scaleway_s3/tasks/main.yml new file mode 100644 index 00000000000..9f74582b871 --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/main.yml @@ -0,0 +1,12 @@ +# AWS_ACCESS_KEY='XXX' AWS_SECRET_KEY='YYY' ansible-playbook ./test/legacy/scaleway.yml --tags test_scaleway_s3 + +# use a fact instead of a variable, otherwise template is evaluate each time variable is used +- set_fact: + bucket_name: "ansible-s3-test-{{ 99999999 | random | to_uuid }}" + +- name: Show bucket name + debug: + var: bucket_name + +- import_tasks: s3_bucket.yml +- import_tasks: aws_s3.yml diff --git a/test/legacy/roles/scaleway_s3/tasks/s3_bucket.yml b/test/legacy/roles/scaleway_s3/tasks/s3_bucket.yml new file mode 100644 index 00000000000..7d3d59e9001 --- /dev/null +++ b/test/legacy/roles/scaleway_s3/tasks/s3_bucket.yml @@ -0,0 +1,90 @@ +- name: Bucket Creation + s3_bucket: + name: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + + requester_pays: + register: bucket_creation_task + +- name: Show bucket_creation_task + debug: + var: bucket_creation_task + +- name: bucket_creation_task is success + assert: + that: + - bucket_creation_task is success + +- name: bucket_creation_task is changed + assert: + that: + - bucket_creation_task is changed + +- name: Bucket Creation (Confirmation) + s3_bucket: + name: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + requester_pays: null + register: bucket_creation_confirmation_task + +- name: Show bucket_creation_confirmation_task + debug: + var: bucket_creation_confirmation_task + +- name: bucket_creation_confirmation_task is success + assert: + that: + - bucket_creation_confirmation_task is success + +- name: bucket_creation_confirmation_task is not changed + assert: + that: + - bucket_creation_confirmation_task is not changed + +- name: Bucket Deletion + s3_bucket: + name: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + requester_pays: null + state: absent + register: bucket_deletion_task + +- name: Show bucket_deletion_task + debug: + var: bucket_deletion_task + +- name: bucket_deletion_task is success + assert: + that: + - bucket_deletion_task is success + +- name: bucket_deletion_task is changed + assert: + that: + - bucket_deletion_task is changed + +- name: Bucket Deletion (Confirmation) + s3_bucket: + name: '{{ bucket_name }}' + s3_url: '{{ s3_url }}' + region: '{{ scaleway_region }}' + requester_pays: null + state: absent + register: bucket_deletion_confirmation_task + +- name: Show bucket_deletion_confirmation_task + debug: + var: bucket_deletion_confirmation_task + +- name: bucket_deletion_confirmation_task is success + assert: + that: + - bucket_deletion_confirmation_task is success + +- name: bucket_deletion_confirmation_task is not changed + assert: + that: + - bucket_deletion_confirmation_task is not changed diff --git a/test/legacy/scaleway.yml b/test/legacy/scaleway.yml index 2ba170d61ab..c8f19fd657a 100644 --- a/test/legacy/scaleway.yml +++ b/test/legacy/scaleway.yml @@ -11,6 +11,7 @@ - { role: scaleway_ip, tags: test_scaleway_ip } - { role: scaleway_ip_facts, tags: test_scaleway_ip_facts } - { role: scaleway_organization_facts, tags: test_scaleway_organization_facts } + - { role: scaleway_s3, tags: test_scaleway_s3 } - { role: scaleway_security_group_facts, tags: test_scaleway_security_group_facts } - { role: scaleway_server_facts, tags: test_scaleway_server_facts } - { role: scaleway_snapshot_facts, tags: test_scaleway_snapshot_facts }