实现多台的分离实现:
[root@localhost playbook]# cat example3.yaml
---
- hosts: 192.168.17.105remote_user: roottasks:- name: create test1 directoryfile: path=/test1/ state=directory- hosts: 192.168.17.106remote_user: roottasks:- name: create test2 directoryfile: path=/test2/ state=directory
剧本执行情况:
在105的机器上创建了test1目录。
在106的机器上创建了test2目录。
搭建nfs系统,并在另外一台机器上进行挂载操作。
[root@localhost playbook]# cat example4.yaml
---
- hosts: 192.168.17.105remote_user: roottasks:- name: install nfs softwareyum: name=nfs-utils,rpcbind,setup state=latest- name: create share folderfile: path=/share/ state=directory- name: sync nfs configurecopy: src=/etc/exports dest=/etc/exportsnotify: restart nfs- name: start rpcbind and enabled in bootservice: name=rpcbind state=started enabled=yes- name: start nfs and enabled in bootservice: name=nfs state=started enabled=yeshandlers:- name: restart nfsservice: name=nfs state=restarted- hosts: 192.168.17.106remote_user: roottasks:- name: install nfs client packageyum: name=nfs-utils state=latest- name: mountshell: mount 192.168.17.105:/share /mnt
检查已经挂在成功: