一、创建目录结构
  cd /etc/ansible/roles/
  mkdir nginx/{files,templates,vars,handlers,meta,default,tasks} -pv
二、files/:存储由copy或script等模块调用的文件;
三、tasks/:配置main.yml文件,用于定义各task;其它的文件需要由main.yml进行“包含”调用;
  cat main.yml
 
    - name: copy package
      copy: src=nginx-1.13.6.tar.gz dest=/usr/local/src/nginx-1.13.6.tar.gz
      tags: cppkg
 
    - name: tar nginx
      shell: cd /usr/local/src;tar -xf nginx-1.13.6.tar.gz
 
    - name: yum install
      yum: name={{ item }} state=latest  
                with_items:
                - openssl-devel
                - pcre-devel
                - gcc
 
              - name: install nginx
                shell: useradd nginx;cd /usr/local/src/nginx-1.13.6;./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre;make && make install
 
              - name: copy conf file
                 template: src=nginx.conf dest=/usr/local/nginx/conf/nginx.conf
 
              - name: systemctl init
      template: src=nginx.service dest=/usr/lib/systemd/system/nginx.service
 
    - name: start nginx service
      service: name=nginx state=started enabled=true
 
六、handlers/:配置main.yml,用于定义各handler;其它的文件需要由main.yml进行“包含”调用;
七、vars/:配置main.yml,用于定义各variable;其它的文件需要由main.yml进行“包含”调用;
  vim main.yml
 
  nginxport: "8080"
  server_name: "web.wsl.com"
  root_dir: "/web"
 
八、templates/:存储由template模块调用的模板文本;
cat nginx.conf
 
user nginx;
worker_processes {{ ansible_processor_vcpus }};
 
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
 
#pid logs/nginx.pid;
 
 
events {
worker_connections 65535;
}
 
 
http {
include 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 logs/access.log main;
 
sendfile on;
#tcp_nopush on;
 
#keepalive_timeout 0;
keepalive_timeout 65;
 
#gzip on;
 
server {
listen {{ nginxport }};
server_name localhost;
 
#charset koi8-r;
 
#access_log logs/host.access.log main;
 
location / {
root html;
index index.html index.htm;
}
 
#error_page 404 /404.html;
 
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
 
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
 
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
 
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
 
 
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
 
# location / {
# root html;
# index index.html index.htm;
# }
#}
 
 
# HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost;
 
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
 
# ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m;
 
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
 
# location / {
# root html;
# index index.html index.htm;
# }
#}
 
}
 
[root@w5 templates]# cat nginx.service
 
[Unit]
Description=The nginx HTTP and reverse proxy server
After=network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
PIDFile=/usr/local/nginx/logs/nginx.pid
ExecStartPre=/usr/bin/rm -f /run/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t
ExecStart=/usr/local/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
KillMode=process
KillSignal=SIGQUIT
TimeoutStopSec=5
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target
 
九、meta/:配置main.yml,定义当前角色的特殊设定及其依赖关系;其它的文件需要由main.yml进行“包含”调用;
十、default/:配置main.yml,用于设定默认变量;
 
十一、定义一个主调用文件
/etc/ansible/nginx.yaml
- hosts: webserver
remote_user: root
roles:
- nginx
 
十二、检测语法
ansible-playbook --syntax-check /etc/ansible/nginx.yaml
 
playbook: /etc/ansible/nginx.yaml
 
十三、测试部署
ansible-playbook -C /etc/ansible/nginx.yaml
-C 测试
部署:ansible-playbook  /etc/ansible/nginx.yaml
 
 
 

ansible-playbook(nginx例)的更多相关文章

  1. ansible笔记(10):初识ansible playbook

    ansible笔记():初识ansible playbook 假设,我们想要在test70主机上安装nginx并启动,我们可以在ansible主机中执行如下3条命令 ansible test70 -m ...

  2. ansible笔记(11):初识ansible playbook(二)

    ansible笔记():初识ansible playbook(二) 有前文作为基础,如下示例是非常容易理解的: --- - hosts: test211 remote_user: root tasks ...

  3. Ansible playbook 批量修改服务器密码 先普通后root用户

    fsckzy   Ansible playbook 批量修改服务器密码 客户的需求:修改所有服务器密码,密码规则为Rfv5%+主机名后3位 背景:服务器有CentOS6.7,SuSE9.10.11,r ...

  4. Ansible playbook基础组件介绍

    本节内容: ansible playbook介绍 ansible playbook基础组件 playbook中使用变量 一.ansible playbook介绍 playbook是由一个或多个“pla ...

  5. ansible入门四(Ansible playbook基础组件介绍)

    本节内容: ansible playbook介绍 ansible playbook基础组件 playbook中使用变量 一.ansible playbook介绍 playbook是由一个或多个“pla ...

  6. ansible playbook模式及语法

    一.什么是playbook及其组成 什么是playbook playbook 翻译过来就是"剧本" playbook的组成 play:定义的是主机的角色 task:定义的是具体执行 ...

  7. ansible playbook 使用

    ansible playbook 格式是json  yaml   1. 执行方法 ansible-playbook deply.yml 2. playbook 格式 关键字 hosts 主机ip 主机 ...

  8. ansible - playbook(剧组)

    目录 ansible - playbook(剧组) 常用命令 五种传参方式 常用元素详解 tags handlers template when 循环 嵌套循环 ansible - playbook( ...

  9. ansible+playbook 搭建lnmp环境

    用三台机器 做ansible+playbook 搭建lnmp环境 IP分配 ansible 主机192.168.202.132 lnmp第一台主机 192.168.202.131 lnmp第一台主机 ...

  10. Ansible--02 ansible playbook的应用

    目录 Ansible playbook的应用 什么是playbook playbook的组成 playbook和Ad-Hoc对比 YAML语法 安装httpd练习 rsyncd实战 实战1: 实战2: ...

随机推荐

  1. 这些好用的 Chrome 插件,提升你的工作效率

    本文首发于我的公众号 Linux云计算网络(id: cloud_dev),专注于干货分享,号内有 10T 书籍和视频资源,后台回复「1024」即可领取,欢迎大家关注,二维码文末可以扫. Google ...

  2. 阿里ECS配置MSSQL远程连接的坑

    mssql 2012 r2远程配置的相关文档有太多: 如:sql server2012 远程访问设置 这里不做远程配置的设置介绍.这篇随笔存在的意义在于,你除了要设置服务器,还需要到阿里云控制台设置安 ...

  3. Entity Framework 异常: 'OFFSET' 附近有语法错误。\r\n在 FETCH 语句中选项 NEXT 的用法无效。

    在使用 EF 的时候,突然发现更新后在服务器中运行出错,异常信息主要包含以下信息: 'OFFSET' 附近有语法错误.\r\n在 FETCH 语句中选项 NEXT 的用法无效.\r\n关键字 'AS' ...

  4. 《HelloGitHub》第 29 期

    公告 月刊现已支持 RSS 订阅 <HelloGitHub>第 29 期 兴趣是最好的老师,HelloGitHub 就是帮你找到兴趣! 简介 分享 GitHub 上有趣.入门级的开源项目. ...

  5. Kafka、ActiveMQ、RabbitMQ、RocketMQ 区别以及高可用原理

    为什么使用消息队列 其实就是问问你消息队列都有哪些使用场景,然后你项目里具体是什么场景,说说你在这个场景里用消息队列是什么? 面试官问你这个问题,期望的一个回答是说,你们公司有个什么业务场景,这个业务 ...

  6. .NET ClrProfiler ILRewrite 商业级APM原理

    Demo:https://github.com/caozhiyuan/ClrProfiler.Trace 背景 为了实现自动.无依赖地跟踪分析应用程序性能(达到商业级APM效果),作者希望能动态修改应 ...

  7. c# List根据某个属性进行分类,变成以属性名称作为分类的多个List

    在平时的开发中,我们从数据库中得到List列表,但是我们希望可以根据属性名称再次进行分类. 其实LINQ中已经内置相应的算法. 长话短说,直接上代码: var dataList = JsonHelpe ...

  8. javascript排序算法-归并排序

    归并排序 概念:归并排序是一种分治算法.其思想是将原始数组切分成较小的数组,直到每个小数组只有一个位置,接着将小数组归并成较大的数组,直到最后只有一个排序完毕的大数组. 时间复杂度: O(nlogn) ...

  9. 超大文本文件浏览器Snaptext,支持不限制大小的文本文件浏览

    文本文件超过1G就很少有软件可以打开了,超过10G就只有有限的几个可以打开了,那20G.30G.100G呢? Snaptext超大文本浏览器,应该是世界上最快速的文本文件浏览器,它支持基本不限制大小的 ...

  10. 四、Snapman多人协作电子表格之——Exprtk脚本

    Snapman多人协作电子表格是一个即时工作系统. Snapman中嵌入了Exprtk脚本进行公式数据运算.Exprtk是一种高性能的脚本,经测试它的数据运算性能只比C#和java底20%. 一.Ex ...