1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add support for Scaleway object storage (#46353)

This commit is contained in:
Rémy Léone 2018-11-09 17:16:53 +01:00 committed by John R Barker
parent b047591dee
commit f4fa3314c4
14 changed files with 535 additions and 0 deletions

View file

@ -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 <https://www.scaleway.com/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

View file

@ -0,0 +1,4 @@
---
scaleway_region: nl-ams
endpoint: s3.nl-ams.scw.cloud
s3_url: https://s3.nl-ams.scw.cloud

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 }