weareinteractive.apache2

Ansible weareinteractive.apache2 ロール

ビルドステータス Galaxy GitHub タグ GitHub スター

weareinteractive.apache2Ansible のロールで、以下を行います:

  • 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 にコピーされ、仮想ホストの設定内で使用できるようになります(下記の使用法を参照)。

  • 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

使用法

以下はプレイブックの例です:

---
# この例では関連するロールを使用しています:
#
# - 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 'Add some feature')
  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