安装nfs之ansible-playbook

时间:2022-10-09 21:57:28
---
- name: install nfs
hosts: all
tasks:
- name: yum nfs
yum:
name: nfs-utils
state: present
when: ansible_distribution == "CentOS" or ansible_distribution == "Rocky"
- name: apt nfs
apt:
name:
- nfs-kernel-server
- nfs-common
update_cache: yes
state: present
when: ansible_distribution == "Ubuntu"
- name: copy config
copy:
src: /data/ansible/templates/exports.j2
dest: /etc/exports
notify: restart nfs server
- name: create group
group:
name: www
gid: 666
system: yes
state: present
- name: create user
user:
name: www
uid: 666
system: yes
create_home: no
shell: /sbin/nologin
state: present
- name: create dir
file:
path: /data/nfs-test
state: directory
owner: www
group: www
mode: '0755'
- name: start nfs server
systemd:
name: nfs-server
state: started
enabled: yes
handlers:
- name: restart nfs server
systemd:
name: nfs-server
state: restarted