Skip to content

Commit

Permalink
mount: handle labels with spaces correctly, sanitize label input
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcDiethelm committed Mar 14, 2019
1 parent a80f199 commit 0357163
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 14 deletions.
18 changes: 12 additions & 6 deletions playbooks/mount.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@

tasks:

- include_role:
name: pmount
tasks_from: mount
with_dict: "{{ mounts }}"
when: task is undefined

# case: Add disk mount
###########################################
- block:
Expand Down Expand Up @@ -73,3 +67,15 @@
do_backup: no

when: task is defined and task == "delete"


# case: Re-mount all disks
###########################################
- block:

- include_role: # not using handlers because we want this to fail if input was bad
name: pmount
tasks_from: mount
with_dict: "{{ mounts }}"

when: task is undefined
15 changes: 7 additions & 8 deletions roles/pmount/tasks/mount.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
---
- name: "Check if disk is mounted: {{ item.key }}"
shell: pmount | grep {{ item.key }}
- name: "Check if disk is mounted: {{ item.key|quote }}"
shell: 'pmount | grep {{ item.key|quote }}'
register: grep
failed_when: "grep.rc == 2"
check_mode: no
changed_when: false

- debug:
msg: "Disk {{ item.key }} is already mounted."
msg: "Disk is already mounted: {{ item.key|quote }}"
when: grep.rc == 0


- block:

- name: "Ensure mount dir is absent before mounting"
- name: 'Ensure mount dir is absent before mounting: {{ mount_path|quote }}'
file:
path: "/media/{{ item.key }}"
path: '{{ mount_path|quote }}'
state: absent
become: yes

- name: "Mount disk {{ item.key }} to /media/{{ item.key }}."
shell: pmount /dev/disk/by-label/{{ item.key }} {{ item.key }}
- name: "Mount disk, label: {{ disk_path|quote }}, mount path: {{ mount_path|quote }}."
command: 'pmount {{ disk_path|quote }} {{ item.key|quote }}'

when: grep.rc == 1
3 changes: 3 additions & 0 deletions roles/pmount/vars/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
disk_path: '/dev/disk/by-label/{{ item.key }}'
mount_path: '/media/{{ item.key }}'

0 comments on commit 0357163

Please sign in to comment.