实现多台的分离实现:
[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系统,并在另外一台机器上进行挂载操作。
[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
检查已经挂在成功:文章来源:https://www.toymoban.com/news/detail-688356.html
文章来源地址https://www.toymoban.com/news/detail-688356.html
到了这里,关于Ansible学习笔记14的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!