From 6d370e3104d8612c7320fd0a4628050e28b4d845 Mon Sep 17 00:00:00 2001 From: Beth Parker Date: Thu, 28 Sep 2017 11:34:36 -0500 Subject: [PATCH] Moved to autofs for sshfs and nfs --- merge.sh | 1 + pillars/roles/mount/deluge.sls | 1 + pillars/roles/mount/gitlab.sls | 1 + pillars/roles/mount/pkg-cache.sls | 1 + pillars/roles/mount/plexmediaserver.sls | 3 +- pillars/roles/mount/radarr.sls | 1 + pillars/roles/mount/saltmaster.sls | 4 +- pillars/roles/mount/sonarr.sls | 1 + states/systems/core/mount/auto.master | 2 + states/systems/core/mount/auto.nfs | 8 +++ states/systems/core/mount/auto.ssh | 13 ++++ states/systems/core/mount/init.sls | 83 +++++++++++++++++-------- 12 files changed, 91 insertions(+), 28 deletions(-) create mode 100644 states/systems/core/mount/auto.master create mode 100644 states/systems/core/mount/auto.nfs create mode 100644 states/systems/core/mount/auto.ssh diff --git a/merge.sh b/merge.sh index 0ffba61..574a29e 100644 --- a/merge.sh +++ b/merge.sh @@ -16,3 +16,4 @@ git push; git checkout dev; git reset --hard master; git push --force; +git reset --hard origin/dev diff --git a/pillars/roles/mount/deluge.sls b/pillars/roles/mount/deluge.sls index 4e41a33..8963ce2 100644 --- a/pillars/roles/mount/deluge.sls +++ b/pillars/roles/mount/deluge.sls @@ -1,6 +1,7 @@ mount: sshfs: /mnt/video: + name: video host: host.actcur.com directory: /mnt/butter/video user: mount diff --git a/pillars/roles/mount/gitlab.sls b/pillars/roles/mount/gitlab.sls index bd3f92b..5718462 100644 --- a/pillars/roles/mount/gitlab.sls +++ b/pillars/roles/mount/gitlab.sls @@ -1,6 +1,7 @@ mount: sshfs: /mnt/repos: + name: repos host: host.actcur.com directory: /mnt/butter/repos user: gitlab diff --git a/pillars/roles/mount/pkg-cache.sls b/pillars/roles/mount/pkg-cache.sls index 568ac3c..5748f28 100644 --- a/pillars/roles/mount/pkg-cache.sls +++ b/pillars/roles/mount/pkg-cache.sls @@ -1,6 +1,7 @@ mount: sshfs: /mnt/pkgs: + name: pkgs host: host.actcur.com directory: /mnt/butter/pkgs user: pkgs diff --git a/pillars/roles/mount/plexmediaserver.sls b/pillars/roles/mount/plexmediaserver.sls index 3b412fb..8724afe 100644 --- a/pillars/roles/mount/plexmediaserver.sls +++ b/pillars/roles/mount/plexmediaserver.sls @@ -1,14 +1,15 @@ mount: sshfs: /mnt/video: + name: video host: host.actcur.com directory: /mnt/butter/video user: mount /mnt/music: + name: music host: host.actcur.com directory: /mnt/butter/music user: mount ext4: /var/lib/plexmediaserver/Library: device: UUID=0ab3f7fc-6525-40ba-905c-ff5fff2de1a3 - diff --git a/pillars/roles/mount/radarr.sls b/pillars/roles/mount/radarr.sls index 4e41a33..8963ce2 100644 --- a/pillars/roles/mount/radarr.sls +++ b/pillars/roles/mount/radarr.sls @@ -1,6 +1,7 @@ mount: sshfs: /mnt/video: + name: video host: host.actcur.com directory: /mnt/butter/video user: mount diff --git a/pillars/roles/mount/saltmaster.sls b/pillars/roles/mount/saltmaster.sls index 120fab5..d8ce90c 100644 --- a/pillars/roles/mount/saltmaster.sls +++ b/pillars/roles/mount/saltmaster.sls @@ -1,10 +1,12 @@ mount: sshfs: /mnt/backups: + name: backups host: host.actcur.com directory: /mnt/butter/backups/configurations user: backups - /secure/ca/: + /secure/ca: + name: ca host: ca.actcur.com directory: /etc/easy-rsa/pki/ user: ca diff --git a/pillars/roles/mount/sonarr.sls b/pillars/roles/mount/sonarr.sls index 4e41a33..8963ce2 100644 --- a/pillars/roles/mount/sonarr.sls +++ b/pillars/roles/mount/sonarr.sls @@ -1,6 +1,7 @@ mount: sshfs: /mnt/video: + name: video host: host.actcur.com directory: /mnt/butter/video user: mount diff --git a/states/systems/core/mount/auto.master b/states/systems/core/mount/auto.master new file mode 100644 index 0000000..5a0f2fe --- /dev/null +++ b/states/systems/core/mount/auto.master @@ -0,0 +1,2 @@ +/mnt/autofs/ssh /etc/autofs/auto.ssh +/mnt/autofs/nfs /etc/autofs/auto.nfs diff --git a/states/systems/core/mount/auto.nfs b/states/systems/core/mount/auto.nfs new file mode 100644 index 0000000..b0a3c8d --- /dev/null +++ b/states/systems/core/mount/auto.nfs @@ -0,0 +1,8 @@ +{%- if nfs is defined -%} + {% for mount in nfs -%} + {%- set host=nfs[mount]['host'] -%} + {%- set dir=nfs[mount]['directory'] %} + {%- set name=nfs[mount]['name'] %} +{{name}} -rw,soft,intr,rsize=8192,wsize=8192 {{host}}:{{dir}} + {%- endfor -%} +{% endif %} diff --git a/states/systems/core/mount/auto.ssh b/states/systems/core/mount/auto.ssh new file mode 100644 index 0000000..bb34016 --- /dev/null +++ b/states/systems/core/mount/auto.ssh @@ -0,0 +1,13 @@ +{%- if sshfs is defined -%} + {% for mount in sshfs -%} + {%- if sshfs[mount]['user'] is defined -%} + {%- set user=sshfs[mount]['user'] -%} + {%- else -%} + {%- set user="mount" -%} + {%- endif -%} + {%- set host=sshfs[mount]['host'] -%} + {%- set dir=sshfs[mount]['directory'] %} + {%- set name=sshfs[mount]['name'] %} +{{name}} -fstype=fuse,rw,allow_other,idmap=user,IdentityFile=/root/.ssh/{{user}}_key :sshfs\#{{user}}@{{host}}\:{{dir}} + {%- endfor -%} +{% endif %} diff --git a/states/systems/core/mount/init.sls b/states/systems/core/mount/init.sls index 0b72676..5e08ff2 100644 --- a/states/systems/core/mount/init.sls +++ b/states/systems/core/mount/init.sls @@ -16,6 +16,27 @@ {%- endfor -%} {% endif %} +autofs-pkg: + pkg.installed: + - name: autofs + service.running: + - name: autofs + - watch: + - file: /etc/autofs/auto.master + {%- if pillar['mount']['sshfs'] is defined %} + - file: /etc/autofs/auto.ssh + {% endif -%} + {%- if pillar['mount']['nfs'] is defined %} + - file: /etc/autofs/auto.nfs + {% endif %} + +autofs-master: + file.managed: + - name: /etc/autofs/auto.master + - source: salt://systems/core/mount/auto.master + - user: root + - group: root + - mode: 644 {%- if pillar['mount']['sshfs'] is defined %} fuse2: @@ -26,6 +47,17 @@ fuse-module: kmod.present: - name: fuse - persist: true + +/etc/autofs/auto.ssh: + file.managed: + - source: salt://systems/core/mount/auto.ssh + - user: root + - group: root + - mode: 644 + - template: jinja + - context: + sshfs: {{pillar['mount']['sshfs']}} + mount_host.actcur.com: ssh_known_hosts.present: - name: host.actcur.com @@ -40,8 +72,7 @@ mount_host.actcur.com: {%- else -%} {%- set user="mount" -%} {%- endif -%} - {%- set host=pillar['mount']['sshfs'][mount]['host'] -%} - {%- set dir=pillar['mount']['sshfs'][mount]['directory'] %} + {%- set name=pillar['mount']['sshfs'][mount]['name'] %} {{ mount }}_key: file.managed: - name: /root/.ssh/{{user}}_key @@ -51,17 +82,12 @@ mount_host.actcur.com: - mode: 600 - makedirs: true -{{ mount }}: - file.directory: [] - mount.mounted: - - device: {{user}}@{{host}}:{{dir}} - - fstype: fuse.sshfs - - mkmnt: True - - opts: allow_other,user,IdentityFile=/root/.ssh/{{user}}_key,delay_connect,x-systemd.automount,_netdev,idmap=user,reconnect - - hidden_opts: allow_other,user,IdentityFile=/root/.ssh/{{user}}_key,delay_connect,x-systemd.automount,_netdev,idmap=user,reconnect - - dump: 0 - - pass_num: 2 - - persist: True +{{ mount }}_link: + file.symlink: + - name: {{ mount }} + - target: /mnt/autofs/ssh/{{name}} + - force: true + - makedirs: true {%- endfor -%} {% endif %} @@ -81,20 +107,25 @@ remote-fs.target: service.running: - enable: true -{% for mount in pillar['mount']['nfs'] %} - {%- set host=pillar['mount']['nfs'][mount]['host'] -%} - {%- set dir=pillar['mount']['nfs'][mount]['directory'] %} +/etc/autofs/auto.nfs: + file.managed: + - source: salt://systems/core/mount/auto.nfs + - user: root + - group: root + - mode: 644 + - template: jinja + - context: + nfs: {{pillar['mount']['nfs']}} -{{ mount }}: - mount.mounted: - - device: {{host}}:{{dir}} - - fstype: nfs - - mkmnt: True - - opts: defaults,noauto,,x-systemd.timeout=10,x-systemd.automount - - hidden_opts: defaults,noauto,,x-systemd.timeout=10,x-systemd.automount - - dump: 0 - - pass_num: 2 - - persist: True +{% for mount in pillar['mount']['nfs'] %} + {%- set name=pillar['mount']['nfs'][mount]['name'] %} + +{{ mount }}_link: + file.symlink: + - name: {{ mount }} + - target: /mnt/autofs/ssh/{{name}} + - force: true + - makedirs: true {%- endfor -%} {% endif %}