当前位置: 首页 > article >正文

【ansible】role流程实验

cd /server/scripts
mkdir roles-all
cd roles-all
mkdir role01
cd role01
touch top.yml
touch hosts
mkdir -p nfs-server/{files,templates,tasks,handlers} group_vars/all/
# 目录详情
[root@m01 /server/scripts/roles-all/role01]# tree F 
.
 ├── group_vars/
 │   └── all/
 ├── hosts
 ├── nfs-server/
 │   ├── files/
 │   ├── handlers/
 │   ├── tasks/
 │   └── templates/
 └── top.yml
 7 directories, 2 files

创建tasks

vim nfs-server/tasks/main.yml
- name: 01. Installing nfs-utils,rpcbind
  yum:
    name: nfs-utils,rpcbind
    state: present
  tags:
    - 01. Install

- name: 02. Modify the configuration file
  template:
    src: exports.j2
    dest: /etc/exports
    backup: yes
  notify:
    - restart_nfs
  tags:
    - 02. Modify the configuration file

- name: 03. Create a shared directory and set the owner
  file:
    path: "{{ nfs_server_dir }}"
    owner: "{{ nfs_user }}"
    group: "{{ nfs_user }}"
    state: directory
  tags:
    - 03. Create a shared directory and set the owner

- name: 04. Start the server
  systemd:
    name: "{{ item }}"
    enabled: yes
    state: started
  loop:
    - rpcbind
  tags:
    - 04. Start the server

vim nfs-server/templates/exports.j2
# author:  {{ author }}
{{ nfs_server_dir }} 172.16.1.0/24(rw,all_squash)
vim group_vars/all/main.yml
author: CJoy
nfs_server_dir: /backup-nfs
nfs_user: nfsnobody

vim nfs-server/handlers/main.yml
---
- name: restart_nfs
  systemd:
    name: nfs
    enabled: yes
    state: restarted

vim top.yml

- hosts: web
  roles:
  - role: nfs-server

目录成型

[root@m01 role01]# tree -F
.
├── group_vars/
│   └── all/
│       └── main.yml
├── hosts
├── nfs-server/
│   ├── files/
│   ├── handlers/
│   │   └── main.yml
│   ├── tasks/
│   │   └── main.yml
│   └── templates/
│       └── exports.j2
└── top.yml

7 directories, 6 files


http://www.kler.cn/news/317630.html

相关文章:

  • 块匹配算法简介(上)
  • 腾讯云负载均衡ssl漏洞(CVE-201602183)解决
  • seL4 Capabilities(翻自官网)(一)
  • 【系统架构设计师】专业英语90题(附答案详解)
  • 代码随想录算法训练营第40天 动态规划part07| 题目: 198.打家劫舍 、 213.打家劫舍II 、 337.打家劫舍III
  • 软件设计-开闭原则
  • 2024年主动降噪头戴式耳机该如何选择?四款品牌高性价比推荐
  • 【TabBar嵌套Navigation案例-JSON的简单使用 Objective-C语言】
  • 用智能码二维码zhinengma.cn做产品说明书
  • 联通云 - 国产化全栈解决方案
  • 速通汇编(六)认识栈,SS、SP寄存器,push和pop指令的作用
  • LAMP架构搭建
  • 微服务远程调用(nacos及OpenFeign简单使用)
  • 程序员下班以后做什么副业合适?_35技术人员副业
  • VMware vCenter Server 8.0U3b 发布下载,新增功能概览
  • 微服务--Gateway网关
  • Apache CVE-2021-41773 漏洞复现
  • 《C++编程魔法:构建绿色主题的奇幻游戏世界》
  • Rust: AES 加密算法库
  • Java语言程序设计基础篇_编程练习题**18.39(拖动树)
  • SpringBoot+Thymeleaf租房管理系统
  • 亲测好用,ChatGPT 3.5/4.0新手使用手册,最好论文指令手册~
  • Python知识点:如何使用Python进行物联网数据处理
  • java日志框架之JUL(Logging)
  • Debezium日常分享系列之:Debezium 2.7.3.Final发布
  • sheng的学习笔记-AI-K-摇臂赌博机(K-armed bandit)
  • 96 kHz、24bit 立体声音频ADC芯片GC5358描述
  • 2025秋招LLM大模型多模态面试题(八)- langchain完整面试题
  • 【Python】快速判断两个commit 是否存在cherry-pick 关系
  • ubuntu查看全部的磁盘分区命令