AnsiblePilot — Master Ansible Automation

AnsiblePilot is the leading resource for learning Ansible automation, DevOps, and infrastructure as code. Browse over 1,100 tutorials covering Ansible modules, playbooks, roles, collections, and real-world examples. Whether you are a beginner or an experienced engineer, our step-by-step guides help you automate Linux, Windows, cloud, containers, and network infrastructure.

Popular Topics

About Luca Berton

Luca Berton is an Ansible automation expert, author of "Ansible for VMware by Examples" and "Ansible for Kubernetes by Example" published by Apress, and creator of the Ansible Pilot YouTube channel. He shares practical automation knowledge through tutorials, books, and video courses to help IT professionals and DevOps engineers master infrastructure automation.

Efficient NFS Server Setup with Ansible on Red Hat — Video Tutorial

Learn to automate the installation and configuration of an NFS server on Red Hat using an Ansible playbook. Enhance your system's efficiency now.

Watch Video

Watch "Efficient NFS Server Setup with Ansible on Red Hat" on YouTube

What You'll Learn

Full Tutorial Content

How to export NFS Share in RedHat-like Linux systems with Ansible? I'm going to show you a live Playbook with some simple Ansible code. I'm Luca Berton and welcome to today's episode of Ansible Pilot. Export an NFS Share in RedHat-like systems - install packages => `ansible.builtin.yum` - create directory => `ansible.builtin.file` - share in config => `ansible.builtin.lineinfile` - export shares => `ansible.builtin.command` - restart service => `ansible.builtin.service` - open firewall => `ansible.posix.firewalld` Today we're talking about how to export an NFS Share in RedHat-like Linux systems. The full process requires six steps that you could automate with six different Ansible modules. Firstly you need to install the `nfs-utils` package and dependency using the `ansible.builtin.yum` Ansible module. Secondly, you need to create the share directory and assign the permission using the `ansible.builtin.file` Ansible module. Thirdly you need to add the share in the `/etc/exports` config file using the `ansible.builtin.lineinfile` Ansible module to add text lines in files. Fourthly you need to export shares executing the `exportfs` command line utility via `ansible.builtin.command` Ansible module, unfortunately there is not a specific module, yet. Fifthly you need to restart the `nfs-server` service and all the dependant using the `ansible.builtin.service` Ansible module. Sixthly you need to open the relevant firewall service-related ports using the `ansible.posix.firewalld` Ansible module. ## Playbook Export NFS Share in RedHat-like systems with Ansible Playbook. code - nfs_server_redhat.yml ```yaml --- - name: nfs service Playbook hosts: all become: true vars: share: "/nfs/share" options: "192.168.0.0/24(rw,sync,root_squash)" permission: '0777' tasks: - name: NFS server installed ansible.builtin.yum: name: - nfs-utils - nfs4-acl-tools state: present - name: share directory exists ansible.builtin.file: path: "{{ share }}" state: directory mode: "{{ permission }}" owner: root group: root - name: share in /etc/exports file ansible.builtin.lineinfile: path: /etc/exports state: present line: '{{ share }} {{ options }}' notify: restart NFS server - name: export share ansible.builtin.command: "exportfs -rav" - name: firewall enabled ansible.posix.firewalld: service: "{{ item }}" state: enabled permanent: true immediate: true with_items: - nfs - rpc-bind - mountd handlers: - name: restart NFS server ansible.builtin.service: name: nfs-server state: restarted enabled: true ``` execution ```bash $ ansible-playbook -i virtualmachines/demo/inventory services/nfs_redhat.yml PLAY [nfs service Playbook] **********************************************************************

About This Tutorial

Read the full written article: Efficient NFS Server Setup with Ansible on Red Hat

Topics Covered

Related Video Tutorials