From c53c0b49786af93bd60b3e3477af26d1368605ce Mon Sep 17 00:00:00 2001 From: Caila Finn Date: Wed, 25 Sep 2024 12:01:43 +0100 Subject: [PATCH] Allow rsync with mantidproject.org hostname RE #99 --- .../ansible/roles/mirror-data/defaults/main.yml | 7 ------- .../ansible/roles/mirror-data/tasks/exchange-keys.yml | 10 +++++----- .../ansible/roles/mirror-data/tasks/main.yml | 6 +++--- .../roles/mirror-data/tasks/update-external-data.sh | 5 +++-- 4 files changed, 11 insertions(+), 17 deletions(-) delete mode 100644 Linux/external-data-mirror/ansible/roles/mirror-data/defaults/main.yml diff --git a/Linux/external-data-mirror/ansible/roles/mirror-data/defaults/main.yml b/Linux/external-data-mirror/ansible/roles/mirror-data/defaults/main.yml deleted file mode 100644 index 018876b..0000000 --- a/Linux/external-data-mirror/ansible/roles/mirror-data/defaults/main.yml +++ /dev/null @@ -1,7 +0,0 @@ -# Default values for creating external data mirror. - -# IP of server containing external data main copy. -main_server_ip: "198.74.56.37" - -# User on the main server. -main_server_user: root \ No newline at end of file diff --git a/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/exchange-keys.yml b/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/exchange-keys.yml index 5fa95b6..da30942 100644 --- a/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/exchange-keys.yml +++ b/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/exchange-keys.yml @@ -11,10 +11,10 @@ - name: Add public key to main server's authorized keys ansible.posix.authorized_key: - user: "{{ main_server_user }}" + user: root key: "{{ lookup('file','/tmp/{{ ansible_hostname }}-id_rsa.pub')}}" - remote_user: "{{ main_server_user }}" - delegate_to: "{{ main_server_ip }}" + remote_user: root + delegate_to: "{{ main_server_hostname }}" - name: Touch the known_hosts file if it's missing file: @@ -23,13 +23,13 @@ mode: 0644 - name: Check if known_hosts contains existing server fingerprint - command: ssh-keygen -F {{ main_server_user }} + command: ssh-keygen -F {{ main_server_hostname }} register: key_exists failed_when: key_exists.stderr != '' changed_when: False - name: Scan for existing remote ssh fingerprint - command: ssh-keyscan -T5 {{ main_server_ip }} + command: ssh-keyscan -T5 {{ main_server_hostname }} register: keyscan failed_when: keyscan.rc != 0 or keyscan.stdout == '' changed_when: False diff --git a/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/main.yml b/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/main.yml index b803e68..2216b05 100644 --- a/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/main.yml +++ b/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/main.yml @@ -5,7 +5,7 @@ mode: '0755' - name: Check if machine has SSH access to the main data store. - ansible.builtin.command: ssh {{ main_server_user }}@{{ main_server_ip }} 'echo success' + ansible.builtin.command: ssh {{ main_server_user }}@{{ main_server_hostname }} 'echo success' register: connected - name: Exchange SSH keys with linode so we can access the data. @@ -13,7 +13,7 @@ when: connected.stdout != "success" - name: Mirror the external data from the main server in a volume (this may take a while). - ansible.builtin.command: "rsync -az --perms -o -g {{ main_server_ip }}:/srv/{{ main_server_ip }}/ftp/external-data/MD5/ /external-data/MD5/" + ansible.builtin.command: "rsync -az --perms -o -g {{ main_server_hostname }}:/srv/{{ main_data_srv_dir }}/ftp/external-data/MD5/ /external-data/MD5/" - name: Copy the data update script onto the mirror machine. ansible.builtin.copy: @@ -25,4 +25,4 @@ ansible.builtin.cron: name: Update external data minute: "*/5" - job: /external-data/update-external-data.sh {{ main_server_ip }} >> /external-data/update-log.txt 2>&1 + job: /external-data/update-external-data.sh {{ main_server_hostname }} {{ main_data_srv_dir }} >> /external-data/update-log.txt 2>&1 diff --git a/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/update-external-data.sh b/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/update-external-data.sh index 555baef..329666b 100644 --- a/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/update-external-data.sh +++ b/Linux/external-data-mirror/ansible/roles/mirror-data/tasks/update-external-data.sh @@ -1,6 +1,7 @@ #! /bin/bash SERVER_IP=${1} +FTP_SRV_DIR=${2} RSYNC_PROCESS_IDS=$(pidof rsync) @@ -8,7 +9,7 @@ printf "%(%H:%M:%S)T " if [ -z "${RSYNC_PROCESS_IDS}" ]; then echo "running rsync..." - rsync -az --perms -o -g $SERVER_IP:/srv/$SERVER_IP/ftp/external-data/MD5/ /external-data/MD5/ + rsync -az --perms -o -g $SERVER_IP:/srv/$FTP_SRV_DIR/ftp/external-data/MD5/ /external-data/MD5/ else echo "rsync is already running. Skipping this time..." -fi \ No newline at end of file +fi