一、创建目录结构
  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. 《前端之路》之 初识 JavaScript

    01 初识 JavaScript 作为在码农圈混迹了 四五年的老码畜来说,学习一门新的语言,就仿佛是老司机开新车一样 轻车熟路. 为什么会这么快呢? 因为各种套路啊- 任何一种计算机语言的最开始都是和 ...

  2. 【Android Studio安装部署系列】二十八、Android Studio查看其它APP的布局结构

    概述 日常使用别家的APP过程中,会遇到一些比较好看的布局,这时候我们就想学习一下别人的布局结构,以便参考. (1)手机连接电脑.设置手机为USB调试模式 参考<[Android Studio安 ...

  3. 内核mailbox

    只罗列增加取走消息: static int add_to_rbuf(struct mbox_chan *chan, void *mssg) { int idx; unsigned long flags ...

  4. HTTP1.0和HTTP1.1的区别

    1.HTTP 1.1支持长连接(PersistentConnection)和请求的流水线(Pipelining)处理 HTTP 1.0规定浏览器与服务器只保持短暂的连接,浏览器的每次请求都需要与服务器 ...

  5. 搞懂MySQL InnoDB事务ACID实现原理

    前言 说到数据库事务,想到的就是要么都做修改,要么都不做.或者是ACID的概念.其实事务的本质就是锁和并发和重做日志的结合体.那么,这一篇主要讲一下InnoDB中的事务到底是如何实现ACID的. 原子 ...

  6. MySQL高可用复制管理工具 —— Orchestrator使用

    背景 在上一篇「MySQL高可用复制管理工具 —— Orchestrator介绍」中大致介绍了Orchestrator的功能.配置和部署,当然最详细的说明可以查阅官方文档.本文开始对Orchestra ...

  7. pytorch深度学习60分钟闪电战

    https://pytorch.org/tutorials/beginner/deep_learning_60min_blitz.html 官方推荐的一篇教程 Tensors #Construct a ...

  8. [TCP/IP] 网络层-ARP协议

    ARP协议可以将网络层地址到任意物理地址转换,从IP地址到MAC地址转换 MAC地址:物理地址,网卡厂家要确保MAC地址全球唯一,48位2进制,显示是12位16进制 1.查看我自己的ip,我自己的的i ...

  9. flex 实例 豆瓣手机端布局实现

    0.最终成品

  10. px妙转rem

    px:像素,相对长度单位,相对于显示器屏幕的分辨率而言(其实我个人认为可以理解为固定单位): rem:这是个web前端中的新成员,是CSS3中新增的一个相对单位.相对的只是html根元素: 1.设定两 ...