ansible 安装nfs
2022-06-23 本文已影响0人
su酥饼
注此方法为离线安装,nfs安装包需要提前准备好,如果没有可更改nfs_install.yml文件中的nfs安装步骤(tasks 的第一步和第二步,可直接更改为yum安装)
这里222为server端 223、224为clien端
cat host_nfs
[nfs_master]
172.23.103.222
[nfs_client]
172.23.103.223
172.23.103.224
nfs_Install.yml
- name: Install NFS
hosts: nfs_master,nfs_client
remote_user: root
gather_facts: false
#此任务为下载安装 nfs,第一步和第二步也可用yum 安装代替
tasks:
- name: copy and tar nfs
unarchive: src=nfs.tar.gz dest=/tmp
- name: install nfs
shell: rpm -ivh /tmp/nfs/*.rpm --force --nodeps
#创建并授权共享存储目录
- name: mkdir dir
file:
path: /data/nfs
state: directory
mode: 0777
#在server端进行的配置
- name: install master
hosts: nfs_master
tasks:
- name: install master
shell:
cmd: |
echo "/data/nfs/ *(insecure,rw,sync,no_root_squash,no_all_squash)" > /etc/exports
systemctl enable rpcbind --now
systemctl enable nfs-server --now
exportfs -r
exportfs
#在客户端进行的配置
- name: install client
hosts: nfs_client
tasks:
- name: install client
shell:
cmd: |
systemctl enable rpcbind --now
systemctl enable nfs-server --now
showmount -e {{groups['nfs_master']|first}}
mount -t nfs {{groups['nfs_master']|first}}:/data/nfs /data/nfs
echo "{{groups['nfs_master']|first}}:/data/nfs /data/nfs nfs defaults 0 0">>/etc/fstab
执行剧本内容
ansible-playbook -i host_nfs nfs_Install.yml
查看
[root@nfs_client bin]# df -h
Filesystem Size Used Avail Use% Mounted on
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.9G 0 7.9G 0% /dev/shm
tmpfs 7.9G 8.7M 7.9G 1% /run
tmpfs 7.9G 0 7.9G 0% /sys/fs/cgroup
/dev/xvda3 495G 6.5G 489G 2% /
/dev/xvda2 497M 172M 325M 35% /boot
/dev/xvda6 498M 16K 498M 1% /boot/efi
tmpfs 1.6G 0 1.6G 0% /run/user/0
172.23.103.222:/data/nfs 1019G 9.1G 1010G 1% /data/nfs