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

检查已经挂在成功:

相关推荐
板鸭〈小号〉20 分钟前
Linux网络基础(一)
linux·网络·智能路由器
范纹杉想快点毕业1 小时前
嵌入式 C 语言编程规范个人学习笔记,参考华为《C 语言编程规范》
linux·服务器·数据库·笔记·单片机·嵌入式硬件·fpga开发
百里晴鸢2 小时前
小白也能懂的iptables核心逻辑!四张表+五条链如何守护你的网络安全?
linux·安全
Akshsjsjenjd3 小时前
Linux 服务部署:自签 CA 证书构建 HTTPS 及动态 Web 集成
linux·前端·https
为什么要内卷,摆烂不香吗3 小时前
kubernetes(4) 微服务
linux·运维·微服务·容器·kubernetes
conkl9 小时前
Linux 零基础万字入门指南(进阶详解版)
linux·运维·服务器·ssh·文件管理·shell·linux基础
三体世界12 小时前
Mysql基本使用语句(一)
linux·开发语言·数据库·c++·sql·mysql·主键
TT-Kun12 小时前
Linux 上手 UDP Socket 程序编写(含完整具体demo)
linux·计算机网络·udp
一川风絮千片雪12 小时前
【环境配置】Linux/Ubuntu24.04 无图形界面安装显卡驱动
linux·运维·服务器
Danileaf_Guo13 小时前
Ubuntu 18.04快速配置WireGuard互联
linux·运维·服务器·ubuntu