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

检查已经挂在成功:

相关推荐
博语小屋4 分钟前
线程同步与条件变量
linux·jvm·数据结构·c++
至善迎风14 分钟前
Linux 服务器安全防护工具完全指南
linux·服务器·安全·防火墙
MC皮蛋侠客14 分钟前
Linux安装go及环境配置教程
linux·运维·golang
满天点点星辰26 分钟前
Linux命令大全-find命令
linux·运维·服务器
H_z_q240138 分钟前
RHCE的条件测试
linux·运维·服务器
新青年.43 分钟前
【Ubuntu】Ubuntu下解决Chrome不能输入中文
linux·chrome·ubuntu
风华同学1 小时前
【环境搭建篇】ARM+Linux环境搭建
linux·运维·arm开发
温柔如酒2 小时前
【linux调试】使用 sysrq 快照内核状态堆栈
linux·运维·服务器
std860212 小时前
Linux 6.18发布:年度最后版本或成新长期支持版本
linux·运维·服务器
HalvmånEver2 小时前
Linux:进程替换(进程控制四)
linux·运维·服务器·学习·进程