From f590720ecaeef4a3623c0e50fba1110454a36719 Mon Sep 17 00:00:00 2001 From: Michal Ptacek Date: Wed, 19 Dec 2018 11:54:34 +0000 Subject: Add resource-data handling role In this role we mostly cover uploading of data resource using either default ssh way or if nfs server is configured it can be used as well for distributing data to infra node. Change-Id: I4784c6ca931b00c1033aedb33e388badfba83650 Issue-ID: OOM-1551 Signed-off-by: Michal Ptacek --- ansible/roles/resource-data/tasks/main.yml | 2 + ansible/roles/resource-data/tasks/nfs-upload.yml | 52 +++++++++++++++++++++ ansible/roles/resource-data/tasks/ssh-upload.yml | 59 ++++++++++++++++++++++++ 3 files changed, 113 insertions(+) create mode 100644 ansible/roles/resource-data/tasks/main.yml create mode 100644 ansible/roles/resource-data/tasks/nfs-upload.yml create mode 100644 ansible/roles/resource-data/tasks/ssh-upload.yml (limited to 'ansible/roles') diff --git a/ansible/roles/resource-data/tasks/main.yml b/ansible/roles/resource-data/tasks/main.yml new file mode 100644 index 00000000..51127226 --- /dev/null +++ b/ansible/roles/resource-data/tasks/main.yml @@ -0,0 +1,2 @@ +--- +- include_tasks: "{{ transport }}-upload.yml" diff --git a/ansible/roles/resource-data/tasks/nfs-upload.yml b/ansible/roles/resource-data/tasks/nfs-upload.yml new file mode 100644 index 00000000..825486b6 --- /dev/null +++ b/ansible/roles/resource-data/tasks/nfs-upload.yml @@ -0,0 +1,52 @@ +--- +- name: Upload resources to infrastructure servers over nfs + block: + - name: Mount resources + mount: + path: /tmp/resource_data + src: "{{ hostvars[groups.resources.0].ansible_host }}:{{ hostvars[groups.resources.0].resources_dir }}" + fstype: nfs + state: mounted + + - name: Unarchive resources + unarchive: + src: "/tmp/resource_data/{{ hostvars[groups.resources.0].resources_filename }}" + remote_src: yes + dest: "{{ app_data_path }}" + when: not resources_data_check.stat.exists + + - name: Unarchive auxiliary resources + unarchive: + src: "/tmp/resource_data/{{ hostvars[groups.resources.0].aux_resources_filename }}" + remote_src: yes + dest: "{{ aux_data_path }}" + when: > + hostvars[groups.resources.0].aux_resources_filename is defined + and aux_data_path is defined and aux_data_path is not none + and hostvars[groups.resources.0].aux_file_presence.stat.exists + and not aux_resources_data_check.stat.exists + + rescue: + - name: Removing the resources data due to an error - so the next run can try again + command: /bin/false + register: upload_failed + + always: + - name: unmount resource dir + mount: + path: /tmp/resource_data + src: "{{ hostvars[groups.resources.0].ansible_host }}:{{hostvars[groups.resources.0].resources_dir }}" + fstype: nfs + state: absent + + - name: Remove the resource data on error + file: + path: "{{ app_data_path }}" + state: absent + when: upload_failed is defined + + - name: Remove the auxilliary resource data on error + file: + path: "{{ aux_data_path }}" + state: absent + when: upload_failed is defined diff --git a/ansible/roles/resource-data/tasks/ssh-upload.yml b/ansible/roles/resource-data/tasks/ssh-upload.yml new file mode 100644 index 00000000..8e04d5c0 --- /dev/null +++ b/ansible/roles/resource-data/tasks/ssh-upload.yml @@ -0,0 +1,59 @@ +--- +- name: Upload resources to infrastructure servers over ssh + block: + - name: Upload ssh private key + copy: + src: "{{ ansible_ssh_private_key_file }}" + dest: /root/.ssh/infra_to_resource.privkey + mode: 0600 + owner: root + group: root + remote_src: no + + - name: Unarchive resources + shell: > + ssh -o StrictHostKeyChecking=no -o BatchMode=yes + -i /root/.ssh/infra_to_resource.privkey + {{ hostvars[groups.resources.0].ansible_host }} + 'cat "{{ hostvars[groups.resources.0].resources_dir }}/{{ hostvars[groups.resources.0].resources_filename }}"' + | tar -C "{{ app_data_path }}" -xf - + args: + warn: False + when: not resources_data_check.stat.exists + + - name: Unarchive auxiliary resources + shell: > + ssh -i /root/.ssh/infra_to_resource.privkey + {{ hostvars[groups.resources.0].ansible_host }} + 'cat "{{ hostvars[groups.resources.0].resources_dir }}/{{ hostvars[groups.resources.0].aux_resources_filename }}"' + | tar -C "{{ aux_data_path }}" -xf - + when: > + hostvars[groups.resources.0].aux_resources_filename is defined + and aux_data_path is defined and aux_data_path is not none + and hostvars[groups.resources.0].aux_file_presence.stat.exists + and not aux_resources_data_check.stat.exists + args: + warn: False + + rescue: + - name: Removing the resources data due to an error - so the next run can try again + command: /bin/false + register: upload_failed + + always: + - name: Remove the ssh private key + file: + path: /root/.ssh/infra_to_resource.privkey + state: absent + + - name: Remove the resource data on error + file: + path: "{{ app_data_path }}" + state: absent + when: upload_failed is defined + + - name: Remove the auxilliary resource data on error + file: + path: "{{ aux_data_path }}" + state: absent + when: upload_failed is defined -- cgit 1.2.3-korg