Skip to content

Commit 84e1f7f

Browse files
committed
Split locations configuration into it's own file
1 parent 8927c54 commit 84e1f7f

File tree

3 files changed

+156
-149
lines changed

3 files changed

+156
-149
lines changed

tasks/configure-locations.yml

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
- name: "Configure locations"
2+
environment: "{{ archivematica_src_ss_environment }}"
3+
block:
4+
# Get id of the first registered pipeline (id=1)
5+
- name: "Configure AM: get default pipeline UUID from SS database"
6+
shell: >
7+
echo "select uuid from locations_pipeline where id='1';"
8+
| {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1
9+
args:
10+
chdir: "{{ archivematica_src_ss_app }}"
11+
executable: "/bin/bash"
12+
register: pipeline_uuid
13+
14+
# Gets the uuid of the first registered space (id=1)
15+
- name: "Configure AM: get default Space UUID from SS database"
16+
shell: >
17+
echo "select uuid from locations_space where id='1';"
18+
| {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1
19+
args:
20+
chdir: "{{ archivematica_src_ss_app }}"
21+
executable: "/bin/bash"
22+
register: space_uuid
23+
24+
- name: "Configure AM: get all TS descriptions from SS database"
25+
shell: >
26+
echo "select description from locations_location;"
27+
| {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | grep -v "^description$"
28+
args:
29+
chdir: "{{ archivematica_src_ss_app }}"
30+
executable: "/bin/bash"
31+
register: location_descriptions
32+
33+
- name: "Configure SS: add custom locations"
34+
uri:
35+
url: "{{ archivematica_src_configure_ss_url }}/api/v2/location/"
36+
headers:
37+
Content-Type: "application/json"
38+
Authorization: "ApiKey {{ archivematica_src_configure_ss_user }}:{{ archivematica_src_configure_ss_api_key }}"
39+
body:
40+
pipeline: ["/api/v2/pipeline/{{ pipeline_uuid.stdout }}/"]
41+
purpose: "{{ item.location_purpose }}"
42+
relative_path: "{{ item.location_path | regex_replace('^\\/', '') }}"
43+
description: "{{ item.location_description }}"
44+
space: "/api/v2/space/{{ space_uuid.stdout }}/"
45+
default: "{{ item.location_default }}"
46+
body_format: json
47+
status_code: 201
48+
method: POST
49+
when: not location_descriptions.stdout | join('') | regex_search( '(^|\n)'+item.location_description+'(\n|$)' )
50+
with_items: "{{ am_ss_default_locations }}"
51+
52+
#
53+
# S3 Space/locations configuration
54+
#
55+
56+
- name: "Configure AM: get S3 Space UUID from SS database"
57+
shell: >
58+
echo "select uuid from locations_space where access_protocol='S3';"
59+
| {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1
60+
args:
61+
chdir: "{{ archivematica_src_ss_app }}"
62+
executable: "/bin/bash"
63+
register: s3_space_exists
64+
65+
- name: "Configure SS: add spaces"
66+
uri:
67+
url: "{{ archivematica_src_configure_ss_url }}/api/v2/space/"
68+
headers:
69+
Content-Type: "application/json"
70+
Authorization: "ApiKey {{ archivematica_src_configure_ss_user }}:{{ archivematica_src_configure_ss_api_key }}"
71+
body:
72+
access_protocol: "{{ item.access_protocol }}"
73+
path: "{{ item.path }}"
74+
staging_path: "{{ item.staging_path }}"
75+
endpoint_url: "{{ item.endpoint_url }}"
76+
access_key_id: "{{ item.access_key_id }}"
77+
secret_access_key: "{{ item.secret_access_key }}"
78+
region: "{{ item.region }}"
79+
bucket: "{{ item.bucket }}"
80+
body_format: json
81+
status_code: 201
82+
method: POST
83+
with_items: "{{ am_ss_s3_spaces }}"
84+
when:
85+
- s3_space_exists.stdout == ""
86+
- am_ss_s3_spaces is defined
87+
88+
- name: "Configure AM: get existing S3 Space UUID from SS database"
89+
shell: >
90+
echo "select uuid from locations_space where access_protocol='S3';"
91+
| {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1
92+
args:
93+
chdir: "{{ archivematica_src_ss_app }}"
94+
executable: "/bin/bash"
95+
register: s3_space_uuid
96+
97+
- name: "Configure SS: add S3 locations"
98+
uri:
99+
url: "{{ archivematica_src_configure_ss_url }}/api/v2/location/"
100+
headers:
101+
Content-Type: "application/json"
102+
Authorization: "ApiKey {{ archivematica_src_configure_ss_user }}:{{ archivematica_src_configure_ss_api_key }}"
103+
body:
104+
pipeline: ["/api/v2/pipeline/{{ pipeline_uuid.stdout }}/"]
105+
purpose: "{{ item.location_purpose }}"
106+
relative_path: "{{ item.location_path | regex_replace('^\\/', '') }}"
107+
staging_path: "{{ item.staging_path }}"
108+
description: "{{ item.location_description }}"
109+
space: "/api/v2/space/{{ s3_space_uuid.stdout }}/"
110+
default: "{{ item.location_default }}"
111+
body_format: json
112+
status_code: 201
113+
method: POST
114+
with_items: "{{ am_ss_s3_locations | default([]) }}"
115+
when:
116+
- am_ss_s3_locations is defined and am_ss_s3_locations != ""
117+
- not location_descriptions.stdout | join('') | regex_search( '(^|\n)'+item.location_description+'(\n|$)' )
118+
119+
#
120+
# Configure replication
121+
#
122+
123+
- name: "Configure replicas"
124+
shell: |
125+
if [ x"$PURPOSE" == x"RP" ]
126+
then
127+
echo $LOCATION replicates $REPLICAOF
128+
LOCATION_ID=$(echo "select id from locations_location where description=\"$LOCATION\";" | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1 )
129+
REPLICAOF_ID=$(echo "select id from locations_location where description=\"$REPLICAOF\";" | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1)
130+
CONFIG_ID=$(echo "select id from locations_location_replicators where from_location_id=$REPLICAOF_ID and to_location_id=$LOCATION_ID;" | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1)
131+
if [ x$CONFIG_ID == x ]
132+
then
133+
echo "insert into locations_location_replicators (from_location_id, to_location_id) values($REPLICAOF_ID,$LOCATION_ID);" | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell
134+
fi
135+
fi
136+
args:
137+
chdir: "{{ archivematica_src_ss_app }}"
138+
executable: "/bin/bash"
139+
environment:
140+
PURPOSE: "{{ item.location_purpose }}"
141+
LOCATION: "{{ item.location_description }}"
142+
REPLICAOF: "{{ item.location_replicaof|default('') }}"
143+
with_items:
144+
- "{{ am_ss_default_locations|default({}) }}"
145+
- "{{ am_ss_s3_locations|default({}) }}"

tasks/configure.yml

Lines changed: 0 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -250,152 +250,3 @@
250250
loop: "{{ lookup('dict',archivematica_src_configure_fprule|default({}),wantlist=True) }}"
251251
when: archivematica_src_configure_fprule is defined
252252

253-
- name: "Configure locations"
254-
environment: "{{ archivematica_src_ss_environment }}"
255-
block:
256-
# Get id of the first registered pipeline (id=1)
257-
- name: "Configure AM: get default pipeline UUID from SS database"
258-
shell: >
259-
echo "select uuid from locations_pipeline where id='1';"
260-
| {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1
261-
args:
262-
chdir: "{{ archivematica_src_ss_app }}"
263-
executable: "/bin/bash"
264-
register: pipeline_uuid
265-
266-
# Gets the uuid of the first registered space (id=1)
267-
- name: "Configure AM: get default Space UUID from SS database"
268-
shell: >
269-
echo "select uuid from locations_space where id='1';"
270-
| {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1
271-
args:
272-
chdir: "{{ archivematica_src_ss_app }}"
273-
executable: "/bin/bash"
274-
register: space_uuid
275-
276-
- name: "Configure AM: get all TS descriptions from SS database"
277-
shell: >
278-
echo "select description from locations_location;"
279-
| {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | grep -v "^description$"
280-
args:
281-
chdir: "{{ archivematica_src_ss_app }}"
282-
executable: "/bin/bash"
283-
register: location_descriptions
284-
285-
- name: "Configure SS: add custom locations"
286-
uri:
287-
url: "{{ archivematica_src_configure_ss_url }}/api/v2/location/"
288-
headers:
289-
Content-Type: "application/json"
290-
Authorization: "ApiKey {{ archivematica_src_configure_ss_user }}:{{ archivematica_src_configure_ss_api_key }}"
291-
body:
292-
pipeline: ["/api/v2/pipeline/{{ pipeline_uuid.stdout }}/"]
293-
purpose: "{{ item.location_purpose }}"
294-
relative_path: "{{ item.location_path | regex_replace('^\\/', '') }}"
295-
description: "{{ item.location_description }}"
296-
space: "/api/v2/space/{{ space_uuid.stdout }}/"
297-
default: "{{ item.location_default }}"
298-
body_format: json
299-
status_code: 201
300-
method: POST
301-
when: not location_descriptions.stdout | join('') | regex_search( '(^|\n)'+item.location_description+'(\n|$)' )
302-
with_items: "{{ am_ss_default_locations }}"
303-
304-
#
305-
# S3 Space/locations configuration
306-
#
307-
308-
- name: "Configure AM: get S3 Space UUID from SS database"
309-
shell: >
310-
echo "select uuid from locations_space where access_protocol='S3';"
311-
| {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1
312-
args:
313-
chdir: "{{ archivematica_src_ss_app }}"
314-
executable: "/bin/bash"
315-
register: s3_space_exists
316-
317-
- name: "Configure SS: add spaces"
318-
uri:
319-
url: "{{ archivematica_src_configure_ss_url }}/api/v2/space/"
320-
headers:
321-
Content-Type: "application/json"
322-
Authorization: "ApiKey {{ archivematica_src_configure_ss_user }}:{{ archivematica_src_configure_ss_api_key }}"
323-
body:
324-
access_protocol: "{{ item.access_protocol }}"
325-
path: "{{ item.path }}"
326-
staging_path: "{{ item.staging_path }}"
327-
endpoint_url: "{{ item.endpoint_url }}"
328-
access_key_id: "{{ item.access_key_id }}"
329-
secret_access_key: "{{ item.secret_access_key }}"
330-
region: "{{ item.region }}"
331-
bucket: "{{ item.bucket }}"
332-
body_format: json
333-
status_code: 201
334-
method: POST
335-
with_items: "{{ am_ss_s3_spaces }}"
336-
when:
337-
- s3_space_exists.stdout == ""
338-
- am_ss_s3_spaces is defined
339-
340-
- name: "Configure AM: get existing S3 Space UUID from SS database"
341-
shell: >
342-
echo "select uuid from locations_space where access_protocol='S3';"
343-
| {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1
344-
args:
345-
chdir: "{{ archivematica_src_ss_app }}"
346-
executable: "/bin/bash"
347-
register: s3_space_uuid
348-
349-
- name: "Configure SS: add S3 locations"
350-
uri:
351-
url: "{{ archivematica_src_configure_ss_url }}/api/v2/location/"
352-
headers:
353-
Content-Type: "application/json"
354-
Authorization: "ApiKey {{ archivematica_src_configure_ss_user }}:{{ archivematica_src_configure_ss_api_key }}"
355-
body:
356-
pipeline: ["/api/v2/pipeline/{{ pipeline_uuid.stdout }}/"]
357-
purpose: "{{ item.location_purpose }}"
358-
relative_path: "{{ item.location_path | regex_replace('^\\/', '') }}"
359-
staging_path: "{{ item.staging_path }}"
360-
description: "{{ item.location_description }}"
361-
space: "/api/v2/space/{{ s3_space_uuid.stdout }}/"
362-
default: "{{ item.location_default }}"
363-
body_format: json
364-
status_code: 201
365-
method: POST
366-
with_items: "{{ am_ss_s3_locations | default([]) }}"
367-
when:
368-
- am_ss_s3_locations is defined and am_ss_s3_locations != ""
369-
- not location_descriptions.stdout | join('') | regex_search( '(^|\n)'+item.location_description+'(\n|$)' )
370-
371-
#
372-
# Configure replication
373-
#
374-
375-
- name: "Configure replicas"
376-
shell: |
377-
if [ x"$PURPOSE" == x"RP" ]
378-
then
379-
echo $LOCATION replicates $REPLICAOF
380-
LOCATION_ID=$(echo "select id from locations_location where description=\"$LOCATION\";" | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1 )
381-
REPLICAOF_ID=$(echo "select id from locations_location where description=\"$REPLICAOF\";" | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1)
382-
CONFIG_ID=$(echo "select id from locations_location_replicators where from_location_id=$REPLICAOF_ID and to_location_id=$LOCATION_ID;" | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell | tail -n1)
383-
if [ x$CONFIG_ID == x ]
384-
then
385-
echo "insert into locations_location_replicators (from_location_id, to_location_id) values($REPLICAOF_ID,$LOCATION_ID);" | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell
386-
fi
387-
fi
388-
args:
389-
chdir: "{{ archivematica_src_ss_app }}"
390-
executable: "/bin/bash"
391-
environment:
392-
PURPOSE: "{{ item.location_purpose }}"
393-
LOCATION: "{{ item.location_description }}"
394-
REPLICAOF: "{{ item.location_replicaof|default('') }}"
395-
with_items:
396-
- "{{ am_ss_default_locations|default({}) }}"
397-
- "{{ am_ss_s3_locations|default({}) }}"
398-
when: am_ss_default_locations is defined or am_ss_s3_locations is defined
399-
tags:
400-
- "configure-am"
401-
- "configure-locations"

tasks/main.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,17 @@
276276
- "amsrc-configure"
277277
when: "archivematica_src_configure_ss|bool or archivematica_src_configure_dashboard|bool"
278278

279+
#
280+
# Configure SS locations
281+
#
282+
- include: "configure-locations.yml"
283+
tags:
284+
- "amsrc-configure"
285+
- "amsrc-configure-locations"
286+
- "configure-locations"
287+
when: am_ss_default_locations is defined or am_ss_s3_locations is defined
288+
289+
279290
#
280291
# Configure GPG locations
281292
#

0 commit comments

Comments
 (0)