Ansible学习笔记14

实现多台的分离实现:

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

检查已经挂在成功:

相关推荐
码农客栈26 分钟前
linux 交叉编译tslib
linux
鱼月半1 小时前
两台电脑直连网络不通怎么办?
linux·网络协议
光电笑映2 小时前
网络通信基础:从协议分层到 Socket 编程预备
linux·运维·服务器·网络
酸菜。2 小时前
dw_apb_gpio总结
linux
wunaiqiezixin2 小时前
MIT 6.S081 file system 实验篇(lab9):Large files (moderate)
linux·unix·os·xv6·mit6.s081
GeW3 小时前
RHCE 考试通过率提升:核心考点、实验环境与排错技巧
linux
吴声子夜歌3 小时前
Shell编程实例——与解析相关的任务(二)
linux·运维·shell
mengge.cloud3 小时前
0917Docker 小白实验教程(理论+实操)
linux·服务器·网络·docker
Escalating_xu4 小时前
【内存管理发展史】从 8086 实模式到分页:CPU 如何把虚拟地址变成物理地址
linux·缓存
亿朝亿夕4 小时前
linux服务排查步骤
linux