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

检查已经挂在成功:

相关推荐
czxyvX2 小时前
007-Linux进程概念及周边知识
linux
Eternity∞3 小时前
Linux系统下,C语言基础
linux·c语言·开发语言
feng68_4 小时前
HAProxy算法实践
linux·运维·haproxy
吹牛不交税5 小时前
在vmware中右键SSH连接虚拟机报错Could not resolve hostname
linux·服务器·ssh
鱼香rose__6 小时前
DOMjudge搭建记录
linux
坂田民工9 小时前
RK3566 AB升级功能
linux·rk3566·buildroot·ab升级
SakitamaX9 小时前
LVS(Linux virual server)介绍与实验
linux·运维·lvs
小义_10 小时前
【Docker】知识八
linux·docker·云原生
开开心心_Every10 小时前
CDR版本转换工具,支持多版本互转免升级软件
linux·运维·服务器·云原生·edge·pdf·serverless
czxyvX10 小时前
009-Linux程序地址空间
linux