Ansible Roles角色
Roles小技巧:
1.创建roles目录结构,手动或使用ansible-galaxy init test roles
2.编写roles的功能,也就是tasks。 nginx rsyncd memcached
3.最后playbook引用roles编写好的tasks
mkdir /root/roles/nginx/{tasks,templates,handlers}
##tasks
[root@manager ~]# cat /root/roles/nginx/tasks/main.yml
- name: Install Nginx Server
yum:
name: nginx
state: present
- name: Configure Nginx Server
template:
src: nginx.conf.j2
dest: /etc/nginx/nginx.conf
notify: Restart Nginx Server
- name: Systemd Nginx Server
systemd:
name: nginx
state: started
enabled: yes
##template
[root@manager roles]# cat /root/roles/nginx/templates/nginx.conf.j2
user www;
worker_processes {{ ansible_processor_vcpus }};
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections {{ ansible_processor_vcpus * 1024 }};
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
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;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
###handlers
[root@manager ~]# cat /root/roles/nginx/handlers/main.yml
- name: Restart Nginx Server
systemd:
name: nginx
state: restarted
#调用playbook
[root@manager roles]# cat /root/roles/site.yml
- hosts: webservers
roles:
- nginx
##hosts ansible.cfg 自备
memcached roles
#安装
#配置
#启动
#1.创建roles的目录结构
[root@manager roles]# mkdir memcached/{tasks,templates,handlers} -p
#2.编写对应的tasks (1.安装 2配置(templates) 3.启动 4.重启(handlers) )
[root@manager roles]# cat memcached/tasks/main.yml
- name: Installed Memecached Server
yum:
name: memcached
state: present
- name: Configure Memcached Server
template:
src: memcached.j2
dest: /etc/sysconfig/memcached
notify: Restart Memcached Server
- name: System Memcached Server
systemd:
name: memcached
state: started
enabled: yes
[root@manager roles]# cat memcached/templates/memcached.j2
PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="{{ ansible_memtotal_mb //2 }}"
OPTIONS=""
[root@manager roles]# cat memcached/handlers/main.yml
- name: Restart Memcached Server
systemd:
name: memcached
state: restarted
#3.playbook调用roles
[root@manager roles]# cat site.yml
- hosts: webservers
roles:
- { role: nginx, tags: web }
- { role: memcached, tags: cache }
NFS服务
#1.创建项目目录结构 --->
[root@manager roles]# mkdir nfs/{tasks,templates,handlers} -p
#2.编写task任务
#3.playbook调用roles项目
- roles:
- 1.nginxProxy+keepalived 10.0.0.5 10.0.0.6 10.0.0.3
- 2.nginx静态网站 172.16.1.7 172.16.1.8
Ansible Roles角色的更多相关文章
- 6.Ansible Roles角色实战
==Roles小技巧:== 1.创建roles目录结构,手动或使用ansible-galaxy init test roles 2.编写roles的功能,也就是tasks. nginx rsyncd ...
- Ansible--06 ansible roles
Ansible roles roles不管是Ansible还是saltstack,我在写一键部署的时候,都不可能把所有的步骤全部写入到一个'剧本'文件当中,我们肯定需要把不同的工作模块,拆分开来,解耦 ...
- ansible roles实践——安装nginx
1.创建roles 在/etc/ansible/roles目录下 1.1 手动创建需要的目录 1.2 使用命令创建,用不到的目录可以创建为空目录,但不可以不创建. 创建目录[root@master] ...
- ansible roles 目录规范
我的ansible roles项目的目录结构: (ansible_venv) [root@localhost ansible_home]# tree ansible_playbooks/ ansibl ...
- ansible roles 自动化安装
例: ansible roles 自动化安装memcached 文件目录结构如下: cat memcached_role.yml - hosts: memcached remote_user: ro ...
- Ansible之roles角色
一.roles简介 ansible自1.2版本引入的新特性,用于层次性.结构化地组织playbook.roles能够根据层次型结构自动装载变量文件.tasks以及handlers等.要使用roles只 ...
- ansible roles 介绍和使用
目录 roles roles 介绍 创建role的步骤 role内个目录中可用的文件 案例 roles roles 介绍 ansible 自1.2版本引入的新特性,用于层次性.结构化地组织playbo ...
- ansible roles实践 zookeeper集群部署
1.下载解压 wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11. ...
- ansible roles实践——安装java
[root@master] /etc/ansible$ cat roles/java/tasks/main.yml ---- name: unzip jdk unarchive: src=jdk-8u ...
随机推荐
- POJ 1182 食物链(经典并查集) (多组输入有时乱加也会错!)
多组输入有时乱加也会错! 这次用多组输入竟然,不用竟然对了,所以以后做题目,若是答案错误,先看加上或者删掉多组输入,看对不对 食物链 Time Limit: 1000MS Memory Lim ...
- hdu 4725 The Shortest Path in Nya Graph(建图+优先队列dijstra)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4725 题意:有n个点和n层,m条边,每一层的任意一个点都可以花费固定的值到下一层或者上一层的任意点 然 ...
- 树形dp poj2342 Anniversary party * 求最大价值
Description There is going to be a party to celebrate the 80-th Anniversary of the Ural State Univer ...
- Dungeon Master POJ - 2251 [kuangbin带你飞]专题一 简单搜索
You are trapped in a 3D dungeon and need to find the quickest way out! The dungeon is composed of un ...
- Git的合并
merge: A---B---C topic / D---E---F---G master A---B---C topic / \ D---E---F---G---H master (在当前的bran ...
- JS-特效 ~ 04. client对象、网页可视区域的宽高、client / offset / scroll 三大家族的区别、冒泡事件、事件委托、获取内嵌式和外链式属性getStyle(ele,attr) ;、缓动动画封装
知识点: 模拟滚动条的解除事件问题 : event内置对象,包含 了大量事件: page兼容性: pageX || clientX + scool().top : if (true === a)tr ...
- css3-旋转的太极图
123 body { background-color: #aaa; } .div { width: 400px; height: 400px; border-radius: 50%; border: ...
- Redis字符串键的底层原理
before C语言基础 Redis基础 导入 redis的命令如下: set x "hello"; get x; hello Redis作为一种存储字符串的缓存结构,其具体实现是 ...
- http压力测试工具及使用说明
http压力测试工具及使用说明 转 说明:介绍几款简单.易使用http压测工具,便于研发同学,压测服务,明确服务临界值,寻找服务瓶颈点. 压测时候可重点以下指标,关注并发用户数.TPS(每秒事务数量) ...
- 最佳内存缓存框架Caffeine
Caffeine是一种高性能的缓存库,是基于Java 8的最佳(最优)缓存框架. Cache(缓存),基于Google Guava,Caffeine提供一个内存缓存,大大改善了设计Guava's ca ...