用roles部署nginx
1、初始化一个role [root@bogon ~]# ansible-galaxy init /etc/ansible/roles/websrvs 查看已经创建的role
[root@bogon ~]# ls /etc/ansible/roles/
webservs 2、配置role 把初始化后 role里面没用的删除,只留下面四个目录 [root@bogon ~]# cd /etc/ansible/roles/webservs/
[root@bogon webservs]# ls
handlers README.md tasks templates vars
[root@bogon webservs]# ls templates/
index.html.j2 nginx.conf.j2 配置变量vars [root@bogon webservs]# cat vars/main.yml
---
# vars file for /etc/ansible/roles/webservs
worker_processes: 4
worker_connections: 768
max_open_files: 65506 tasks 文件内容 [root@bogon webservs]# cat tasks/main.yml
---
# tasks file for /etc/ansible/roles/webservs
- name: install nginx
command: yum install nginx -y - name: copy nginx config file
template: src=nginx.conf.j2 dest=/etc/nginx/nginx.conf
notify: restart nginx - name: copy index.html
template:
src: index.html.j2
dest: /usr/share/nginx/www/index.html
mode: 0644
notify: restart nginx - name: see file
command: ls /root
notify: restart nginx handlers 文件内容: [root@bogon webservs]# cat handlers/main.yml
---
# handlers file for /etc/ansible/roles/webservs
- name: restart nginx
service: name=nginx state=restarted 模板文化内容: [root@bogon webservs]# cat templates/nginx.conf.j2
worker_processes {{ worker_processes }};
worker_rlimit_nofile {{ max_open_files }}; events {
worker_connections {{ worker_connections }};
} http {
server {
listen 80;
root /usr/share/nginx/www;
index index.html index.htm default.html index.php;
server_name loclhost;
location / {
try_files / =404;
}
} } [root@bogon webservs]# cat templates/index.html.j2
<html>
<head>
<title>welcome to american</title>
</head>
<body>
<h1>nginx, confitured by ansible</h1>
<p>if you can see this, ansible successfully installed nginx.</p> <p>{{ ansible_hostname }}</p>
</body>
</html> 3、配置playbook,把role添加进来 [root@bogon ~]# cat nginx_role.yaml
---
- hosts: webservers
become: yes
become_method: sudo
roles:
- role: webservs 4、开始执行Playbook [root@bogon ~]# ansible-playbook nginx_role.yaml
用roles部署nginx的更多相关文章
- Git+Gitlab+Ansible的roles实现一键部署Nginx静态网站(一)--技术流ken
前言 截止目前已经写了<Ansible基础认识及安装使用详解(一)--技术流ken>,<Ansible常用模块介绍及使用(二)--技术流ken><Ansible剧本介绍及 ...
- Git+Gitlab+Ansible的roles实现一键部署Nginx静态网站(4)
前言 截止目前已经写了<Ansible基础认识及安装使用详解(一)–技术流ken>,<Ansible常用模块介绍及使用(二)–技术流ken><Ansible剧本介绍及使用 ...
- debian完整部署 Nginx + uWSGI + Django
手工部署一个Django服务器真心不容易,需要安装很多东西.从头开始搭建服务器,主要是为了梳理一下后续开发中一般为碰到的平台部署.对后续问题的解决有一定帮助. 通常部署有2中方式: 一种是使用现成提供 ...
- debian7下部署nginx服务器
笔者是在vmware中的Debian7下部署nginx服务器,采用离线部署方式.过程如下: 1.准备好需要的离线安装包 nginx-1.6.2.tar.gz,pcre-8.34.tar.gz,open ...
- 在Docker下部署Nginx
在Docker下部署Nginx 在Docker下部署Nginx,包括: 部署一个最简单的Nginx,可以通过80端口访问默认的网站 设置记录访问和错误日志的路径 设置静态网站的路径 通过proxy_p ...
- 自动部署Nginx和nfs并架设Nginx集群脚本
本人经过多次尝试,简单完成了自动部署Nginx和nfs脚本,并且能够自动部署web反向代理集群,下面详细的阐述一下本人的思路.(以下脚本本人处于初学阶段,写的并不是很完善,所以需要后期进行整理和修正, ...
- Linux中以单容器部署Nginx+ASP.NET Core
引言 正如前文提到的,强烈推荐在生产环境中使用反向代理服务器转发请求到Kestrel Http服务器,本文将会实践将Nginx --->ASP.NET Core 部署架构容器化的过程. Ng ...
- Windows Server 2008 R2 Enterprise x64 部署 nginx、tomcat、mysql
部署nginx nginx主要做反向代理用,可以单独部署到其它机器上,这里nginx和tomcat部署在同一台机器上. 下载nginx-1.14.1.zip,并解压到目标目录,打开cmd进入到解压后的 ...
- windows10下面部署nginx(解决文件名中文乱码问题)
由于开发需要,我们总是需要先在windows环境下面部署项目进行测试,通过之后才会移植到linux系统进行测试部署. 本篇文章会介绍一下windows终端下面部署nginx WEB服务的一些步骤流程, ...
随机推荐
- LogHelper
原文链接 public class LogHelper { static string strLogCOMPath = Directory.GetCurrentDirectory() + " ...
- Redis和Memcache对比及选择(转载)
原文地址:http://blog.csdn.net/sunmenggmail/article/details/36176029 没有必要过多的关注性能.由于Redis只使用单核,而Memcached可 ...
- Test测试方法
Junit 注解 解释 @Before 在每个测试方法运行前执行的方法 @After 在每个测试方法运行后执行的方法 @BeforeClass 在类中所有测试运行之前运行的方法 @AfterClass ...
- 阻止默认/冒泡事件(兼容ie)
(1) 阻止默认事件 function(e){ if(e && e.preventDefault){ e.preventDefault(); }else{ //IE window.ev ...
- qt5--鼠标操作
#include "mylabel.h" #include <QDebug> #include <QPointF> #include <QPoint& ...
- javascript中创建对象的方式及优缺点(一)
1. 简单方式创建对象 // 字面量方式创建对象 var person1 = { name: "xyc", age: 23, sayHi: function() { console ...
- idea2018.3.6安装与破解教程(亲测可用、破解到2100年)
最近,帮室友进行idea安装,之前自己安装借鉴的博客已404,在网上找了好几个都无效,想着总结一份备用. 此博客是又找了一台电脑,边安装边写的. 目录 (已安装好的,可以直接看idea2018.3.6 ...
- CodeForces 349B--Color the Fence(贪心)
B. Color the Fence time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- AcWing:108. 奇数码问题(归并排序 + 逆序数)
你一定玩过八数码游戏,它实际上是在一个3×3的网格中进行的,1个空格和1~8这8个数字恰好不重不漏地分布在这3×3的网格中. 例如: 5 2 8 1 3 _ 4 6 7 在游戏过程中,可以把空格与其上 ...
- php正则表达式的学习
真的发现什么都需要这个 所以还是来把它学了吧 正则表达式的基本知识汇总 行定位符(^与$) 行定位符是用来描述字符串的边界.“$”表示行结尾“^”表示行开始如"^de",表示以de ...