|
| 1 | +--- |
| 2 | +# This tasks file configures the Pipeline Local Filesystem Spaces |
| 3 | +# Pipeline Local Filesystems refer to the storage that is local to the Archivematica pipeline, |
| 4 | +# but remote to the Storage Service. It's a ssh-based remote space. |
| 5 | +# More info: |
| 6 | +# https://www.archivematica.org/en/docs/storage-service-0.16/administrators/#pipeline-local-filesystem |
| 7 | + |
| 8 | + |
| 9 | +# Get pipeline uuid |
| 10 | +- name: Get pipeline uuid |
| 11 | + become: "yes" |
| 12 | + shell: > |
| 13 | + echo: "select value from DashboardSettings where name='dashboard_uuid';" |
| 14 | + | {{ archivematica_src_am_dashboard_virtualenv }}/bin/python manage.py dbshell |
| 15 | + | tail -n1 |
| 16 | + args: |
| 17 | + chdir: "{{ archivematica_src_am_dashboard_app }}" |
| 18 | + executable: /bin/bash |
| 19 | + environment: "{{ archivematica_src_am_dashboard_environment }}" |
| 20 | + register: am_configure_pipelinelocalfs_pipeline_uuid |
| 21 | + |
| 22 | +# Define archivematica_src_configure_pipeline_remote_name |
| 23 | +- set_fact: |
| 24 | + am_configure_pipelinelocalfs_pipeline_remote_name: "{{ ansible_host }}" |
| 25 | + |
| 26 | +# Redefine archivematica_src_configure_pipeline_remote_name when archivematica_src_configure_am_site_url is defined |
| 27 | +- set_fact: |
| 28 | + am_configure_pipelinelocalfs_pipeline_remote_name: "{{ archivematica_src_configure_am_site_url|urlsplit('hostname') }}" |
| 29 | + when: "archivematica_src_configure_am_site_url is defined" |
| 30 | + |
| 31 | +# Check when Pipeline Local Filesystem already exists |
| 32 | +- name: "Get Pipeline Local Filesystem Space ID when it is already configured" |
| 33 | + become: "yes" |
| 34 | + shell: > |
| 35 | + echo "select space_id from locations_pipelinelocalfs where remote_name='{{ am_configure_pipelinelocalfs_pipeline_remote_name }}';" |
| 36 | + | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell |
| 37 | + | tail -n1 |
| 38 | + args: |
| 39 | + chdir: "{{ archivematica_src_ss_app }}" |
| 40 | + executable: /bin/bash |
| 41 | + environment: "{{ archivematica_src_ss_environment }}" |
| 42 | + delegate_to: "{{ archivematica_src_configure_ss_inventory_hostname | default(archivematica_src_configure_ss_url|urlsplit('hostname')) }}" |
| 43 | + remote_user: "{{ archivematica_src_configure_ss_ssh_user | default('artefactual') }}" |
| 44 | + register: am_configure_pipelinelocalfs_space_id |
| 45 | + |
| 46 | +# Create Pipeline Local Filesystem Space when it doesn't exist |
| 47 | + |
| 48 | +- name: "Create Pipeline Local Filesystem Space" |
| 49 | + uri: |
| 50 | + url: "{{ archivematica_src_configure_ss_url }}/api/v2/space/" |
| 51 | + headers: |
| 52 | + Content-Type: "application/json" |
| 53 | + Authorization: "ApiKey {{ archivematica_src_configure_ss_user }}:{{ archivematica_src_configure_ss_api_key }}" |
| 54 | + body: |
| 55 | + access_protocol: "PIPE_FS" |
| 56 | + path: "/" |
| 57 | + staging_path: "/var/archivematica/storage_service" |
| 58 | + remote_user: "archivematica" |
| 59 | + remote_name: "{{ am_configure_pipelinelocalfs_pipeline_remote_name }}" |
| 60 | + rsync_password: "" |
| 61 | + assume_rsync_daemon: False |
| 62 | + body_format: json |
| 63 | + status_code: 201 |
| 64 | + method: POST |
| 65 | + when: |
| 66 | + - am_configure_pipelinelocalfs_space_id.stdout is defined |
| 67 | + - am_configure_pipelinelocalfs_space_id.stdout == "" |
| 68 | + |
| 69 | +- name: "Get Pipeline Local Filesystem Space ID when it is created" |
| 70 | + shell: > |
| 71 | + echo "select space_id from locations_pipelinelocalfs where remote_name='{{ am_configure_pipelinelocalfs_pipeline_remote_name }}';" |
| 72 | + | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell |
| 73 | + | tail -n1 |
| 74 | + args: |
| 75 | + chdir: "{{ archivematica_src_ss_app }}" |
| 76 | + executable: /bin/bash |
| 77 | + environment: "{{ archivematica_src_ss_environment }}" |
| 78 | + delegate_to: "{{ archivematica_src_configure_ss_inventory_hostname | default(archivematica_src_configure_ss_url|urlsplit('hostname')) }}" |
| 79 | + remote_user: "{{ archivematica_src_configure_ss_ssh_user | default('artefactual') }}" |
| 80 | + register: am_configure_pipelinelocalfs_space_id_new |
| 81 | + when: |
| 82 | + - am_configure_pipelinelocalfs_space_id.stdout is defined |
| 83 | + - am_configure_pipelinelocalfs_space_id.stdout == "" |
| 84 | + |
| 85 | + |
| 86 | +# Reassign pipelinelocalfs_space_id when the Space is created |
| 87 | +- set_fact: am_configure_pipelinelocalfs_space_id={{ am_configure_pipelinelocalfs_space_id_new }} |
| 88 | + when: am_configure_pipelinelocalfs_space_id_new.stdout is defined |
| 89 | + |
| 90 | + |
| 91 | +- name: "Create Pipeline Local Filesystem locations" |
| 92 | + include_tasks: configure-create-location.yml |
| 93 | + vars: |
| 94 | + am_configure_space_uuid: "{{ am_configure_pipelinelocalfs_space_id.stdout }}" |
| 95 | + am_configure_pipeline_uuid: "{{ am_configure_pipelinelocalfs_pipeline_uuid.stdout }}" |
| 96 | + with_items: "{{ archivematica_src_configure_pipeline_localfs_locations }}" |
| 97 | + loop_control: |
| 98 | + loop_var: am_configure_location |
| 99 | + |
| 100 | +# Transfer Backlog and Currently Processing locations must be exactly one per pipeline. |
| 101 | +# So it is necessary to remove the pipeline from default locations when these locations_locationpipelinenew locations are added |
| 102 | +- name: "Delete pipeline from default LocalFilesystem Currently Procession or Transfer Backlog location when added to Pipeline LocalFS" |
| 103 | + shell: > |
| 104 | + echo "delete from locations_locationpipeline where pipeline_id='{{ am_configure_pipelinelocalfs_pipeline_uuid.stdout }}' and location_id in |
| 105 | + (select uuid from locations_location where purpose='{{ item }}' and space_id in |
| 106 | + (select space_id from locations_localfilesystem where id='1'));" |
| 107 | + | {{ archivematica_src_ss_virtualenv }}/bin/python manage.py dbshell |
| 108 | + | tail -n1 |
| 109 | + args: |
| 110 | + chdir: "{{ archivematica_src_ss_app }}" |
| 111 | + executable: /bin/bash |
| 112 | + environment: "{{ archivematica_src_ss_environment }}" |
| 113 | + delegate_to: "{{ archivematica_src_configure_ss_inventory_hostname | default(archivematica_src_configure_ss_url|urlsplit('hostname')) }}" |
| 114 | + remote_user: "{{ archivematica_src_configure_ss_ssh_user | default('artefactual') }}" |
| 115 | + when: "item in (archivematica_src_configure_pipeline_localfs_locations | map(attribute='location_purpose') | list)" |
| 116 | + loop: |
| 117 | + - "BL" |
| 118 | + - "CP" |
| 119 | + |
| 120 | +- name: "Create ssh key in SS" |
| 121 | + user: |
| 122 | + name: "archivematica" |
| 123 | + generate_ssh_key: "yes" |
| 124 | + ssh_key_file: ".ssh/id_rsa" |
| 125 | + delegate_to: "{{ archivematica_src_configure_ss_inventory_hostname | default(archivematica_src_configure_ss_url|urlsplit('hostname')) }}" |
| 126 | + remote_user: "{{ archivematica_src_configure_ss_ssh_user | default('artefactual') }}" |
| 127 | + register: am_configure_pipelinelocalfs_ss_ssh_key |
| 128 | + |
| 129 | +- name: "Use StrictHostKeyChecking=no ssh option for archivematica user" |
| 130 | + lineinfile: |
| 131 | + create: "yes" |
| 132 | + path: "/var/lib/archivematica/.ssh/config" |
| 133 | + owner: "archivematica" |
| 134 | + group: "archivematica" |
| 135 | + mode: "0600" |
| 136 | + line: "StrictHostKeyChecking no" |
| 137 | + delegate_to: "{{ archivematica_src_configure_ss_inventory_hostname | default(archivematica_src_configure_ss_url|urlsplit('hostname')) }}" |
| 138 | + remote_user: "{{ archivematica_src_configure_ss_ssh_user | default('artefactual') }}" |
| 139 | + |
| 140 | +- name: "Show ssh key" |
| 141 | + debug: msg={{ am_configure_pipelinelocalfs_ss_ssh_key.ssh_public_key }} |
| 142 | + |
| 143 | +- name: "Add SS ssh key to pipeline server" |
| 144 | + authorized_key: |
| 145 | + user: "archivematica" |
| 146 | + state: "present" |
| 147 | + key: "{{ am_configure_pipelinelocalfs_ss_ssh_key.ssh_public_key }}" |
0 commit comments