weareinteractive.apache2

weareinteractive.apache2 角色

Build Status Galaxy GitHub Tags GitHub Stars

weareinteractive.apache2 是一个 Ansible 角色,功能包括:

  • 安装 apache2
  • 配置 apache2
  • 启用/禁用配置
  • 创建站点
  • 启用/禁用站点
  • 启用/禁用模块
  • 可选地移除默认主机
  • 添加规则
  • 配置服务

注意:

由于 Ansible Galaxy 现在支持组织,该角色已从 franklinkim.apache2 移动到 weareinteractive.apache2!

安装

使用 ansible-galaxy

$ ansible-galaxy install weareinteractive.apache2

使用 requirements.yml

- src: weareinteractive.apache2

使用 git

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

依赖

  • Ansible >= 2.4

变量

以下是该角色的所有默认变量列表,变量也可在 defaults/main.yml 中找到。

---
# apache2_packages:
#   - apache2
#   - apache2-mpm-prefork
# apache2_module:
#   - { id: auth, state: absent }
#   - { id: rewrite, state: present }
# apache2_confs:
#   - { id: security, state: absent }
#   - { name: mime, state: present }
#   - id: my_config
#     state: present
#     template: path/to/template.j2
# apache2_sites:
#   - id: mysite (必需)
#     name: mysite.local (必需)
#     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: ''
#

# 包(版本)
apache2_packages:
  - apache2
# 监听的端口
apache2_ports: [80]
# 监听的 ssl 端口
apache2_ssl_ports: [443]
# 监听的地址(仅适用于 2.2)
apache2_listen_addresses: ['*']
# 启用/禁用的模块
apache2_modules: []
# 启用/禁用的配置
apache2_confs: []
# 启用/禁用的站点
apache2_sites: []
# 文档根目录的位置(默认 /var/www 表示 /var/www/<SiteId>/htdocs)
apache2_sites_basedir: /var/www
# 默认站点模板文件
apache2_sites_template: etc/apache2/sites-available/site.j2
# 移除默认主机
apache2_remove_default: no
# 开机自动启动
apache2_service_enabled: yes
# 当前状态:started, stopped
apache2_service_state: started
# 设置为: Full | OS | Minimal | Minor | Major | Prod
apache2_server_tokens: Prod
# 设置为: On | Off | EMail
apache2_server_signiture: 'Off'
# 设置为: On | Off | extended
apache2_trace_enable: 'Off'
# 证书路径
apache2_certs_path: /etc/ssl/certs
# 密钥路径
apache2_keys_path: /etc/ssl/private

处理器

以下是 handlers/main.yml 中定义的处理器。

---

- name: 测试并重启 apache2
  command: apache2ctl configtest
  notify: 重启 apache2

- name: 测试并重新加载 apache2
  command: apache2ctl configtest
  notify: 重新加载 apache2

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

- name: 重新加载 apache2
  service: name=apache2 state=reloaded
  when: apache2_service_state != 'stopped'

规则

一些从 HTML 5 Boilerplate 获得的配置片段将被复制到 /etc/apache2/rules 中,可以在你的虚拟主机配置中使用(请参见下面的使用方法)。

  • 压缩
  • 内容转换
  • 跨域资源共享(CORS)
  • CORS 图片
  • CORS 计时
  • CORS Web 字体
  • etag
  • 到期时间
  • 文件合并
  • 基于文件名的缓存破坏
  • IE Cookies
  • IE Edge
  • MIME
  • 安全文件访问
  • 安全主机
  • 安全 MIME
  • 安全签名
  • 安全技术
  • SSL
  • UTF-8

使用

以下是一个示例剧本:

---
# 该示例使用相关角色:
#
# - weareinteractive.apt  (https://github.com/weareinteractive/ansible-apt)
# - weareinteractive.openssl  (https://github.com/weareinteractive/ansible-openssl)
# - weareinteractive.htpasswd (https://github.com/weareinteractive/ansible-htpasswd)

- hosts: all
  become: yes
  roles:
    - weareinteractive.apt
    - weareinteractive.openssl
    - weareinteractive.htpasswd
    - weareinteractive.apache2
  vars:
    htpasswd:
      - name: foobar
        users:
          - { name: foobar, password: foobar }
    apache2_modules:
      - { id: ssl, state: present }
      - { id: mime, state: present }
      - { id: headers, state: present }
      - { id: rewrite, state: present }
    apache2_remove_default: yes
    openssl_generate_csr: yes
    openssl_self_signed:
      - name: 'foobar.local'
        country: 'DE'
        state: 'Bavaria'
        city: 'Munich'
        organization: 'Foo Bar'
        unit: 'Foo Bar Unit'
        email: '[email protected]'
    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

测试

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

贡献

在没有正式风格指南的情况下,请注意保持现有的编码风格。为任何新或更改的功能添加单元测试和示例。

  1. 分叉它
  2. 创建你的特性分支 (git checkout -b my-new-feature)
  3. 提交你的更改 (git commit -am '添加新特性')
  4. 推送到分支 (git push origin my-new-feature)
  5. 创建新的拉取请求

注意:要更新 README.md 文件,请安装并运行 ansible-role

$ gem install ansible-role
$ ansible-role docgen

许可

版权 (c) We Are Interactive 根据 MIT 许可证。

关于项目

Installs and configures apache2

安装
ansible-galaxy install weareinteractive.apache2
许可证
mit
下载
15.9k