Ansible-完成NFS网络文件系统搭建

1.roles/nfs/tasks/main.yml

# 配置文件中指定共享目录
echo '
/data/zh    172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/data/kod   172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)

/data/zrlog 172.16.1.0/24(rw,sync,all_squash,anonuid=53,anongid=53)
' > /etc/exports

# 创建共享目录
mkdir /data/{zh,zrlog,kod} -p
chown www.www -R /data
chown tomcat.tomcat -R /data/kod

# 启动服务并加入开机自启
systemctl start nfs
systemctl enable nfs

2.roles/nfs/handlers/main.yml

# 重启nfs服务端使配置文件生效
systemctl restart nfs
- name: Restart nfs
  systemd:
    name: nfs
    state: restarted

3.roles/nfs/templates/exports.j2

/data/zh     172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)
/data/kod    172.16.1.0/24(rw,sync,all_squash,anonuid=666,anongid=666)

/data/zrlog  172.16.1.0/24(rw,sync,all_squash,anonuid=53,anongid=53)

你可能感兴趣的:(Ansible-完成NFS网络文件系统搭建)