一、创建目录结构
  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. 老毛桃pe安装系统

    1.准备一个空白U盘,插入电脑. 2.下载老毛桃pe 3.下载完成后,打开老毛桃,默认制作成系统盘,傻瓜操作,无需修改参数 4.打开浏览器,下载要安装的系统 www.msdn.itellyou.cn ...

  2. Hadoop伪分布式集群搭建

    声明:作者原创,转载注明出处. 作者:帅气陈吃苹果 1.下载Hadoop压缩包 wget http://mirrors.hust.edu.cn/apache/hadoop/common/hadoop- ...

  3. Window环境下搭建Git服务器

    如果公司要搭建自己的 Git 服务器,可以使用 gitblit 这个开源的 Git 服务器 下载gitblit安装包 到 http://gitblit.com/下载安装包 解压缩下载的压缩包即可,无需 ...

  4. [翻译]Mock 在 Python 中的使用介绍

    目录 Mock 在 Python 中的使用介绍 原文链接与说明 恐惧系统调用 一个简单的删除函数 使用 Mock 重构 潜在陷阱 向 'rm' 中加入验证 将文件删除作为服务 方法 1:模拟实例的方法 ...

  5. Css-移动端适配总结

    前言 工作以后,大部分的业务工作都是基于移动端H5的,开发过程中学习了很多东西,遇到过许多问题,诸如rem\em\css px\device px等,本文纯属个人的归纳总结,如有问题,请指出亲喷~ P ...

  6. 【带着canvas去流浪(4)】绘制散点图

    目录 一. 任务说明 二. 重点提示 三. 示例代码 四.散点hover交互效果的实现 4.1 基本算法 4.2 参考代码 4.3 Demo中的小问题 示例代码托管在:http://www.githu ...

  7. C# 委托链(多播委托)

    委托既可以封装一个方法,又可以对同一类型的方法进行封装,它就是多播委托 using System; using System.Collections.Generic; using System.Lin ...

  8. 史上最全office2016 激活码

    现在office版本已经更新到2016了,现在给大家分享Office 2016 各个版本的激活码,记得断网激活哈.(本人使用的是家庭版) Office 2016 Pro Retail 版激活密钥: [ ...

  9. js正则表达式替换HTML标签以及空格( )

    参考:范仁义 js代码: function filter(text) { var reg = /<[^<>]+>/g;//1.全局匹配g肯定忘记写,2.<>标签中不 ...

  10. selenium+python自动化测试系列---基础知识篇(1、HTML基础知识1)

    1.什么是HTML HTML是一种描述网页的语言.HTML指超文本标记语言(Hyper Text Markup Language),它不是一种编程语言,而是一种标记语言(markup language ...