darexsu.nginx

Ansible 角色 Nginx

CI MoleculeAnsible 角色

平台

测试 仓库:distribution 仓库:nginx
Debian 11 Nginx 1.18 nginx.org
Debian 10 Nginx 1.14 nginx.org
Ubuntu 20.04 Nginx 1.18-1.20 nginx.org
Ubuntu 18.04 Nginx 1.18-1.20 nginx.org
Oracle Linux 8 Nginx 1.14-1.20 nginx.org
Rocky Linux 8 Nginx 1.14-1.20 nginx.org

安装

ansible-galaxy install darexsu.nginx --force

合并行为

替换或合并字典(在 ansible.cfg 中设置 "hash_behaviour=replace"):

# 替换               # 合并
---                 ---
  vars:               vars:
    dict:               merge:
      a: "value"          dict: 
      b: "value"            a: "value" 
                            b: "value"

# 合并是如何工作的?
您的变量 [host_vars]  -->  默认变量 [当前角色] --> 默认变量 [包含的角色]
  
  dict:          dict:              dict:
    a: "1" -->     a: "1"    -->      a: "1"
                   b: "2"    -->      b: "2"
                                  c: "3"
    
安装并配置:Nginx(合并版本)
---
- hosts: all
  become: true

  vars:
    merge:
      # Nginx
      nginx:
        enabled: true
        repo: "nginx"
      # Nginx -> 安装
      nginx_install:
        enabled: true
      # Nginx -> 配置 -> nginx.conf
      nginx_conf:
        enabled: true
        data:
          user: "www-data"
          worker_processes: "auto"
          error_log: "/var/log/nginx/error.log notice"
          pidfile: "/var/run/nginx.pid"
          worker_connections: "1024"
      #   ...
      # Nginx -> 配置 -> {virtualhost}.conf
      nginx_virtualhost:
        default_conf:
          enabled: true
          file: "default.conf"
          state: "present"
          src: "nginx_virtualhost.j2"
          backup: false
          data:
            listen_port: "80"
            listen_ipv6: false
            server_name: "localhost"
            root: "/usr/share/nginx/html"
            index: "index.html index.htm index.php"
            error_page: ""
            access_log: false
            error_log: false
            tcp_ip_socket:
              enabled: false
              listen: "127.0.0.1:9000"
            unix_socket:
              enabled: true
              file: "php-fpm.sock"
 
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role:
        name: darexsu.nginx
    
安装:Nginx,仓库:distribution(合并版本)
---
- hosts: all
  become: true

  vars:
    merge:
      # Nginx
      nginx:
        enabled: true
        repo: "distribution"
      # Nginx -> 安装
      nginx_install:
        enabled: true
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx
安装:Nginx,仓库:nginx(合并版本)
---
- hosts: all
  become: true

  vars:
    merge:
      # Nginx
      nginx:
        enabled: true
        repo: "nginx"
      # Nginx -> 安装
      nginx_install:
        enabled: true
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx
    
配置:nginx.conf(合并版本)
---
- hosts: all
  become: true

  vars:
    merge:
      # Nginx
      nginx:
        enabled: true
        repo: "nginx"
      # Nginx -> 配置 -> nginx.conf
      nginx_conf:
        enabled: true
        file: "nginx.conf"
        src: "nginx_conf.j2"
        backup: false
        data:
          user: "www-data"
          worker_processes: "auto"
          error_log: "/var/log/nginx/error.log notice"
          pidfile: "/var/run/nginx.pid"
          worker_connections: "1024"
          multi_accept: "off"
          mime_file_path: "/etc/nginx/mime.types"
          access_log: "/var/log/nginx/access.log"
          sendfile: "off"
          tcp_nopush: "off"
          tcp_nodelay: "on"
          keepalive_timeout: "75s"
          keepalive_requests: "1000"
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx
    
配置:virtualhost.conf tcp/ip socket(合并版本)
---
- hosts: all
  become: true

  vars:
    merge:
      # Nginx
      nginx:
        enabled: true
      # Nginx -> 配置 -> {virtualhost}.conf
      nginx_virtualhost:
        default_conf:
          enabled: true
          file: "default.conf"
          state: "present"
          src: "nginx_virtualhost.j2"
          backup: false
          data:
            listen_port: "80"
            listen_ipv6: false
            server_name: "localhost"
            root: "/usr/share/nginx/html"
            index: "index.html index.htm index.php"
            error_page: ""
            access_log: false
            error_log: false
            tcp_ip_socket:
              enabled: true
              listen: "127.0.0.1:9000"
            unix_socket:
              enabled: false
              file: "php-fpm.sock"
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx
    
配置:virtualhost.conf unix socket(合并版本)
---
- hosts: all
  become: true

  vars:
    merge:
      # Nginx
      nginx:
        enabled: true
      # Nginx -> 配置 -> {virtualhost}.conf
      nginx_virtualhost:
        default_conf:
          enabled: true
          file: "default.conf"
          state: "present"
          src: "nginx_virtualhost.j2"
          backup: false
          data:
            listen_port: "80"
            listen_ipv6: false
            server_name: "localhost"
            root: "/usr/share/nginx/html"
            index: "index.html index.htm index.php"
            error_page: ""
            access_log: false
            error_log: false
            tcp_ip_socket:
              enabled: true
              listen: "127.0.0.1:9000"
            unix_socket:
              enabled: false
              file: "php-fpm.sock"
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx    
配置:添加多个 virtualhost.conf(合并版本)
---
- hosts: all
  become: true

  vars:
    merge:
      # Nginx
      nginx:
        enabled: true
      # Nginx -> 配置 -> default.conf
      nginx_virtualhost:
        default_conf:
          enabled: true
          file: "default.conf"
          state: "present"
          src: "nginx_virtualhost.j2"
          backup: false
          data:
            listen_port: "80"
            listen_ipv6: false
            server_name: "localhost"
            root: "/usr/share/nginx/html"
            index: "index.html index.htm index.php"
            error_page: ""
            access_log: false
            error_log: false
            tcp_ip_socket:
              enabled: true
              listen: "127.0.0.1:9000"
            unix_socket:
              enabled: false
              file: "php-fpm.sock"
      # Nginx -> 配置 -> new.conf
        new_conf:
          enabled: true
          file: "new.conf"
          state: "present"
          src: "nginx_virtualhost.j2"
          backup: false
          data:
            listen_port: "80"
            listen_ipv6: false
            server_name: "localhost"
            root: "/usr/share/nginx/html"
            index: "index.html index.htm index.php"
            error_page: ""
            access_log: false
            error_log: false
            tcp_ip_socket:
              enabled: true
              listen: "127.0.0.1:9001"
            unix_socket:
              enabled: false
              file: "php-fpm.sock"
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx    
安装并配置:Nginx(完整版本)
---
- hosts: all
  become: true

  vars:
    # Nginx
    nginx:
      enabled: true
      repo: "nginx"
      service:
        enabled: true
        state: "started"
    # Nginx -> 安装
    nginx_install:
      enabled: true
    # Nginx -> 配置 -> nginx.conf
    nginx_conf:
      enabled: true
      file: "nginx.conf"
      src: "nginx_conf.j2"
      backup: false
      data:
        user: "www-data"
        worker_processes: "auto"
        error_log: "/var/log/nginx/error.log notice"
        pidfile: "/var/run/nginx.pid"
        worker_connections: "1024"
        multi_accept: "off"
        mime_file_path: "/etc/nginx/mime.types"
        access_log: "/var/log/nginx/access.log"
        sendfile: "off"
        tcp_nopush: "off"
        tcp_nodelay: "on"
        keepalive_timeout: "75s"
        keepalive_requests: "1000"
    # Nginx -> 配置 -> {virtualhost}.conf
    nginx_virtualhost:
      default_conf:
        enabled: true
        file: "default.conf"
        state: "present"
        src: "nginx_virtualhost.j2"
        backup: false
        data:
          listen_port: "80"
          listen_ipv6: false
          server_name: "localhost"
          root: "/usr/share/nginx/html"
          index: "index.html index.htm index.php"
          error_page: ""
          access_log: false
          error_log: false
          tcp_ip_socket:
            enabled: false
            listen: "127.0.0.1:9000"
          unix_socket:
            enabled: true
            file: "php-fpm.sock"
 
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role:
        name: darexsu.nginx
    
安装:Nginx,仓库:distribution(完整版本)
---
- hosts: all
  become: true

  vars:
    # Nginx
    nginx:
      enabled: true
      repo: "distribution"
      service:
        enabled: true
        state: "started"
    # Nginx -> 安装
    nginx_install:
      enabled: true
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx
安装:Nginx,仓库:nginx(完整版本)
---
- hosts: all
  become: true

  vars:
    # Nginx
    nginx:
      enabled: true
      repo: "nginx"
      service:
        enabled: true
        state: "started"
    # Nginx -> 安装
    nginx_install:
      enabled: true
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx
    
配置:nginx.conf(完整版本)
---
- hosts: all
  become: true

  vars:
    # Nginx
    nginx:
      enabled: true
      repo: "nginx"
      service:
        enabled: true
        state: "started"
    # Nginx -> 配置 -> nginx.conf
    nginx_conf:
      enabled: true
      file: "nginx.conf"
      src: "nginx_conf.j2"
      backup: false
      data:
        user: "www-data"
        worker_processes: "auto"
        error_log: "/var/log/nginx/error.log notice"
        pidfile: "/var/run/nginx.pid"
        worker_connections: "1024"
        multi_accept: "off"
        mime_file_path: "/etc/nginx/mime.types"
        access_log: "/var/log/nginx/access.log"
        sendfile: "off"
        tcp_nopush: "off"
        tcp_nodelay: "on"
        keepalive_timeout: "75s"
        keepalive_requests: "1000"
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx
    
配置:virtualhost.conf tcp/ip socket(完整版本)
---
- hosts: all
  become: true

  vars:
    # Nginx
    nginx:
      enabled: true
      repo: "nginx"
      service:
        enabled: true
        state: "started"
    # Nginx -> 配置 -> {virtualhost}.conf
    nginx_virtualhost:
      default_conf:
        enabled: true
        file: "default.conf"
        state: "present"
        src: "nginx_virtualhost.j2"
        backup: false
        data:
          listen_port: "80"
          listen_ipv6: false
          server_name: "localhost"
          root: "/usr/share/nginx/html"
          index: "index.html index.htm index.php"
          error_page: ""
          access_log: false
          error_log: false
          tcp_ip_socket:
            enabled: true
            listen: "127.0.0.1:9000"
          unix_socket:
            enabled: false
            file: "php-fpm.sock"
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx
    
配置:virtualhost.conf unix socket(完整版本)
---
- hosts: all
  become: true

  vars:
    # Nginx
    nginx:
      enabled: true
      repo: "nginx"
      service:
        enabled: true
        state: "started"
    # Nginx -> 配置 -> {virtualhost}.conf
    nginx_virtualhost:
      default_conf:
        enabled: true
        file: "default.conf"
        state: "present"
        src: "nginx_virtualhost.j2"
        backup: false
        data:
          listen_port: "80"
          listen_ipv6: false
          server_name: "localhost"
          root: "/usr/share/nginx/html"
          index: "index.html index.htm index.php"
          error_page: ""
          access_log: false
          error_log: false
          tcp_ip_socket:
            enabled: true
            listen: "127.0.0.1:9000"
          unix_socket:
            enabled: false
            file: "php-fpm.sock"
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx    
配置:添加多个 virtualhost.conf(完整版本)
---
- hosts: all
  become: true

  vars:
    # Nginx
    nginx:
      enabled: true
      repo: "nginx"
      service:
        enabled: true
        state: "started"
    # Nginx -> 配置 -> default.conf
    nginx_virtualhost:
      default_conf:
        enabled: true
        file: "default.conf"
        state: "present"
        src: "nginx_virtualhost.j2"
        backup: false
        data:
          listen_port: "80"
          listen_ipv6: false
          server_name: "localhost"
          root: "/usr/share/nginx/html"
          index: "index.html index.htm index.php"
          error_page: ""
          access_log: false
          error_log: false
          tcp_ip_socket:
            enabled: true
            listen: "127.0.0.1:9000"
          unix_socket:
            enabled: false
            file: "php-fpm.sock"
    # Nginx -> 配置 -> new.conf
      new_conf:
        enabled: true
        file: "new.conf"
        state: "present"
        src: "nginx_virtualhost.j2"
        backup: false
        data:
          listen_port: "80"
          listen_ipv6: false
          server_name: "localhost"
          root: "/usr/share/nginx/html"
          index: "index.html index.htm index.php"
          error_page: ""
          access_log: false
          error_log: false
          tcp_ip_socket:
            enabled: true
            listen: "127.0.0.1:9001"
          unix_socket:
            enabled: false
            file: "php-fpm.sock"
  
  tasks:
    - name: 包含角色 darexsu.nginx
      include_role: 
        name: darexsu.nginx    
关于项目

install and configure nginx from distro/third-party

安装
ansible-galaxy install darexsu.nginx
许可证
mit
下载
2.4k
拥有者