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 ...
随机推荐
- Fractions Again?! UVA - 10976
It is easy to see that for every fraction in the form 1k(k > 0), we can always find two positive ...
- codeforces 284 E. Coin Troubles(背包+思维)
题目链接:http://codeforces.com/contest/284/problem/E 题意:n种类型的硬币,硬币的面值可能相同,现在要在满足一些限制条件下求出,用这些硬币构成t面值的方案数 ...
- codeforces 459 C. Pashmak and Buses(思维)
题目链接:http://codeforces.com/problemset/problem/459/C 题意:有n个人,k辆车,d天要求没有两个人在d天都坐在一起.输出坐的方法. 题解:这题很有意思, ...
- 【转】Android CTS 测试
http://blog.csdn.net/zxm317122667/article/details/8508013 Android-CTS 4.0.3测试基本配置 1. Download CTS CT ...
- 基于SpringBoot从零构建博客网站 - 开发文章详情页面
文章详情页面是博客系统中最为重要的页面,登录用户与游客都可以浏览文章详情页面,只不过只有登录用户才能进行其它的一些操作,比如评论.点赞和收藏等等. 本次的开发任务只是将文章详情页面展示出来,至于一些收 ...
- BASK、BFSK、BPSK调制方法的Matlab程序实现
%以下为手动编程方法,也可调用matlab集成函数dmod,具体调制方式见doc. n = [0:0.01:5.99]; x1 = ones(1,100); x2 = zeros(1,100); x3 ...
- 美团集群调度系统HULK技术演进
本文根据美团基础架构部/弹性策略团队负责人涂扬在2019 QCon(全球软件开发大会)上的演讲内容整理而成.本文涉及Kubernetes集群管理技术,美团相关的技术实践可参考此前发布的<美团点评 ...
- 6 个 K8s 日志系统建设中的典型问题,你遇到过几个?
作者 | 元乙 阿里云日志服务数据采集客户端负责人,目前采集客户端 logtail 在集团百万规模部署,每天采集上万应用数 PB 数据,经历多次双 11.双 12 考验. 导读:随着 K8s 不断 ...
- Python:给定一个不超过5位的正整数,判断有几位
方法一:作比较 [root@python markPy]# cat five.py #!/usr/bin/python3 a=int(input(">>>>" ...
- DevExpress的PdfViewer添加工具栏实现PDF打开、预览、保存、打印
场景 Winform控件-DevExpress18下载安装注册以及在VS中使用: https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/1 ...