forked from mantidproject/dockerfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
Linux/external-data-mirror/ansible/roles/mirror/defaults/main.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# 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 |
44 changes: 44 additions & 0 deletions
44
Linux/external-data-mirror/ansible/roles/mirror/tasks/exchange-keys.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
- name: Generate key pair if it does not exist | ||
community.crypto.openssh_keypair: | ||
force: no # Don't regenerate existing keys. | ||
path: ~/.ssh/id_rsa | ||
|
||
- name: Read public key into tmp to copy over. | ||
fetch: | ||
src: ~/.ssh/id_rsa.pub | ||
dest: /tmp/{{ ansible_hostname }}-id_rsa.pub | ||
flat: yes | ||
|
||
- name: Add public key to main server's authorized keys | ||
ansible.posix.authorized_key: | ||
user: "{{ main_server_user }}" | ||
key: "{{ lookup('file','/tmp/{{ ansible_hostname }}-id_rsa.pub')}}" | ||
remote_user: "{{ main_server_user }}" | ||
delegate_to: "{{ main_server_ip }}" | ||
|
||
- name: Touch the known_hosts file if it's missing | ||
file: | ||
path: ~/.ssh/known_hosts | ||
state: touch | ||
mode: 0644 | ||
|
||
- name: Check if known_hosts contains existing server fingerprint | ||
command: ssh-keygen -F {{ main_server_user }} | ||
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 }} | ||
register: keyscan | ||
failed_when: keyscan.rc != 0 or keyscan.stdout == '' | ||
changed_when: False | ||
when: key_exists.rc == 1 | ||
|
||
- name: Copy ssh-key to local known_hosts | ||
lineinfile: | ||
name: ~/.ssh/known_hosts | ||
create: yes | ||
line: "{{ item }}" | ||
when: key_exists.rc == 1 | ||
with_items: "{{ keyscan.stdout_lines|default([]) }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters