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

检查已经挂在成功:

相关推荐
愚润求学2 分钟前
【Linux】数据链路层 and 其他知识
linux·运维·网络
刀法孜然11 分钟前
vim 编辑中,临时挂起编辑器进程,返回到终端命令行
linux·编辑器·vim
Amelio_Ming13 分钟前
systemd-journald和rsyslogd日志配置详解
linux·运维·服务器
九皇叔叔1 小时前
Linux Shell 中的 $():命令替换的核心用法
linux·运维·chrome
半桔1 小时前
【网络编程】详解 IP 协议:报头字段、路由器功能、网段划分和分片传输
linux·网络·网络协议·tcp/ip
大聪明-PLUS1 小时前
TCP/IP 协议族—理论与实践(二)
linux·嵌入式·arm·smarc
liulilittle1 小时前
Linux内核网络优化:两个网络调优解决方案
linux·运维·服务器·网络·内核·信息与通信·通信
hweiyu002 小时前
Linux运维实战:系统及服务管理(视频教程)
linux·运维·服务器
风随心飞飞2 小时前
linux 环境下mysql 数据库自动备份和清库 通过crontab 创建定时任务实现mysql数据库备份
linux·数据库·mysql
止观止2 小时前
VS Code 二次开发:跨平台图标定制全攻略
linux·windows·vscode·macos