Skip to content

Commit c8a8c19

Browse files
authored
- fix s3 idempotence (#300)
- currently, s3 part dies if run twice - make s3 config code simpler by removing some copy-and-paste and using a loop - aws_cli install on debian
1 parent dda7a02 commit c8a8c19

3 files changed

Lines changed: 41 additions & 45 deletions

File tree

tasks/aws_cli.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
ansible.builtin.package:
1818
name: awscli
1919
state: latest
20-
when: ansible_os_family == "RedHat"
20+
when: ansible_os_family == "RedHat" or ansible_os_family == "Debian"

tasks/s3.yml

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,44 @@
2626
group: '{{ dataverse.payara.group }}'
2727
mode: '0600'
2828

29-
# this assumes only one S3 datastore. not completely viable any more.
30-
#- name: set storage-driver-id to s3
31-
# shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.storage-driver-id={{ s3.storage_driver_id }}"'
32-
33-
- name: set s3 type to s3
34-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.type={{ s3.files_type }}"'
35-
36-
- name: set s3 label to s3
37-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.label={{ s3.label }}"'
38-
39-
- name: set s3 bucket name
40-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.bucket-name={{ s3.bucket_name }}"'
41-
42-
- name: set s3 url expiration minutes
43-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.url-expiration-minutes={{ s3.url_expiration_minutes }}"'
29+
- name: set s3 settings in dataverse
30+
shell: 'asadmin-create-or-replace-option.sh "{{ item.key }}" "{{ item.value }}"'
31+
register: output
32+
changed_when: "'Command create-jvm-options executed successfully.' in output.stdout"
33+
when:
34+
- item.value is defined
35+
- item.value != ''
36+
with_items:
37+
- key: dataverse.files.storage-driver-id
38+
value: "{{ s3.storage_driver_id }}"
39+
- key: dataverse.files.s3.type
40+
value: "{{ s3.files_type }}"
41+
- key: dataverse.files.s3.label
42+
value: "{{ s3.label }}"
43+
- key: dataverse.files.s3.bucket-name
44+
value: "{{ s3.bucket_name }}"
45+
- key: dataverse.files.s3.url-expiration-minutes
46+
value: "{{ s3.url_expiration_minutes }}"
47+
- key: dataverse.files.s3.upload-redirect
48+
value: "{{ s3.upload_redirect }}"
49+
- key: dataverse.files.s3.path-style-access
50+
value: "{{ s3.path_style_access }}"
51+
- key: dataverse.files.s3.payload-signing
52+
value: "{{ s3.payload_signing }}"
53+
- key: dataverse.files.s3.chunked-encoding
54+
value: "{{ s3.chunked_encoding }}"
55+
- key: dataverse.files.s3.custom-endpoint-region
56+
value: "{{ s3.custom_endpoint_region }}"
4457

4558
# optional s3 settings
4659

4760
- name: expose custom_endpoint_url as variable
4861
set_fact:
4962
custom_endpoint_url: '{{ s3.custom_endpoint_url }}'
5063

64+
- ansible.builtin.import_tasks: s3_custom_endpoint_url.yml
65+
when: custom_endpoint_url | length > 0
66+
5167
- name: create S3 bucket
5268
shell:
5369
'aws s3api create-bucket --bucket {{ s3.bucket_name }}'
@@ -81,30 +97,8 @@
8197
when: (s3.download_redirect == true or s3.upload_redirect == true)
8298
and custom_endpoint_url | length == 0
8399
and s3.cors_already_set == false
84-
85-
- ansible.builtin.import_tasks: s3_custom_endpoint_url.yml
86-
when: custom_endpoint_url | length > 0
87-
88100
- name: set s3 direct download
89-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.download-redirect={{ s3.download_redirect }}"'
90-
when: s3.download_redirect == true
91-
92-
- name: set s3 direct upload
93-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.upload-redirect={{ s3.upload_redirect }}"'
94-
when: s3.upload_redirect == true
95-
96-
- name: set s3 path style access
97-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.path-style-access={{ s3.path_style_access }}"'
98-
when: s3.path_style_access == true
99-
100-
- name: set s3 payload signing
101-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.payload-signing={{ s3.payload_signing }}"'
102-
when: s3.payload_signing == true
103-
104-
- name: turn chunked encoding off
105-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.chunked-encoding={{ s3.chunked_encoding }}"'
106-
when: s3.chunked_encoding == false
101+
shell: 'asadmin-create-or-replace-option.sh "dataverse.files.s3.download-redirect" "{{ s3.download_redirect }}"'
102+
register: output
103+
changed_when: "'Command create-jvm-options executed successfully.' in output.stdout"
107104

108-
- name: set custom endpoint region
109-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.custom-endpoint-region={{ s3.custom_endpoint_region }}"'
110-
when: s3.custom_endpoint_region is defined and s3.custom_endpoint_region != ''

tasks/s3_custom_endpoint_url.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---
22

3-
- name: escape custom endpoint url colons
4-
set_fact: "custom_endpoint_escaped={{ s3.custom_endpoint_url | regex_replace (':','\\:') }}"
5-
63
- name: set s3 custom endpoint url
7-
shell: '{{ payara_dir}}/bin/asadmin create-jvm-options "-Ddataverse.files.s3.custom-endpoint-url={{ custom_endpoint_escaped }}"'
4+
shell: 'asadmin-create-or-replace-option.sh "dataverse.files.s3.custom-endpoint-url" "{{ custom_endpoint_url }}"'
85

96
- name: create S3 bucket
107
shell:
118
'aws s3api create-bucket --bucket {{ s3.bucket_name }} --endpoint-url {{ s3.custom_endpoint_url }}'
129
args:
1310
executable: /bin/bash
11+
become: yes
1412
become_user: '{{ dataverse.payara.user }}'
1513
environment:
1614
PATH: "{{ lookup('env', 'PATH') }}:/usr/local/bin"
1715
when: s3.create_bucket == true
16+
register: output
17+
changed_when: "'Command create-jvm-options executed successfully.' in output.stdout"
1818

1919
- name: enable CORS on S3 bucket
2020
shell:
@@ -27,3 +27,5 @@
2727
PATH: "{{ lookup('env', 'PATH') }}:/usr/local/bin"
2828
when: s3.download_redirect == true or
2929
s3.upload_redirect == true
30+
register: output
31+
changed_when: "'Command create-jvm-options executed successfully.' in output.stdout"

0 commit comments

Comments
 (0)