Giter VIP home page Giter VIP logo

ansible-nginx's Introduction

Ansible weareinteractive.nginx role

Build Status Galaxy GitHub Tags GitHub Stars

weareinteractive.nginx is an Ansible role which:

  • installs nginx
  • configures nginx
  • creates sites
  • enables/disables sites
  • optionally removes default host
  • adds rules
  • configures service

Note:

Since Ansible Galaxy supports organization now, this role has moved from franklinkim.nginx to weareinteractive.nginx!

Installation

Using ansible-galaxy:

$ ansible-galaxy install weareinteractive.nginx

Using requirements.yml:

- src: weareinteractive.nginx

Using git:

$ git clone https://github.com/weareinteractive/ansible-nginx.git weareinteractive.nginx

Dependencies

  • Ansible >= 2.4

Related (see example)

Variables

Here is a list of all the default variables for this role, which are also available in defaults/main.yml.

---

# nginx_sites:
#   - id: foo (required)
#     name: foo.com (required)
#     ip: '*'
#     port: 80
#     state: present
#     add_webroot: no
#     template: path/to/template.j2
#     aliases: []
#     redirects: []
#     ssl:
#       port: 443
#       key_name: mykey.key
#       key_path: path/to/key
#       cert_name: mycert.crt
#       cert_path: path/to/cert
#     rules: []
#     auth:
#       name: foo
#       file: foo
#     append: ''
#

# dependencies packages to install package
nginx_dependencies:
  - ca-certificates
  - gnupg2
# apt repository
nginx_repo: "deb http://nginx.org/packages/{{ ansible_distribution|lower }}/ {{ ansible_distribution_release }} nginx"
# apt repository key
nginx_repo_key: ABF5BD827BD9BF62
# package name (version)
nginx_package: nginx
# run as a less privileged user for security reasons.
nginx_user: www-data
# number or auto
nginx_worker_processes: 1
nginx_worker_connections: 1024
# default settings
nginx_sendfile: 'on'
nginx_tcp_nopush: 'on'
nginx_tcp_nodelay: 'on'
nginx_keepalive_timeout: 15
nginx_types_hash_max_size: 2048
nginx_server_names_hash_bucket_size: 128
nginx_server_tokens: 'off'
# remove default site
nginx_remove_default: no
# start on boot
nginx_service_enabled: yes
# current state: started, stopped
nginx_service_state: started
# enabled/disabled sites
nginx_sites: []
# add rules
nginx_add_rules: yes

Handlers

These are the handlers that are defined in handlers/main.yml.

---

- name: restart nginx
  service: name=nginx state=restarted
  when: nginx_service_state != 'stopped'

- name: reload nginx
  service: name=nginx state=reloaded
  when: nginx_service_state != 'stopped'

Rules

If nginx_add_rules is yes, it will copy some configuration rules to /etc/nginx/rules:

  • cache_busting.conf
  • cors_web_fonts.conf
  • gzip.conf
  • no_transform.conf
  • ssl.conf
  • cors_ajax.con
  • expires.conf
  • gzip_static.conf
  • security.conf

Usage

This is an example playbook:

---

- hosts: all
  become: yes
  roles:
    - weareinteractive.apt
    - weareinteractive.openssl
    - weareinteractive.htpasswd
    - weareinteractive.nginx
  vars:
    htpasswd:
      - name: foobar
        users:
          - { name: foobar, password: foobar }
    openssl_generate_csr: yes
    openssl_self_signed:
      - name: fooboar.local
        subject:
           C: DE
           ST: Bavaria
           L: Munich
           O: Foo Bar Inc
           CN: foobar.local
           emailAddress: [email protected]
    nginx_sites:
      - id: foobar
        add_webroot: yes
        name: foobar.local
        ssl:
          key_name: foobar.local.key
          cert_name: foobar.local.crt
        rules:
          - gzip
          - security
        auth:
          name: Foo Bar
          file: foobar
    nginx_worker_processes: 1
    nginx_remove_default: yes
    # do not start service as we're running in docker
    nginx_service_state: stopped
    nginx_service_enabled: no

Testing

$ git clone https://github.com/weareinteractive/ansible-nginx.git
$ cd ansible-nginx
$ make test

Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests and examples for any new or changed functionality.

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Note: To update the README.md file please install and run ansible-role:

$ gem install ansible-role
$ ansible-role docgen

License

Copyright (c) We Are Interactive under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.