Debian Codegraph @

test/integration/targets/mount_facts/tasks/main.yml

raw
1 - name: Setup a NFS mount and test getting extended mount facts
2 become: yes
3 become_user: root
4 vars:
5 os_nfs_root:
6 Darwin: /opt # TODO: can remote_tmp_dir (in /private) work?
7 nfs_root: "{{ os_nfs_root[ansible_os_family] | default(remote_tmp_dir) }}"
8 nfs_source: "{{ [nfs_root, 'nfs_src'] | path_join }}"
9 nfs_mount: "{{ [nfs_root, 'nfs_mnt'] | path_join }}"
10 block:
11 - name: Setup - install NFS server and client packages (Debian)
12 package:
13 state: present
14 name:
15 - nfs-kernel-server
16 - nfs-common
17 when: ansible_os_family == 'Debian'
18
19 - name: Setup - install NFS server package (RedHat)
20 package:
21 name: nfs-utils
22 state: present
23 when: ansible_os_family == 'RedHat'
24
25 - name: Setup - install NFS server package (Alpine)
26 command: apk add nfs-utils
27 when: ansible_os_family == 'Alpine'
28
29 - name: Setup - create export directory on server
30 file:
31 path: "{{ nfs_source }}"
32 state: directory
33 mode: '0755'
34
35 - name: Setup - configure NFS exports (Linux)
36 copy:
37 dest: /etc/exports
38 content: |
39 {{ nfs_source }} 127.0.0.1(rw,no_root_squash)
40 when: ansible_os_family not in ('FreeBSD', 'Darwin')
41
42 - name: Setup - configure NFS exports (FreeBSD)
43 copy:
44 dest: /etc/exports
45 content: |
46 {{ nfs_source }} -alldirs -maproot=root localhost
47 V4: /
48 when: ansible_os_family == 'FreeBSD'
49
50 - name: Setup - configure NFS exports (Darwin)
51 copy:
52 dest: /etc/exports
53 content: |
54 {{ nfs_source }} -alldirs -maproot=root localhost
55 when: ansible_os_family == 'Darwin'
56
57 # https://docs.freebsd.org/en/books/handbook/network-servers/#network-nfs
58 - name: Setup - configure NFS server (FreeBSD)
59 lineinfile:
60 line: "{{ item.option }}={{ item.value }}"
61 regexp: "^{{ item.option }}=.+$"
62 path: /etc/rc.conf
63 loop:
64 - option: rpcbind_enable
65 value: "YES"
66 - option: nfs_server_enable
67 value: "YES"
68 - option: nfsv4_server_enable
69 value: "YES"
70 when: ansible_os_family == 'FreeBSD'
71
72 - name: Setup - restart nfs-server (Linux)
73 service:
74 name: nfs-server
75 state: restarted
76 when: ansible_os_family == 'Debian' or ansible_os_family == 'RedHat'
77
78 - name: Setup - restart nfsd (Darwin)
79 command: nfsd restart # log show --predicate 'process == "nfsd"' --info --last 5m
80 when: ansible_os_family == 'Darwin'
81
82 - name: Setup - start mountd and nfsd (FreeBSD)
83 shell: "service {{ item }} onestart || service {{ item }} onerestart"
84 loop:
85 - mountd
86 - nfsd
87 when: ansible_os_family == 'FreeBSD'
88 ignore_errors: true
89
90 # https://wiki.alpinelinux.org/wiki/Setting_up_an_NFS_server
91 - name: Setup - start nfs (Alpine)
92 command: rc-service nfs start
93 when: ansible_os_family == 'Alpine'
94
95 - name: Setup - reload NFS exports (Alpine)
96 command: exportfs -ra
97 when: ansible_os_family == 'Alpine'
98
99 - name: Setup - create mount point for the NFS client
100 file:
101 path: "{{ nfs_mount }}"
102 state: directory
103 mode: '0755'
104
105 - name: Setup - mount the NFS source with a timeout to prevent a hang
106 timeout: 2
107 block:
108 - name: Setup - mount the NFS source (Linux)
109 command: "mount -t nfs localhost:{{ nfs_source }} {{ nfs_mount}}"
110 when: ansible_os_family not in ('FreeBSD', 'Darwin')
111
112 - name: Setup - mount the NFS source (FreeBSD)
113 command: "mount -t nfs -o nfsv4 localhost:{{ nfs_source }} {{ nfs_mount }}"
114 when: ansible_os_family == 'FreeBSD'
115
116 - name: Setup - mount the NFS source (Darwin)
117 # TODO this syntax is deprecated, but adding '-o vers=4' to use nfsv4 fails with:
118 # mount_nfs: can't mount /opt/nfs from localhost onto /opt/nfs_mnt: RPC prog. not avail
119 # mount: /opt/nfs_mnt failed with 74
120 command: "mount -t nfs localhost:{{ nfs_source }} {{ nfs_mount }}"
121 when: ansible_os_family == 'Darwin'
122 timeout: 4 # 2 isn't cutting it
123
124 - name: Test gathering NFS mount facts
125 mount_facts:
126 mount_binary: "mount"
127 devices: "[!/]*"
128 fstypes:
129 - nfs
130 - nfs4
131
132 - assert:
133 that:
134 - nfs_mount in mount_points
135 - aggregate_mounts == []
136 - mount_points[nfs_mount]["device"] == ("localhost:" ~ nfs_source)
137
138 always:
139 - command: "umount {{ nfs_mount }}"
140
141 - name: Test collecting static and dynamic sources
142 block:
143 - name: Collect all static mounts
144 mount_facts:
145 sources:
146 - static
147 register: static
148
149 - name: Collect all dynamic mounts
150 mount_facts:
151 sources:
152 - dynamic
153 register: dynamic
154
155 - name: Collect dynamic mounts without file sources
156 mount_facts:
157 sources:
158 - mount
159 include_aggregate_mounts: true
160 register: dynamic_mount
161
162 - name: Test static mounts are found
163 assert:
164 that:
165 - static.ansible_facts.mount_points.keys() | length > 0
166 when: ansible_os_family != "Darwin" # No /etc/fstab
167
168 - name: Test dynamic mounts are found
169 assert:
170 that:
171 - dynamic.ansible_facts.mount_points.keys() | length > 0
172 - dynamic_mount.ansible_facts.mount_points.keys() | length > 0
173 - dynamic_mount.ansible_facts.aggregate_mounts | length > 0
174
175 - name: Test any devices have a UUID (Linux)
176 assert:
177 that:
178 - dynamic.ansible_facts.mount_points.values() | list | map(attribute='uuid') | unique | length > 0
179 - dynamic_mount.ansible_facts.mount_points.values() | list | map(attribute='uuid') | unique | length > 0
180 - static.ansible_facts.mount_points.values() | list | map(attribute='uuid') | unique | length > 0
181 when: ansible_os_family not in ("Darwin", "FreeBSD")
182
183 - name: Test duplicate sources
184 mount_facts:
185 sources:
186 - mount
187 - mount
188 include_aggregate_mounts: true
189 register: mount_repeated
190
191 - assert:
192 that:
193 - (mount_repeated.ansible_facts.aggregate_mounts | length) == (dynamic_mount.ansible_facts.aggregate_mounts | length)