pgporada.httpd
概要: ansible-role-httpd
このロールはhttpd(Apache)を設定し、定義したvhostsを構成し、リライト/リダイレクトルールを設定します。私はデータセンターで働いていたときにシニア管理者から教わった方法でvhostsを構成しています。この方法をキャリアの中でずっと続けています。この設定は意見に基づいたものです。あなたが同意しない可能性もあります。
変数定義
ELBやHaProxyなどのロードバランサーの背後でhttpdを実行している場合に使用します。trueの場合、customer_logger.confを/etc/httpd/conf.d/
にコピーします。カスタムロガーはx-forwardedソースIPヘッダーを取得します。
httpd_is_behind_loadbalancer: false
/etc/httpd/conf/httpd.conf
にデフォルトのドキュメントルートディレクトリを設定します。通常、バグラント用にオーバーライドする必要がありますが、そうでなければ変更しないでください。
httpd_conf_docrootdir: /var/www/domains
httpdがリッスンするポートを設定します。
httpd_conf_port: 80
httpd_conf_port_ssl: 443
httpdのkeepaliveディレクティブを有効または無効にします。ansible用のブール値です。Docs
httpd_conf_keepalive_enable: true
リクエストを処理するためのマルチプロセッシングモジュールです。Docs
httpd_conf_mpm: prefork # 他の有効なオプションは'event'と'worker'です
mod_headersを使用して、すべてのクッキーにhttponlyとsecureを設定します。これには注意が必要です。ブール値で、デフォルトはfalseです。Docs
httpd_conf_securecookies: false
例 Playbook
---
- hosts: localhost
connection: local
become: true
become_method: sudo
vars:
httpd_vhosts_enabled:
- url: jenkins.philporada.com
enable_ssl_vhost: false
#path_to_ssl_ca: /path/to/ca.pem
#path_to_ssl_cert: /path/to/cert.pem
#path_to_ssl_key: /path/to/key.pem
#path_to_ssl_chain: /path/to/bundle.pem
aliases: []
serveradmin: [email protected]
errorlog: "/var/log/httpd/error_log"
accesslog: "/var/log/httpd/access_log"
directory: "/var/www"
docrootdir: public_html
extra_parameters_main: |
#
#RewriteEngine On
# ELBからのリクエストをhttpsにリライトします
# ヘルスチェックが301リダイレクトで失敗するため、負である!httpsではなく、httpにマッチさせたいです
#RewriteCond %{HTTP:X-Forwarded-Proto} ^http$
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI}
extra_parameters_include: |
#
# これはバグラント専用です
#EnableSendfile Off
# git関連のものを隠します
RewriteRule ^(.*/)?\.git+ - [R=404,L]
RewriteRule ^(.*/)?\.gitignore+ - [R=404,L]
roles:
- ansible-roles-httpd
...
このロールをハックする方法
テストを実行する前に、yamllintで構文を検証する必要があります。
find . -type f -name "*.yml*" | sed "s|\./||g" | egrep -v "(\.kitchen/|\[warning\]|\.molecule/)" | xargs yamllint -f parsable
以下のような出力が表示され、その結果に対して手動で対応するか、単に無視できます。エラーが見つかることがわかります。このエラーは、ansibleが完了するのを妨げた可能性があります。これを見つけるのは良いことです。
$ find . -type f -name "*.yml*" | sed "s|\./||g" | egrep -v "(\.kitchen/|\[warning\]|\.molecule/)" | xargs yamllint -f parsable
defaults/main.yml:41:121: [warning] 行が長すぎます (127 > 120 文字) (line-length)
meta/main.yml:7:22: [error] 構文エラー: マッピング値はここには許可されていません
test/integration/default/default.yml:4:1: [warning] コメントが内容のようにインデントされていません (comments-indentation)
test/requirements.yml:2:2: [warning] コメントの先頭にスペースが足りません (comments)
テストキッチンのgemをインストールするには、ruby環境が必要です。gemはbundlerを使ってインストールします。
git clone git@github.com:pgporada/ansible-role-httpd.git
bundle install
bundle update
bundle exec kitchen create
bundle exec kitchen converge
bundle exec kitchen verify
bundle exec kitchen destroy
これで、.kitchen.yml
ファイルで定義されたデフォルトページにアクセスできるようになります。
テーマ音楽
著者情報
GPLv3
Phil Porada