aboutsummaryrefslogtreecommitdiffstats
path: root/roles/nfsclient/tasks/main.yml
blob: f84c926208d79c12315f17431a7621ab9cf134ef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

# nfsclient ~~ roles/nfsclient/tasks/main.yml
# setup nfs client for a given server

---

- name: fallback to default nfs server
  set_fact:
    nfsclient_server: "{{ global.nfs_server }}"
  when: nfsclient_server is not defined

- name: fallback default nfs server directory
  set_fact:
    nfsclient_server_dir: "{{ global.nfs_server_dir }}"
  when: nfsclient_server_dir is not defined

- name: translate server string to server dict if not
  set_fact:
    nfsclient_server: "{{ hostvars[nfsclient_server] }}"

- name: include distribution specific prerequisites
  include_tasks: "_{{ ansible_distribution | lower }}.yml"
  ignore_errors: true

- name: ensure tmp directory exists for testing nfsd
  file:
    path: "{{ nfsclient_test_dir }}"
    owner: 0
    group: 0
    mode: 0700
    state: directory

- name: test nfs setup
  shell: mount -t nfs "{{ nfsclient_server.ip.out }}:{{ nfsclient_server_dir }}" /tmp/nfsd-test

- name: cleanup fstab with previous nfs setup
  lineinfile:
    path: /etc/fstab
    regexp: ^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}:/.* {{ nfsclient_dir }} nfs
    state: absent

- name: complete fstab with nfs
  lineinfile:
    path: /etc/fstab
    line: "{{ nfsclient_server.ip.out }}:{{ nfsclient_server_dir }} {{ nfsclient_dir }} nfs rw,nodev,nosuid 0 0"

- name: reload fstab
  shell: |
    umount -af -t nfs
    mount -a
  ignore_errors: true

- name: remove nfs test directory
  file:
    path: "{{ nfsclient_test_dir }}"
    state: absent

- name: register mounted volumes
  shell: df -P | grep nfs
  register: out

- name: display mounted volumes 
  debug:
    msg: |
      {{ out.stdout_lines }}
      {{ out.stderr_lines }}
remember that computers suck.