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

检查已经挂在成功:

相关推荐
我星期八休息3 小时前
网络编程—应用层HTTP协议
linux·运维·开发语言·前端·网络·网络协议·http
ShineWinsu4 小时前
对于Linux:UDPsocket编程基础的解析
linux·运维·网络协议·udp·ip·端口号·进程间通信
hehelm4 小时前
AI大模型接入SDK—通用模块设计
linux·开发语言·c++
Ai拆代码的曹操7 小时前
K8s Pod Pending 逐层排查:从 FailedScheduling 到 PVC StorageClass 不存在的实战记录
java·linux·kubernetes
wangbing11258 小时前
JPA下自定义主键
java·linux·服务器
bush48 小时前
正点原子imx6ull-uboot,奇怪的问题
linux·学习
dddwjzx9 小时前
嵌入式Linux C应用编程——Framebuffer应用编程
linux·嵌入式
今天也想躺ping10 小时前
linux系统移植pjsua库实现sip通话功能
linux·sip·交叉编译
信仰87411 小时前
Linux进阶篇01:网络基础配置
linux·网络·php
hkj880811 小时前
Linux 总线-设备-驱动(Bus-Device-Driver)完整协作原理
linux·运维·microsoft