【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
相关推荐
宁zz17 小时前
乌班图安装jenkins
运维·jenkins
无名之逆17 小时前
Rust 开发提效神器:lombok-macros 宏库
服务器·开发语言·前端·数据库·后端·python·rust
大丈夫立于天地间17 小时前
ISIS协议中的数据库同步
运维·网络·信息与通信
cg501717 小时前
Spring Boot 的配置文件
java·linux·spring boot
暮云星影17 小时前
三、FFmpeg学习笔记
linux·ffmpeg
rainFFrain18 小时前
单例模式与线程安全
linux·运维·服务器·vscode·单例模式
GalaxyPokemon18 小时前
Muduo网络库实现 [九] - EventLoopThread模块
linux·服务器·c++
mingqian_chu18 小时前
ubuntu中使用安卓模拟器
android·linux·ubuntu
xujiangyan_19 小时前
nginx的反向代理和负载均衡
服务器·网络·nginx