William-Yeh.nginx

williamyeh.nginx 适用于 Ansible Galaxy

Circle CI Build Status

概述

Ansible Galaxy 中的角色名称: williamyeh.nginx

该 Ansible 角色为 Nginx 提供以下功能:

  • 安装特定版本。
  • 针对重启/重载/停止事件的处理器;
  • 基本配置(真实 配置应由用户的模板文件来完成;请参见下面的 用法 部分)。

角色变量

必须变量

无。

可选变量

用户可安装的配置文件(通过 Ansible 的模板系统):

# 安装到 "/etc/nginx/nginx.conf" 的主配置模板;
# 相对于 `playbook_dir`
nginx_conf_main

# 安装到 "/etc/nginx/conf.d" 的其他配置模板;
# 字典字段:
#   - key: 此配置的备注
#   - value:
#     - src: 相对于 `playbook_dir` 的模板文件
#     - dest: 相对于 `/etc/nginx/conf.d/` 的目标文件
nginx_conf_others

用户可配置的默认值:

# Nginx 版本;例如,"1.8.1"
# 如果未指定,将安装默认(通常是最新稳定)版本。
nginx_version

# 在角色结束时启动服务?
# 默认:True
nginx_start      

# 工作进程的用户 ID;
# 默认: "nginx"。
nginx_user

# nginx.conf 中的 worker_rlimit_nofile
nginx_ulimit:  51200

# nginx.conf 中的 worker_connections
nginx_worker_connections:  1024

# 安装健康检查端点 "http://HOST:PORT/nginx_status"?
nginx_status:  False

# 是否使用 `service` 命令启动/重启 nginx 守护进程?
nginx_use_service:  True

处理器

  • 重启 nginx
  • 重载 nginx
  • 停止 nginx

用法

第一步:添加角色

在您的剧本文件中添加角色名称 williamyeh.nginx

第二步:添加变量

在您的剧本文件中设置变量。

简单示例:

---
# 文件:simple-playbook.yml

- hosts: all

  roles:
    - williamyeh.nginx

  vars:
    nginx_version: 1.8.1

第三步:复制用户的配置文件(如有必要)

更实际的示例:

---
# 文件:complex-playbook.yml

- hosts: all

  roles:
    - williamyeh.nginx

  vars:
    nginx_version: 1.8.1

    nginx_conf_main: "templates/nginx.conf.j2"

    nginx_conf_others:
      conf_template_for_app_1:
        src: "templates/app-1.conf.j2"
        dest: app-1.conf
      conf_template_for_app_2:
        src: "templates/app-2.conf.j2"
        dest: app-2.conf

依赖

无。

许可证

MIT 许可证。详细信息见 许可证文件

历史

重写自我在 Galaxy 之前的版本:server-config-template

在重构过程中,Ansible Galaxy 上的一些角色也给了我启发:

关于项目

Install and configure Nginx

安装
ansible-galaxy install William-Yeh.nginx
许可证
mit
下载
3.4k
拥有者