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

检查已经挂在成功:

相关推荐
Christal_pyy18 分钟前
树莓派4基于Debian GNU/Linux 12 (Bookworm)添加多个静态ipv4网络
linux·网络·debian
csbDD1 小时前
2025年网络安全(黑客技术)三个月自学手册
linux·网络·python·安全·web安全
Natsuagin4 小时前
轻松美化双系统启动界面与同步时间设置(Windows + Ubuntu)
linux·windows·ubuntu·grub
我们的五年4 小时前
【Linux网络编程】应用层协议HTTP(请求方法,状态码,重定向,cookie,session)
linux·网络·http
我们的五年6 小时前
【Linux网络】TCP/IP地址的有机结合(有能力VS100%???),IP地址的介绍
linux·运维·网络·tcp/ip
davenian6 小时前
< OS 有关 > Ubuntu 24 SSH 服务器更换端口 in jp/us VPSs
linux·ubuntu·ssh
诚信爱国敬业友善7 小时前
GUI编程(window系统→Linux系统)
linux·python·gui
sekaii7 小时前
ReDistribution plan细节
linux·服务器·数据库
YH_DevJourney8 小时前
Linux-C/C++《C/8、系统信息与系统资源》
linux·c语言·c++
威哥爱编程8 小时前
Linux驱动开发13个实用案例
linux