【ansible】role流程实验

bash 复制代码
cd /server/scripts
bash 复制代码
mkdir roles-all
bash 复制代码
cd roles-all
bash 复制代码
mkdir role01
bash 复制代码
cd role01
bash 复制代码
touch top.yml
touch hosts
mkdir -p nfs-server/{files,templates,tasks,handlers} group_vars/all/
bash 复制代码
# 目录详情
[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

bash 复制代码
vim nfs-server/tasks/main.yml
bash 复制代码
- 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
bash 复制代码
vim nfs-server/templates/exports.j2
bash 复制代码
# author:  {{ author }}
{{ nfs_server_dir }} 172.16.1.0/24(rw,all_squash)
bash 复制代码
vim group_vars/all/main.yml
bash 复制代码
author: CJoy
nfs_server_dir: /backup-nfs
nfs_user: nfsnobody
bash 复制代码
vim nfs-server/handlers/main.yml
bash 复制代码
---
- name: restart_nfs
  systemd:
    name: nfs
    enabled: yes
    state: restarted
bash 复制代码
vim top.yml
bash 复制代码
- hosts: web
  roles:
  - role: nfs-server

目录成型

bash 复制代码
[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
相关推荐
无聊的小坏坏19 小时前
从零开始:C++ 多线程 TCP 服务器实战(续篇)
服务器·c++·tcp/ip
利刃大大19 小时前
【高并发服务器】十、Connection连接管理模块设计与实现
服务器·c++·高并发·项目
Felven1 天前
统信系统下设置RTC时间
linux·rtc·1024程序员节
码龄3年 审核中1 天前
说说SSH的端口转发
大数据·运维·ssh
盛世隐者1 天前
【Linux】定制Linux系统
linux·运维·服务器
-Excalibur-1 天前
形象解释关于TCP/IP模型——层层封装MAC数据帧的过程
linux·c语言·网络·笔记·单片机·网络协议·tcp/ip
小跌—1 天前
Linux:数据链路层
linux·网络
用户31187945592181 天前
Fedora 37 安装 libicu-71.1-2.fc37.x86_64.rpm 教程(命令行步骤)
linux
搬砖的小码农_Sky1 天前
Linux(Ubuntu)操作系统下文件的解压
linux·ubuntu
景彡先生1 天前
Python函数定义与调用全解析:从基础语法到实战技巧
linux·开发语言·python