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

Ansible角色定制实例

目录

角色定制:roles

角色定制实例:利用角色部署wordpress

1.在roles目录下生成对应的目录结构

2.定义配置文件

①nginx

②php

 ③mysql

④定义剧本文件

⑤启动服务


角色定制:roles

      对于普通的剧本(playbook)有个弊端就是无法实现复用假设在同时部署Web、db、ha 时或不同服务器组合不同的应用就需要写多个yml文件。很难实现灵活的调用。

  roles 用于层次性、结构化地组织playbook。roles 能够根据层次型结构自动装载变量文件、tasks以及handlers等。要使用roles只需要在playbook中使用include指令即可。简单来讲,roles就是通过分别将变量(vars)、文件(file)、任务(tasks)、模块(modules)及处理器(handlers)放置于单独的目录中,并可以便捷地include它们的一种机制。

角色定制实例:利用角色部署wordpress

192.168.134.165 server01

192.168.134.166 server02

192.168.134.163 server03

server01管理其他两个服务器资产。

1.在roles目录下生成对应的目录结构
[root@server01 ~]# mkdir roles
#生成相应的目录
[root@server01 roles]# ansible-galaxy init nginx
[root@server01 roles]# ansible-galaxy init mysql
[root@server01 roles]# ansible-galaxy init php
[root@server01 roles]# tree
.
├── mysql
│   ├── defaults
│   │   └── main.yml
│   ├── files
│   ├── handlers
│   │   └── main.yml
│   ├── meta
│   │   └── main.yml
│   ├── README.md
│   ├── tasks
│   │   └── main.yml
│   ├── templates
│   ├── tests
│   │   ├── inventory
│   │   └── test.yml
│   └── vars
│       └── main.yml
├── nginx
│   ├── defaults
│   │   └── main.yml
│   ├── files
│   ├── handlers
│   │   └── main.yml
│   ├── meta
│   │   └── main.yml
│   ├── README.md
│   ├── tasks
│   │   └── main.yml
│   ├── templates
│   │   └── nginx.conf
│   ├── tests
│   │   ├── inventory
│   │   └── test.yml
│   └── vars
│       └── main.yml
├── php
│   ├── defaults
│   │   └── main.yml
│   ├── files
│   ├── handlers
│   │   └── main.yml
│   ├── meta
│   │   └── main.yml
│   ├── README.md
│   ├── tasks
│   │   └── main.yml
│   ├── templates
│   ├── tests
│   │   ├── inventory
│   │   └── test.yml
│   └── vars
│       └── main.yml
2.定义配置文件

我们需要修改每个文件对应的配置。

①nginx
  • [root@server01 roles]# vim nginx/tasks/main.yml
[root@server01 roles]# vim nginx/tasks/main.yml 
---
# tasks file for nginx- name: install {{ server }}yum: name={{ server }},epel-release  state=present- name: start {{ server }}service: name={{ server }} state=started- name: 拷贝wordpress源代码unarchive: src=/root/wordpress-6.4.1-zh_CN.tar.gz dest=/usr/share/nginx/html- name: copy wordpresscopy: src=/root/roles/wp-config.php  dest=/usr/share/nginx/html/wordpress/- name: copytemplate: src=/root/roles/nginx/templates/nginx.conf dest=/etc/nginx/  #将nginx的配置文件模板发送到资产上notify: restartnginxtags: rs#上传wordpress的包
[root@server01 ~]# rz 
[root@server01 ~]# ll
-rw-r--r--  1 root root 25302043 11月 13 09:58 wordpress-6.4.1-zh_CN.tar.gz
  • 创建 /root/roles/wp-config.php文件写入一下内容
<?php
/*** The base configuration for WordPress** The wp-config.php creation script uses this file during the installation.* You don't have to use the web site, you can copy this file to "wp-config.php"* and fill in the values.** This file contains the following configurations:** * Database settings* * Secret keys* * Database table prefix* * ABSPATH** @link https://wordpress.org/documentation/article/editing-wp-config-php/** @package WordPress*/// ** Database settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define( 'DB_NAME', 'wordpress' );/** Database username */
define( 'DB_USER', 'wordpress' );/** Database password */
define( 'DB_PASSWORD', 'Aren@123' );/** Database hostname */
define( 'DB_HOST', '192.168.134.166' );/** Database charset to use in creating database tables. */
define( 'DB_CHARSET', 'utf8mb4' );/** The database collate type. Don't change this if in doubt. */
define( 'DB_COLLATE', '' );/**#@+* Authentication unique keys and salts.** Change these to different unique phrases! You can generate these using* the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}.** You can change these at any point in time to invalidate all existing cookies.* This will force all users to have to log in again.** @since 2.6.0*/
define( 'AUTH_KEY',         'ug.ct&MB!sL1_o/6t.}Xt4|f?;%|@.Zw6>wUwM3uSXcgB_nnOaZF-m^oUAuV.i-n' );
define( 'SECURE_AUTH_KEY',  'EP#~FNQDJRfL4C8Lboja}KVrc:fhdq_L~gn#wN>^qrn.DHZQwkjl=]-:QFcv:aY-' );
define( 'LOGGED_IN_KEY',    '3NQgD!)H{lR=,s(EQm7!jYrlR*T|3:h:Ag>_|#6qAO k6U#vvF)gXqb EKdcu[]v' );
define( 'NONCE_KEY',        ',LMJd60b=Qj1]B)ut!JAYCuJ)xN?`Dlnc>P8Tl_hCTk3Sl+qyAvpi_[VbCTAR?:/' );
define( 'AUTH_SALT',        'uj<)Ftb_ZA8+;ms%1AqGik.P@35[]r?.d~jc4J?]und3^vEV*=noZ}z^Gbj?u,oQ' );
define( 'SECURE_AUTH_SALT', '-CoV$a0F^9AF ?Zk()y<{}*WB`QP;$++T`F2NC6OUb]2=i9GW`*/1RjLb&sTO>}/' );
define( 'LOGGED_IN_SALT',   '2)?iJr4fi!gqk5~76^f1}Apdwynt:;$JoNdw]ty:kL]tEfy[%$H(oLNdCX/bFhJy' );
define( 'NONCE_SALT',       'zU(c-T%ayYW17wFle,oVj0@VG&m,e#Ujs~M|@>q[^|RCp*q)GbGTbRh*zh_#V5h6' );/**#@-*//*** WordPress database table prefix.** You can have multiple installations in one database if you give each* a unique prefix. Only numbers, letters, and underscores please!*/
$table_prefix = 'wp_';
define( 'WP_DEBUG', false );/* Add any custom values between this line and the "stop editing" line. *//* That's all, stop editing! Happy publishing. *//** Absolute path to the WordPress directory. */
if ( ! defined( 'ABSPATH' ) ) {define( 'ABSPATH', __DIR__ . '/' );
}/** Sets up WordPress vars and included files. */
require_once ABSPATH . 'wp-settings.php';

  • [root@server01 roles]# vim nginx/vars/main.yml
[root@server01 roles]# vim nginx/vars/main.yml
---
# vars file for nginxserver: nginxport: 80
  • [root@server01 roles]# vim nginx/templates/nginx.conf
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;events {worker_connections 1024;
}http {log_format  main  '$remote_addr - $remote_user [$time_local] "$request" ''$status $body_bytes_sent "$http_referer" ''"$http_user_agent" "$http_x_forwarded_for"';access_log  /var/log/nginx/access.log  main;sendfile            on;tcp_nopush          on;tcp_nodelay         on;keepalive_timeout   65;types_hash_max_size 4096;include             /etc/nginx/mime.types;default_type        application/octet-stream;# Load modular configuration files from the /etc/nginx/conf.d directory.# See http://nginx.org/en/docs/ngx_core_module.html#include# for more information.include /etc/nginx/conf.d/*.conf;server {listen       {{ port }};server_name  localhost;root         /usr/share/nginx/html/wordpress;index index.php;# Load configuration files for the default server block.include /etc/nginx/default.d/*.conf;location ~ \.php$ {root          /usr/share/nginx/html/wordpress;  #指定网站目录fastcgi_pass   127.0.0.1:9000;    #指定访问地址fastcgi_index  index.php;           #指定默认文件fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name; #站点根目录,取决于root配置项include        fastcgi_params;  #包含nginx常量定义}error_page 404 /404.html;location = /404.html {}error_page 500 502 503 504 /50x.html;location = /50x.html {}}}
  • 定义handlers文件 [root@server01 roles]# vim nginx/handlers/main.yml 
---
# handlers file for nginx- name: restartnginxservice: name={{ server }} state=restarted
②php
  • root@server01 roles]# vim php/tasks/main.yml 
---
# tasks file for php- name: install phpyum: name=php80-php-xsl,php80-php,php80-php-cli,php80-php-devel,php80-php-gd,php80-php-pdo,php80-php-mysql,php80-php-fpm state=present- name: start phpservice: name=php80-php-fpm state=started
 ③mysql
  • [root@server01 roles]# vim mysql/tasks/main.yml 
---
# tasks file for mysql- name: install mariadbyum: name=mariadb-server,mariadb  state=present disablerepo=mysql-5.7-community- name: start dbservice: name=mariadb  state=started  enabled=true- name: change passwdshell: mysql  -e "create database {{ db_name }}; grant all on wordpress.* to 'wordpress'@'%' identified by '{{ db_pass }}'; flush privileges"tags: db           
  • [root@server01 roles]# vim mysql/vars/main.yml
---
# vars file for mysqldb_name: 'wordpress'db_pass: Aren@123
④定义剧本文件

接下来,我们就来定义剧本文件,由于大部分设置我们都单独配置在了roles里面,所以,接下来剧本就只需要写一点点内容即可:

[root@server01 roles]# vim roles.yaml 
---- hosts: allremote_user: rootroles:- nginx- php- mysql
⑤启动服务
  • [root@server01 roles]# ansible-playbook /root/roles/roles.yaml

 进入web页面

相关文章:

Ansible角色定制实例

目录 角色定制&#xff1a;roles 角色定制实例&#xff1a;利用角色部署wordpress 1.在roles目录下生成对应的目录结构 2.定义配置文件 ①nginx ②php ③mysql ④定义剧本文件 ⑤启动服务 角色定制&#xff1a;roles 对于普通的剧本&#xff08;playbook&#xff09;有…...

ElastaticSearch--- es多字段聚合

在使用es时&#xff0c;我们经常会用到聚合查询。 简单的聚合查询&#xff0c;已经在前面介绍过&#xff0c;详情见&#xff1a; https://www.cnblogs.com/expiator/p/13843969.html 有时&#xff0c;也会用到多字段聚合查询。类似于Mysql的Group By多个字段。 比如&#xf…...

本周Github有趣开源项目:Rspress等6个

Github有趣的项目、工具和库&#xff1a; 1、sshx 一个基于 Web 的安全协作终端。通过网络进行快速、协作的实时终端共享 特征&#xff1a; 运行一个命令即可与任何人共享您的终端。 在无限画布上调整大小、移动窗口以及自由缩放和平移。 查看其他人的光标实时移动。 连接到…...

【华为OD题库-016】字符串摘要-Java

题目 给定一个字符串的摘要算法&#xff0c;请输出给定字符串的摘要值 1、去除字符串中非字母的符号 2、如果出现连续字符(不区分大小写)&#xff0c;则输出:该字符(小)&#xff0b;连续出现的次数 3、如果是非连续的宁符(不区分大小写)&#xff0c;则输出:该字符(小写)该字母之…...

生成式AI - Knowledge Graph Prompting:一种基于大模型的多文档问答方法

大型语言模型&#xff08;LLM&#xff09;已经彻底改变了自然语言处理&#xff08;NLP&#xff09;任务。它们改变了我们与文本数据交互和处理的方式。这些强大的AI模型&#xff0c;如OpenAI的GPT-4&#xff0c;改变了理解、生成人类类似文本的方式&#xff0c;导致各种行业出现…...

深度学习AIR-PolSAR-Seg图像数据预处理

文章目录 深度学习sar图像数据预处理一.图片预处理操作1.log(1x)处理2.sqrt平方化处理 二.原网络训练效果展示原始数据训练效果展示&#xff1a; 三.对比实验1.采用原始数据2.采用取log(1x)后的数据3.采用取平方后归一化处理&#xff1a; 四.总结&#xff1a;五.思考 深度学习s…...

求最大公约数math.gcd()

【小白从小学Python、C、Java】 【计算机等级考试500强双证书】 【Python-数据分析】 求最大公约数 math.gcd() [太阳]选择题 下列代码执行输出的结果是&#xff1f; import math print("【执行】print(math.gcd(6, 8))") print(math.gcd(6, 8)) print(&quo…...

数据结构之队列

目录 引言 队列的概念与结构 队列的实现 定义 初始化 销毁 入队 判断队列是否为空 出队 获取队头元素 获取队尾元素 检测队列中有效元素个数 元素访问 源代码 queue.h queue.c test.c 引言 数据结构之路经过栈后&#xff0c;就来到了与栈联系紧密的兄弟—…...

MySQL数据库——存储过程-循环(while、repeat、loop)

目录 while 介绍 案例 repeat 介绍 案例 loop 介绍 案例一 案例二 while 介绍 while 循环是有条件的循环控制语句。满足条件后&#xff0c;再执行循环体中的SQL语句。具体语法为&#xff1a; -- 先判定条件&#xff0c;如果条件为true&#xff0c;则执行逻辑&#…...

Django路由

路由系统 1.Django1中的路由1.1 普通形式1.2 分组1.2.1 无名分组1.2.2 有名分组 2. Django2版本2.1 传统的路由2.2 正则表达式路由 3. 路由分发3.1 include(一般使用此方式做路由分发)3.2 手动分发 4. name别名及使用name的反向URL生成4.1 一般情况下的别名使用及反向生成4.2 分…...

头歌实践平台-数据结构-二叉树及其应用

第1关&#xff1a;实现二叉树的创建 #include "binary_tree.h"BiTreeNode* CreatBiTree(char* s, int &i, int len) // 利用先序遍历创建二叉树 // 参数&#xff1a;先序遍历字符串s&#xff0c;字符串初始下标i0&#xff0c;字符串长度len。 // 返回&#xff1…...

2023.11.11通过html内置“required-star“添加一个红色的星号来表示必填项

2023.11.11通过html内置"required-star"添加一个红色的星号来表示必填项 在HTML中&#xff0c;可以使用标签来为元素添加说明。同时可以通过添加一个红色的星号来表示必填项。 <!DOCTYPE html> <html lang"en"> <head><meta charse…...

pcie【C#】

根据提供的引用内容&#xff0c;使用C#编写PCIE的Demo需要遵循以下步骤&#xff1a;1.连接好硬件后&#xff0c;烧录bit文件&#xff0c;安装PCIe内核驱动&#xff0c;然后重启计算机。2.打开VS工程&#xff0c;创建一个新的C#控制台应用程序项目。3.在项目中添加对C DLL的引用…...

西门子精智屏数据记录U盘插拔问题总结

西门子精智屏数据记录U盘插拔问题总结 注意: 数据记录过程中不允许带电插拔 U 盘! 数据记录的相关功能可参考以下链接中的内容: TIA博途wincc V16 如何进行变量周期归档?...

(论文阅读27/100)Deep Filter Banks for Texture Recognition and Segmentation

27.文献阅读笔记 简介 题目 Deep Filter Banks for Texture Recognition and Segmentation 作者 Mircea Cimpoi, Subhransu Maji, Andrea Vedaldi, 原文链接 http://www.cv-foundation.org/openaccess/content_cvpr_2015/papers/Cimpoi_Deep_Filter_Banks_2015_CVPR_pap…...

ARMday06(串口)

代码&#xff1a; #include "gpio.h" #include "stm32mp1xx_gpio.h" #include "stm32mp1xx_rcc.h" #include "stm32mp1xx_uart.h" void init(); char getc(); void putc(const char data); int main() {init();//初始化putc(j);char …...

Rust字符串详解

文章目录 字符串切片String迭代方法基础字符串方法容量操作增删改查 字符串切片 我们所熟知的由双引号括起来的字符串&#xff0c;在Rust中只是个字符串切片&#xff0c;又叫字符串字面值。这种类型一旦创建&#xff0c;则不可更改。但支持索引&#xff0c;从切片中索引出来的…...

(四)七种元启发算法(DBO、LO、SWO、COA、LSO、KOA、GRO)求解无人机路径规划MATLAB

一、七种算法&#xff08;DBO、LO、SWO、COA、LSO、KOA、GRO&#xff09;简介 1、蜣螂优化算法DBO 蜣螂优化算法&#xff08;Dung beetle optimizer&#xff0c;DBO&#xff09;由Jiankai Xue和Bo Shen于2022年提出&#xff0c;该算法主要受蜣螂的滚球、跳舞、觅食、偷窃和繁殖…...

Window安装MongoDB

三种NOSQL的一种,Redis MongoDB ES 应用场景: 1.社交场景:使用Mongodb存储用户信息,以及用户发表的朋友圈信息,通过地理位置索引实现附近的人,地点等功能 2.游戏场景:使用Mongodb存储游戏用户信息,用户的装备,积分等直接以内嵌文档的形式存储,方便查询,高效率存储和访问…...

20.有效的括号(LeetCode)

思路&#xff1a;用栈的后进先出的特性&#xff0c;来完成题目的要求 因为C有库&#xff0c;可以直接用&#xff0c;而C语言没有&#xff0c;所以我们直接把写好的栈拷贝上来用。 首先&#xff0c;完成框架的搭建 其次&#xff0c;再实现循环内的部分。1.左括号入栈 2.右括…...

PHP和Node.js哪个更爽?

先说结论&#xff0c;rust完胜。 php&#xff1a;laravel&#xff0c;swoole&#xff0c;webman&#xff0c;最开始在苏宁的时候写了几年php&#xff0c;当时觉得php真的是世界上最好的语言&#xff0c;因为当初活在舒适圈里&#xff0c;不愿意跳出来&#xff0c;就好比当初活在…...

3.3.1_1 检错编码(奇偶校验码)

从这节课开始&#xff0c;我们会探讨数据链路层的差错控制功能&#xff0c;差错控制功能的主要目标是要发现并且解决一个帧内部的位错误&#xff0c;我们需要使用特殊的编码技术去发现帧内部的位错误&#xff0c;当我们发现位错误之后&#xff0c;通常来说有两种解决方案。第一…...

NFT模式:数字资产确权与链游经济系统构建

NFT模式&#xff1a;数字资产确权与链游经济系统构建 ——从技术架构到可持续生态的范式革命 一、确权技术革新&#xff1a;构建可信数字资产基石 1. 区块链底层架构的进化 跨链互操作协议&#xff1a;基于LayerZero协议实现以太坊、Solana等公链资产互通&#xff0c;通过零知…...

前端开发面试题总结-JavaScript篇(一)

文章目录 JavaScript高频问答一、作用域与闭包1.什么是闭包&#xff08;Closure&#xff09;&#xff1f;闭包有什么应用场景和潜在问题&#xff1f;2.解释 JavaScript 的作用域链&#xff08;Scope Chain&#xff09; 二、原型与继承3.原型链是什么&#xff1f;如何实现继承&a…...

人工智能--安全大模型训练计划:基于Fine-tuning + LLM Agent

安全大模型训练计划&#xff1a;基于Fine-tuning LLM Agent 1. 构建高质量安全数据集 目标&#xff1a;为安全大模型创建高质量、去偏、符合伦理的训练数据集&#xff0c;涵盖安全相关任务&#xff08;如有害内容检测、隐私保护、道德推理等&#xff09;。 1.1 数据收集 描…...

在树莓派上添加音频输入设备的几种方法

在树莓派上添加音频输入设备可以通过以下步骤完成&#xff0c;具体方法取决于设备类型&#xff08;如USB麦克风、3.5mm接口麦克风或HDMI音频输入&#xff09;。以下是详细指南&#xff1a; 1. 连接音频输入设备 USB麦克风/声卡&#xff1a;直接插入树莓派的USB接口。3.5mm麦克…...

深度学习之模型压缩三驾马车:模型剪枝、模型量化、知识蒸馏

一、引言 在深度学习中&#xff0c;我们训练出的神经网络往往非常庞大&#xff08;比如像 ResNet、YOLOv8、Vision Transformer&#xff09;&#xff0c;虽然精度很高&#xff0c;但“太重”了&#xff0c;运行起来很慢&#xff0c;占用内存大&#xff0c;不适合部署到手机、摄…...

系统掌握PyTorch:图解张量、Autograd、DataLoader、nn.Module与实战模型

本文较长&#xff0c;建议点赞收藏&#xff0c;以免遗失。更多AI大模型应用开发学习视频及资料&#xff0c;尽在聚客AI学院。 本文通过代码驱动的方式&#xff0c;系统讲解PyTorch核心概念和实战技巧&#xff0c;涵盖张量操作、自动微分、数据加载、模型构建和训练全流程&#…...

在Zenodo下载文件 用到googlecolab googledrive

方法&#xff1a;Figshare/Zenodo上的数据/文件下载不下来&#xff1f;尝试利用Google Colab &#xff1a;https://zhuanlan.zhihu.com/p/1898503078782674027 参考&#xff1a; 通过Colab&谷歌云下载Figshare数据&#xff0c;超级实用&#xff01;&#xff01;&#xff0…...

iOS 项目怎么构建稳定性保障机制?一次系统性防错经验分享(含 KeyMob 工具应用)

崩溃、内存飙升、后台任务未释放、页面卡顿、日志丢失——稳定性问题&#xff0c;不一定会立刻崩&#xff0c;但一旦积累&#xff0c;就是“上线后救不回来的代价”。 稳定性保障不是某个工具的功能&#xff0c;而是一套贯穿开发、测试、上线全流程的“观测分析防范”机制。 …...