{"id":1425,"date":"2024-06-19T05:18:24","date_gmt":"2024-06-19T05:18:24","guid":{"rendered":"http:\/\/shijuvarghese.com\/?p=1425"},"modified":"2025-05-23T19:02:28","modified_gmt":"2025-05-23T19:02:28","slug":"ansible-install-nfs-mounts-nfs-server-installation-included","status":"publish","type":"post","link":"http:\/\/shijuvarghese.com\/?p=1425","title":{"rendered":"Ansible: Install NFS mounts (NFS server installation included)"},"content":{"rendered":"<p>NFS, or Network File Share is a service that allows client to store and share files and folders that will be stored in a centralized server.<\/p>\n<p>Installing NFS server on RHEL 9 node is straight forwards. Here we are going to configure the Ansible server itself to host the NFS server too. The procedure is as follows:<\/p>\n<p>&nbsp;<\/p>\n<p><strong>[root@centos9vm ~]#<\/strong> mkdir \/centos9vm_share<br \/>\n<strong>[root@centos9vm ~]#<\/strong> touch \/centos9vm_share\/file_1<br \/>\n<strong>[root@centos9vm ~]#<\/strong> dnf install nfs-utils -y<br \/>\n<strong>[root@centos9vm ~]#<\/strong> echo &#8220;\/centos9vm_share *(ro)&#8221; &gt;&gt; \/etc\/exports<\/p>\n<p>======<br \/>\n<strong>[root@centos9vm ~]#<\/strong> systemctl start nfs-server rpcbind<br \/>\n<strong>[root@centos9vm ~]#<\/strong> systemctl enable nfs-server rpcbind<\/p>\n<p>======<br \/>\n<strong>[root@centos9vm ~]#<\/strong> showmount -e localhost<br \/>\nExport list for localhost:<br \/>\n\/centos9vm_share *<\/p>\n<p>======<\/p>\n<p>Now let us see if we can attach this mountpoint on a client node 192.168.48.129. Let us create a playbook.<\/p>\n<p><strong>[root@centos9vm ~]#<\/strong> cat mount_nfs.yml<\/p>\n<p>==== ==<br \/>\n<em>&#8211;\u00a0 &#8211; &#8211;<\/em><br \/>\n<em>&#8211; name: Playbook to mount NFS shared storage<\/em><br \/>\n<em> &nbsp; &nbsp; hosts: 192.168.48.129<\/em><br \/>\n<em> &nbsp; &nbsp; tasks:<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &#8211; name: Task to mount NFS share<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ansible.posix.mount:<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; src: 192.168.48.128:\/centos9vm_share<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; path: \/mnt<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; state: mounted<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fstype: nfs<\/em><\/p>\n<p>==== ===<\/p>\n<p><strong>[root@<span style=\"color: #ff6600;\">centosMYOBvm <\/span>~]#<\/strong> df -h | grep mnt<\/p>\n<p>There will none when running the above command as we have unmounted the mount during the first half of this exercise. Now let us run the playbook on the controller node.<\/p>\n<p><strong>[root@centos9vm ~]#<\/strong> ansible-navigator run -m stdout mount_nfs.yml<\/p>\n<p>=== === =<\/p>\n<p><em>PLAY [Playbook to mount NFS shared storage] ************************************<\/em><\/p>\n<p><em>TASK [Gathering Facts] *********************************************************<\/em><\/p>\n<p><em>ok: [192.168.48.129]<\/em><\/p>\n<p><em>TASK [Task to mount NFS share] *************************************************<\/em><br \/>\n<em>changed: [192.168.48.129]<\/em><\/p>\n<p><em>PLAY RECAP *********************************************************************<\/em><br \/>\n<em>192.168.48.129 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0<\/em><\/p>\n<p>==== ===<\/p>\n<p>Let us check back on the managed node again. This time the NFS share should be added.<\/p>\n<p><strong>[root@<span style=\"color: #ff6600;\">centosMYOBvm<\/span> ~]#<\/strong> df -h | grep mnt<br \/>\n<em>192.168.48.128:\/centos9vm_share 4.4G 3.0G 1.5G 68% \/mnt<\/em><\/p>\n<p>==== ===<\/p>\n<p>Now let us see if we can unmount the share using a small tweak in the same playbook, but with the &#8220;state&#8221; parameter replacing the existing one.<\/p>\n<p><strong>[root@centos9vm ~]#<\/strong> cat mount_nfs.yml<\/p>\n<p>===== ===<br \/>\n<em>&#8211; &#8211; &#8211;<\/em><br \/>\n<em>&#8211; name: Playbook to mount NFS shared storage<\/em><br \/>\n<em> &nbsp; &nbsp; hosts: 192.168.48.129<\/em><br \/>\n<em> &nbsp; &nbsp; tasks:<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &#8211; name: Task to mount NFS share<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ansible.posix.mount:<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; src: 192.168.48.128:\/centos9vm_share<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; path: \/mnt<\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; state: <strong>unmounted<\/strong><\/em><br \/>\n<em> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; fstype: nfs<\/em><br \/>\n==== ====<br \/>\n<strong>[root@centos9vm ~]#<\/strong> ansible-navigator run -m stdout mount_nfs.yml<\/p>\n<p><em>PLAY [Playbook to mount NFS shared storage] ************************************<\/em><\/p>\n<p><em>TASK [Gathering Facts] *********************************************************<\/em><br \/>\n<em>ok: [192.168.48.129]<\/em><\/p>\n<p><em>TASK [Task to mount NFS share] *************************************************<\/em><br \/>\n<em>changed: [192.168.48.129]<\/em><\/p>\n<p><em>PLAY RECAP *********************************************************************<\/em><br \/>\n<em>192.168.48.129 : ok=2 changed=1 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0<\/em><\/p>\n<p>=== ===<\/p>\n<p>Let us check back on the managed node now.<\/p>\n<p><strong>[root@<span style=\"color: #ff6600;\">centosMYOBvm<\/span> ~]#<\/strong> df -h | grep mnt<\/p>\n<p>We should not see any output now.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>NFS, or Network File Share is a service that allows client to store and share files and folders that will be stored in a centralized <a class=\"mh-excerpt-more\" href=\"http:\/\/shijuvarghese.com\/?p=1425\" title=\"Ansible: Install NFS mounts (NFS server installation included)\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":1792,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,21,3,11],"tags":[],"class_list":["post-1425","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ansible","category-devops","category-linux","category-nfs"],"_links":{"self":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1425","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1425"}],"version-history":[{"count":9,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1425\/revisions"}],"predecessor-version":[{"id":1435,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/posts\/1425\/revisions\/1435"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=\/wp\/v2\/media\/1792"}],"wp:attachment":[{"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1425"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1425"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shijuvarghese.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1425"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}