实现多台的分离实现:
bash
[root@localhost playbook]# cat example3.yaml
---
- hosts: 192.168.17.105
remote_user: root
tasks:
- name: create test1 directory
file: path=/test1/ state=directory
- hosts: 192.168.17.106
remote_user: root
tasks:
- name: create test2 directory
file: path=/test2/ state=directory
剧本执行情况:
在105的机器上创建了test1目录。
在106的机器上创建了test2目录。
搭建nfs系统,并在另外一台机器上进行挂载操作。
bash
[root@localhost playbook]# cat example4.yaml
---
- hosts: 192.168.17.105
remote_user: root
tasks:
- name: install nfs software
yum: name=nfs-utils,rpcbind,setup state=latest
- name: create share folder
file: path=/share/ state=directory
- name: sync nfs configure
copy: src=/etc/exports dest=/etc/exports
notify: restart nfs
- name: start rpcbind and enabled in boot
service: name=rpcbind state=started enabled=yes
- name: start nfs and enabled in boot
service: name=nfs state=started enabled=yes
handlers:
- name: restart nfs
service: name=nfs state=restarted
- hosts: 192.168.17.106
remote_user: root
tasks:
- name: install nfs client package
yum: name=nfs-utils state=latest
- name: mount
shell: mount 192.168.17.105:/share /mnt
检查已经挂在成功: