├── ansible.cfg ├── vars ├── main.yml └── RedHat.yml ├── defaults └── main.yml ├── templates └── exports.j2 ├── handlers └── main.yml ├── test.yml ├── meta └── main.yml ├── tasks ├── main.yml └── setup-RedHat.yml └── README.md /ansible.cfg: -------------------------------------------------------------------------------- 1 | [defaults] 2 | roles_path = ../ 3 | -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for nfs 3 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # defaults file nfs 3 | 4 | nfs_exports: [] 5 | -------------------------------------------------------------------------------- /vars/RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for RedHat 3 | 4 | nfs_server_daemon: nfs 5 | -------------------------------------------------------------------------------- /templates/exports.j2: -------------------------------------------------------------------------------- 1 | {% for export in nfs_exports %} 2 | {{ export }} 3 | {% endfor %} 4 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for nfs 3 | 4 | - name: restart nfs 5 | service: "name={{ nfs_server_daemon }} state=restarted" 6 | -------------------------------------------------------------------------------- /test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # test for RedHat/CentOS 3 | 4 | - name: Install NFS server. 5 | hosts: nfs 6 | vars: 7 | nfs_exports: 8 | - "/opt *(rw,sync,no_root_squash)" 9 | - "/mnt *(rw,sync,no_root_squash)" 10 | roles: 11 | - ansible-role-nfs 12 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: z 4 | description: NFS installation for Linux. 5 | company: 6 | license: license (BSD, MIT) 7 | min_ansible_version: 1.8 8 | platforms: 9 | - name: EL 10 | versions: 11 | - 6 12 | - 7 13 | categories: 14 | - system 15 | dependencies: [] 16 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for nfs 3 | 4 | # Include variables and define needed variables. 5 | - name: Include OS-specific variables. 6 | include_vars: "{{ ansible_os_family }}.yml" 7 | 8 | # Setup/install tasks. 9 | - include: setup-RedHat.yml 10 | when: ansible_os_family == 'RedHat' 11 | 12 | - name: Copy exports file. 13 | template: 14 | src: exports.j2 15 | dest: /etc/exports 16 | owner: root 17 | group: root 18 | mode: 0644 19 | notify: restart nfs 20 | 21 | - name: Ensure nfs is running. 22 | service: name={{ nfs_server_daemon }} state=started 23 | -------------------------------------------------------------------------------- /tasks/setup-RedHat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # tasks file for RedHat 3 | 4 | - name: Ensure NFS utilities are installed. 5 | yum: name=nfs-utils state=installed 6 | 7 | - name: Ensure rpcbind is running. 8 | service: name=rpcbind state=started enabled=yes 9 | 10 | - name: Ensure nfs is start on boot when RedHat/CentOS 6. 11 | service: name={{ nfs_server_daemon }} enabled=yes 12 | when: ansible_os_family == 'RedHat' and ansible_distribution_major_version == '6' 13 | 14 | - name: Ensure nfs is start on boot when RedHat/CentOS 7. 15 | service: name=nfs-server enabled=yes 16 | when: ansible_os_family == 'RedHat' and ansible_distribution_major_version == '7' 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role: nfs 2 | 3 | Installs NFS utilities on RedHat/CentOS. 4 | 5 | ## Requirements 6 | 7 | None. 8 | 9 | ## Role Variables 10 | 11 | ### `defaults/main.yml` 12 | 13 | * `nfs_exports: []` 14 | 15 | A list of exports which will be placed in the `/etc/exports` file. 16 | ``` 17 | Simple example: 18 | nfs_exports: { "/home/public *(rw,sync,no_root_squash)" } 19 | nfs_exports: 20 | - "/home/public1 *(rw,sync,no_root_squash)" 21 | - "/home/public2 *(rw,sync,no_root_squash)" 22 | ``` 23 | 24 | ## Dependencies 25 | 26 | None. 27 | 28 | ## Example Playbook 29 | 30 | - hosts: servers 31 | vars: 32 | nfs_exports: { "/home/public *(rw,sync,no_root_squash)" } 33 | roles: 34 | - nfs 35 | 36 | ## Author Information 37 | 38 | z 39 | --------------------------------------------------------------------------------