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

检查已经挂在成功:

相关推荐
dishugj1 小时前
【linux】Redhat 6.3系统安装zabbix-agent软件包,无法使用YUM源问题
linux·运维·zabbix
无奈笑天下1 小时前
【麒麟镜像vmtools异常排查指导书】
linux·运维·经验分享·云计算·kylin
Xの哲學1 小时前
Linux多级时间轮:高精度定时器的艺术与科学
linux·服务器·网络·算法·边缘计算
QT 小鲜肉2 小时前
【Linux命令大全】001.文件管理之mmove命令(实操篇)
linux·服务器·前端·chrome·笔记
Winner13002 小时前
查看rk3566摄像头设备、能力、支持格式
linux·网络·人工智能
QT 小鲜肉3 小时前
【Linux命令大全】001.文件管理之mdel命令(实操篇)
linux·运维·服务器·chrome·笔记
大聪明-PLUS3 小时前
如何从零开始开发 Linux 驱动程序
linux·嵌入式·arm·smarc
物随心转3 小时前
input子系统工作原理
linux
一只旭宝4 小时前
Linux专题六:进程替换详解加五种进程间通讯方式(套接字放到tcp通信编程上讲述)
linux
开压路机4 小时前
Linux的基本指令
linux·服务器