aboutsummaryrefslogtreecommitdiffstats
path: root/roles/nfsclient/tasks/main.yml
blob: 79caf84a71de16dbd7f39d55ed8649073f6ec7ad (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

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

---

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

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

- name: ensure directory exists on remote server
  file:
    path: "{{ nfsclient_server_dir }}"
    owner: "0"
    group: "0"
    mode: "755"
    state: directory
  delegate_to: "{{ nfsclient_server_.ansible_host }}"

- name: ensure directory exists on client
  file:
    path: "{{ nfsclient_dir }}"
    owner: "0"
    group: "0"
    mode: "755"
    state: directory
  register: result
  failed_when:
    - result.failed
    - '"Errno 17" not in result.msg'

- 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
  register: result

- 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: mount -a
  ignore_errors: true

- name: reload facts
  setup:

- name: display mounted volumes 
  debug:
    var: ansible_mounts
remember that computers suck.