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

检查已经挂在成功:

相关推荐
安审若无25 分钟前
linux怎么检查磁盘是否有坏道
linux·运维·服务器
HalvmånEver25 分钟前
Linux的第二章 : 基础的指令(二)
linux·运维·服务器·开发语言·学习
大梦南柯26 分钟前
linux创建网站
linux·运维·服务器
刘永鑫Adam27 分钟前
代码管理及Linux模拟工具Git for Windows安装使用教程
linux·运维·服务器·git
孙同学_28 分钟前
【Linux篇】信号从哪来?到哪去?—— Linux信号的产生方式与保存机制
linux·运维·服务器
唐古乌梁海29 分钟前
【linux】crontab 命令详解,linux定时任务
linux·运维·服务器
aitav030 分钟前
⚡ Linux awk 命令全面详解(包括记录、字段、命令空间)
linux·运维·服务器·bash·shell·awk
egoist202332 分钟前
[linux仓库]线程同步与生产者消费者模型[线程·陆]
linux·c语言·开发语言·线程同步·阻塞队列·生产者消费者模型
qq_4017004133 分钟前
Linux 理解 nohup cmd & 后台运行机制
linux·运维·服务器
此生只爱蛋33 分钟前
【Linux】TCP
linux·tcp/ip