# /etc/exports: the access control list for filesystems which may be exported# to NFS clients. See exports(5).## Example for NFSv2 and NFSv3:# /srv/homes hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)## Example for NFSv4:# /srv/nfs4 gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)# /srv/nfs4/homes gss/krb5i(rw,sync,no_subtree_check)#/nfs 10.0.0.1/24(rw,sync,no_root_squash,no_subtree_check)
nfs-server.yml
1234567891011121314151617181920212223242526
----hosts:nfs_serverremote_user:ubuntusudo:yestasks:-name:Create mountable dirfile:path=/share state=directory mode=777 owner=root group=root-name:make sure the mount drive has a filesystemfilesystem:fstype=ext4 dev={{ mountable_share_drive | default('/dev/xvdb') }}-name:set mountpointsmount:name=/share src={{ mountable_share_drive | default('/dev/xvdb') }} fstype=auto opts=defaults,nobootwait dump=0 passno=2 state=mounted-name:Ensure NFS utilities are installed.apt:name={{ item }} state=installed update_cache=yeswith_items:-nfs-common-nfs-kernel-server-name:copy /etc/exportstemplate:src=exports.j2 dest=/etc/exports owner=root group=root-name:restart nfs serverservice:name=nfs-kernel-server state=restarted
nfs_clients.yml
12345678910111213
-hosts:nfs_clientsremote_user:ubuntusudo:yestasks:-name:Ensure NFS common is installed.apt:name=nfs-common state=installed update_cache=yes-name:Create mountable dirfile:path=/nfs state=directory mode=777 owner=root group=root-name:set mountpointsmount:name=/nfs src={{hostvars[groups['nfs_server'][0]]['ansible_eth0']['ipv4']['address']}}:/share fstype=nfs opts=defaults,nobootwait dump=0 passno=2 state=mounted