Skip to content

kaywolter/ansible-apache2

 
 

Repository files navigation

Ansible franklinkim.apache2 role

Build Status Galaxy GitHub Tags GitHub Stars

franklinkim.apache2 is an ansible role which:

  • installs apache2
  • configures apache2
  • enables/disables confs
  • creates sites
  • enables/disables sites
  • enables/disables modules
  • optionally removes default host
  • adds rules
  • configures service

Installation

Using ansible-galaxy:

$ ansible-galaxy install franklinkim.apache2

Using requirements.yml:

- src: franklinkim.apache2

Using git:

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

Dependencies

  • Ansible >= 1.9

Variables

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

---
# apache2_module:
#   - { id: auth, state: absent }
#   - { id: rewrite, state: present }
# apache2_confs:
#   - { id: security, state: absent }
#   - { name: mime, state: present }
# apache2_sites:
#   - id: mysite (required)
#     name: mysite.local (required)
#     ip: '*'
#     port: 80
#     state: present
#     add_webroot: no
#     template: path/to/template.j2
#     rules: []
#     aliases: []
#     redirects: []
#     ssl:
#       port: 443
#       key_name: mykey
#       cert_name: mycert
#       chain_name: mychain
#     auth:
#       name: mysite
#       file: mysite
#     append: ''
#

# package name (version)
apache2_package: apache2
# mpm package name (version)
apache2_mpm_package: apache2-mpm-prefork
# ports to listen to
apache2_ports: [80]
# ssl ports to listen to
apache2_ssl_ports: [443]
# addresses to listen to (2.2  only)
apache2_listen_addresses: ['*']
# enabled/disabled modules
apache2_modules: []
# enabled/disabled confs
apache2_confs: []
# enabled/disabled sites
apache2_sites: []
# remove the default host
apache2_remove_default: no
# start on boot
apache2_service_enabled: yes
# current state: started, stopped
apache2_service_state: started
# set to one of:  Full | OS | Minimal | Minor | Major | Prod
apache2_server_tokens: Prod
# set to one of:  On | Off | EMail
apache2_server_signiture: 'Off'
# set to one of:  On | Off | extended
apache2_trace_enable: 'Off'
# path to certificates
apache2_certs_path: /etc/ssl/certs
# path to keys
apache2_keys_path: /etc/ssl/private

Handlers

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

---

- name: restart apache2
  service: name=apache2 state=restarted
  when: apache2_service_state != 'stopped'

- name: reload apache2
  service: name=apache2 state=reloaded
  when: apache2_service_state != 'stopped'

Rules

Some configuration fragments obtained from HTML 5 Boilerplate will be copied to /etc/apache2/rules which can then be used inside your vhost configurations (see usage below).

  • compression
  • content_transform
  • cors
  • cors_images
  • cors_timing
  • cors_web_fonts
  • etag
  • expires
  • file_concatenation
  • filename_based_cache_busting
  • ie_cookies
  • ie_edge
  • mimes
  • security_file_access
  • security_hosts
  • security_mime
  • security_signiture
  • security_technology
  • ssl
  • utf8

Usage

This is an example playbook:

---
# this examples uses related roles:
#
# - franklinkim.openssl  (https://github.com/weareinteractive/ansible-openssl)
# - franklinkim.htpasswd (https://github.com/weareinteractive/ansible-htpasswd)

- hosts: all
  sudo: yes
  roles:
    - franklinkim.openssl
    - franklinkim.htpasswd
    - franklinkim.apache2
  vars:
    apache2_modules:
      - { id: ssl, state: present }
      - { id: mime, state: present }
      - { id: headers, state: present }
      - { id: rewrite, state: present }
    apache2_remove_default: yes
    htpasswd:
      - name: foobar
        users:
          - { name: foobar, password: foobar }
    openssl_self_signed:
      - { name: 'foobar.local', country: 'DE', state: 'Bavaria', city: 'Munich', organization: 'Foo Bar', email: 'foo@bar.com' }
    apache2_sites:
      - id: foobar
        state: present
        name: foobar.local
        rules:
          - mimes
          - expires
          - compression
        add_webroot: yes
        auth:
          name: Foo Bar
          file: foobar
        ssl:
          key_name: foobar.local
          cert_name: foobar.local

Testing

$ git clone https://github.com/weareinteractive/ansible-apache2.git
$ cd ansible-apache2
$ vagrant up

Contributing

In lieu of a formal styleguide, 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.

About

Ansible role which installs and configures apache2

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages

  • ApacheConf 95.5%
  • Shell 4.5%