75 lines
3.6 KiB
YAML
75 lines
3.6 KiB
YAML
---
|
|
- name: Setup NFS Storage for Consul Cluster
|
|
hosts: localhost
|
|
gather_facts: false
|
|
vars:
|
|
nfs_server: snail
|
|
nfs_export_path: /fs/1000/nfs/Fnsync
|
|
nfs_mount_path: /mnt/fnsync
|
|
|
|
tasks:
|
|
- name: Install NFS client and mount on master
|
|
ansible.builtin.shell: |
|
|
ssh -o StrictHostKeyChecking=no -p 60022 ben@master '
|
|
echo "3131" | sudo -S apt update &&
|
|
echo "3131" | sudo -S apt install -y nfs-common &&
|
|
echo "3131" | sudo -S mkdir -p {{ nfs_mount_path }} &&
|
|
echo "3131" | sudo -S mount -t nfs {{ nfs_server }}:{{ nfs_export_path }} {{ nfs_mount_path }} &&
|
|
echo "{{ nfs_server }}:{{ nfs_export_path }} {{ nfs_mount_path }} nfs defaults 0 0" | echo "3131" | sudo -S tee -a /etc/fstab
|
|
'
|
|
delegate_to: localhost
|
|
register: master_result
|
|
|
|
- name: Install NFS client and mount on ash3c
|
|
ansible.builtin.shell: |
|
|
ssh -o StrictHostKeyChecking=no ben@ash3c '
|
|
echo "3131" | sudo -S apt update &&
|
|
echo "3131" | sudo -S apt install -y nfs-common &&
|
|
echo "3131" | sudo -S mkdir -p {{ nfs_mount_path }} &&
|
|
echo "3131" | sudo -S mount -t nfs {{ nfs_server }}:{{ nfs_export_path }} {{ nfs_mount_path }} &&
|
|
echo "{{ nfs_server }}:{{ nfs_export_path }} {{ nfs_mount_path }} nfs defaults 0 0" | echo "3131" | sudo -S tee -a /etc/fstab
|
|
'
|
|
delegate_to: localhost
|
|
register: ash3c_result
|
|
|
|
- name: Install NFS client and mount on warden
|
|
ansible.builtin.shell: |
|
|
ssh -o StrictHostKeyChecking=no ben@warden '
|
|
echo "3131" | sudo -S apt update &&
|
|
echo "3131" | sudo -S apt install -y nfs-common &&
|
|
echo "3131" | sudo -S mkdir -p {{ nfs_mount_path }} &&
|
|
echo "3131" | sudo -S mount -t nfs {{ nfs_server }}:{{ nfs_export_path }} {{ nfs_mount_path }} &&
|
|
echo "{{ nfs_server }}:{{ nfs_export_path }} {{ nfs_mount_path }} nfs defaults 0 0" | echo "3131" | sudo -S tee -a /etc/fstab
|
|
'
|
|
delegate_to: localhost
|
|
register: warden_result
|
|
|
|
- name: Test NFS connectivity on all nodes
|
|
ansible.builtin.shell: |
|
|
ssh -o StrictHostKeyChecking=no -p 60022 ben@master 'echo "3131" | sudo -S touch {{ nfs_mount_path }}/test-master-$(date +%s) && ls -la {{ nfs_mount_path }}/'
|
|
ssh -o StrictHostKeyChecking=no ben@ash3c 'echo "3131" | sudo -S touch {{ nfs_mount_path }}/test-ash3c-$(date +%s) && ls -la {{ nfs_mount_path }}/'
|
|
ssh -o StrictHostKeyChecking=no ben@warden 'echo "3131" | sudo -S touch {{ nfs_mount_path }}/test-warden-$(date +%s) && ls -la {{ nfs_mount_path }}/'
|
|
delegate_to: localhost
|
|
register: nfs_test_result
|
|
|
|
- name: Display NFS test results
|
|
ansible.builtin.debug:
|
|
var: nfs_test_result.stdout_lines
|
|
|
|
- name: Create Consul data directories on NFS
|
|
ansible.builtin.shell: |
|
|
ssh -o StrictHostKeyChecking=no -p 60022 ben@master 'echo "3131" | sudo -S mkdir -p {{ nfs_mount_path }}/consul-master'
|
|
ssh -o StrictHostKeyChecking=no ben@ash3c 'echo "3131" | sudo -S mkdir -p {{ nfs_mount_path }}/consul-ash3c'
|
|
ssh -o StrictHostKeyChecking=no ben@warden 'echo "3131" | sudo -S mkdir -p {{ nfs_mount_path }}/consul-warden'
|
|
delegate_to: localhost
|
|
register: consul_dirs_result
|
|
|
|
- name: Display setup completion
|
|
ansible.builtin.debug:
|
|
msg:
|
|
- "NFS setup completed successfully!"
|
|
- "NFS mount point: {{ nfs_mount_path }}"
|
|
- "Consul data directories created:"
|
|
- " - {{ nfs_mount_path }}/consul-master"
|
|
- " - {{ nfs_mount_path }}/consul-ash3c"
|
|
- " - {{ nfs_mount_path }}/consul-warden" |