ansible-fastly

Fastlyサービスを設定するためのAnsibleモジュール
インストール
$ ansible-galaxy install Jimdo.fastly
ドキュメント
モジュールオプション
名称 |
必須 |
説明 |
デフォルト |
name |
はい |
作成するサービスのユニークな名前 |
|
fastly_api_key |
いいえ |
Fastly APIキー。設定しない場合、FASTLY_API_KEY環境変数の値が使用されます。 |
|
activate_new_version |
いいえ |
新しく作成したバージョンを自動的に有効にするかどうかを設定します |
true |
domains |
はい |
サービスのエントリポイントとなるドメイン名のリスト |
|
backends |
はい |
ドメインからのリクエストを処理するバックエンドのリスト |
|
cache_settings |
いいえ |
キャッシュ設定のリスト |
|
conditions |
いいえ |
条件のリスト |
|
directors |
いいえ |
ディレクタのリスト |
|
gzips |
いいえ |
gzip設定のリスト |
|
headers |
いいえ |
各リクエストに操作するヘッダーのリスト |
|
healthchecks |
いいえ |
バックエンド目的のヘルスチェックのリスト |
|
request_settings |
いいえ |
リクエスト設定のリスト |
|
response_objects |
いいえ |
レスポンスオブジェクトのリスト |
|
settings |
いいえ |
設定オブジェクト |
|
s3s |
いいえ |
S3ロガーのリスト |
|
syslogs |
いいえ |
Syslogロガーのリスト |
|
vcl_snippets |
いいえ |
VCLスニペットのリスト |
|
バックエンド
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
port |
いいえ |
integer |
80 |
address |
はい |
string |
|
ssl_hostname |
いいえ |
string |
|
ssl_ca_cert |
いいえ |
string |
|
ssl_cert_hostname |
いいえ |
string |
|
shield |
いいえ |
string |
|
healthcheck |
いいえ |
string |
|
weight |
いいえ |
integer |
100 |
connect_timeout |
いいえ |
integer |
1000 |
first_byte_timeout |
いいえ |
integer |
15000 |
between_bytes_timeout |
いいえ |
integer |
10000 |
error_threshold |
いいえ |
integer |
0 |
max_conn |
いいえ |
integer |
200 |
キャッシュ設定
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
action |
いいえ |
enum ('cache', 'pass', 'restart') |
|
cache_condition |
いいえ |
string |
|
stale_ttl |
いいえ |
integer |
0 |
条件
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
comment |
いいえ |
string |
|
priority |
いいえ |
integer |
0 |
statement |
はい |
string |
|
type |
はい |
enum ('REQUEST', 'PREFETCH', 'CACHE', 'RESPONSE') |
|
ディレクタ
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
backends |
いいえ |
array of strings |
|
capacity |
いいえ |
integer |
100 |
comment |
いいえ |
string |
'' |
quorum |
いいえ |
integer |
75 |
shield |
いいえ |
string |
|
type |
いいえ |
integer (1,2,3,4のいずれか) |
1 |
retries |
いいえ |
integer |
5 |
ヘッダー
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
action |
いいえ |
enum ('set', 'append', 'delete', 'regex', 'regex_repeat') |
set |
dst |
はい |
string |
|
ignore_if_set |
いいえ |
integer (0または1のいずれか) |
0 |
priority |
いいえ |
integer |
100 |
regex |
いいえ |
string |
|
request_condition |
いいえ |
string |
|
response_condition |
いいえ |
string |
|
cache_condition |
いいえ |
string |
|
src |
はい |
string |
|
substitution |
いいえ |
string |
|
type |
はい |
enum ('request', 'fetch', 'cache', 'response') |
|
ヘルスチェック
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
check_interval |
いいえ |
integer |
|
comment |
いいえ |
string |
'' |
expected_response |
いいえ |
integer |
200 |
host |
はい |
string |
|
http_version |
いいえ |
string |
1.1 |
initial |
いいえ |
integer |
|
method |
いいえ |
string |
HEAD |
path |
いいえ |
string |
'/' |
threshold |
いいえ |
integer |
|
timeout |
いいえ |
integer |
|
window |
いいえ |
integer |
|
リクエスト設定
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
request_condition |
いいえ |
string |
|
action |
いいえ |
enum ('lookup', 'pass') |
|
xff |
いいえ |
enum ('clear', 'leave', 'append', 'append_all', 'overwrite') |
|
hash_keys |
いいえ |
string |
|
default_host |
いいえ |
string |
|
max_stale_age |
いいえ |
integer |
0 |
force_miss |
いいえ |
integer |
0 |
force_ssl |
いいえ |
integer |
0 |
timer_support |
いいえ |
integer |
0 |
geo_headers |
いいえ |
integer |
0 |
bypass_busy_wait |
いいえ |
integer |
0 |
レスポンスオブジェクト
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
request_condition |
いいえ |
string |
|
response |
いいえ |
string |
Ok |
status |
いいえ |
integer |
200 |
content |
いいえ |
string |
|
content_type |
いいえ |
string |
|
VCLスニペット
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
dynamic |
いいえ |
integer |
0 |
type |
いいえ |
string |
"init" |
content |
はい |
string |
|
priority |
いいえ |
integer |
100 |
S3ロギング
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
access_key |
いいえ |
string |
|
bucket_name |
いいえ |
string |
|
domain |
いいえ |
string |
|
format |
いいえ |
string |
%{%Y-%m-%dT%H:%M:%S}t %h "%r" %>s %b |
format_version |
いいえ |
integer |
2 |
gzip_level |
いいえ |
integer |
0 |
message_type |
いいえ |
enum ('classic', 'loggly', 'logplex', 'blank') |
classic |
path |
いいえ |
string |
/ |
period |
いいえ |
integer |
3600 |
placement |
いいえ |
string |
|
redundancy |
いいえ |
string |
|
response_condition |
いいえ |
string |
'' |
secret_key |
いいえ |
string |
|
server_side_encryption_kms_key_id |
いいえ |
string |
|
server_side_encryption |
いいえ |
string |
|
timestamp_format |
いいえ |
string |
%Y-%m-%dT%H |
Syslogロギング
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
name |
はい |
string |
|
address |
はい |
string |
|
format |
いいえ |
string |
%{%Y-%m-%dT%H:%M:%S}t %h "%r" %>s %b |
format_version |
いいえ |
integer |
2 |
hostname |
いいえ |
string |
|
ipv4 |
いいえ |
string |
|
message_type |
いいえ |
enum ('classic', 'loggly', 'logplex', 'blank') |
classic |
placement |
いいえ |
string |
|
port |
はい |
int |
|
response_condition |
いいえ |
string |
'' |
tls_ca_cert |
いいえ |
string |
|
tls_hostname |
いいえ |
string |
|
token |
いいえ |
string |
|
use_tls |
いいえ |
int |
0 |
設定
Fastlyドキュメント
フィールド |
必須 |
種類 |
デフォルト |
general.default_ttl |
いいえ |
integer |
3600 |
例
Playbookでfastly_serviceモジュールを使用する
---
- hosts: localhost
connection: local
gather_facts: False
roles:
- Jimdo.fastly
tasks:
- fastly_service:
name: リダイレクトサービス
domains:
- name: test1.example.net
comment: リダイレクトドメイン
backends:
- name: localhost
port: 80
address: 127.0.0.1
headers:
- name: Locationヘッダーの設定
dst: http.Location
type: response
action: set
src: http://test3.example.net req.url.path
ignore_if_set: 0
priority: 10
response_objects:
- name: 301ステータスコードの設定
status: 301
$ ansible-playbook -i localhost, fastly.yml
開発
テストの実行
FASTLY_API_KEY=some_secret python -m unittest discover tests
VCRカセットの更新
VCR.pyは、HTTPリクエストをモックするためにテストで使用されています。
カセットを更新するには、tests/fixtures/cassettes
ディレクトリを削除し、通常通りテストを実行します。記録を有効にするには、有効なFastly APIキーが必要です。