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 |
是 |
字符串 |
|
port |
否 |
整数 |
80 |
address |
是 |
字符串 |
|
ssl_hostname |
否 |
字符串 |
|
ssl_ca_cert |
否 |
字符串 |
|
ssl_cert_hostname |
否 |
字符串 |
|
shield |
否 |
字符串 |
|
healthcheck |
否 |
字符串 |
|
weight |
否 |
整数 |
100 |
connect_timeout |
否 |
整数 |
1000 |
first_byte_timeout |
否 |
整数 |
15000 |
between_bytes_timeout |
否 |
整数 |
10000 |
error_threshold |
否 |
整数 |
0 |
max_conn |
否 |
整数 |
200 |
缓存设置
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
name |
是 |
字符串 |
|
action |
否 |
枚举 ('cache', 'pass', 'restart') |
|
cache_condition |
否 |
字符串 |
|
stale_ttl |
否 |
整数 |
0 |
条件
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
name |
是 |
字符串 |
|
comment |
否 |
字符串 |
|
priority |
否 |
整数 |
0 |
statement |
是 |
字符串 |
|
type |
是 |
枚举 ('REQUEST', 'PREFETCH', 'CACHE', 'RESPONSE') |
|
导向器
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
name |
是 |
字符串 |
|
backends |
否 |
字符串数组 |
|
capacity |
否 |
整数 |
100 |
comment |
否 |
字符串 |
'' |
quorum |
否 |
整数 |
75 |
shield |
否 |
字符串 |
|
type |
否 |
整数 (1, 2, 3, 4中的一个) |
1 |
retries |
否 |
整数 |
5 |
头部
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
name |
是 |
字符串 |
|
action |
否 |
枚举 ('set', 'append', 'delete', 'regex', 'regex_repeat') |
set |
dst |
是 |
字符串 |
|
ignore_if_set |
否 |
整数 (0, 1中的一个) |
0 |
priority |
否 |
整数 |
100 |
regex |
否 |
字符串 |
|
request_condition |
否 |
字符串 |
|
response_condition |
否 |
字符串 |
|
cache_condition |
否 |
字符串 |
|
src |
是 |
字符串 |
|
substitution |
否 |
字符串 |
|
type |
是 |
枚举 ('request', 'fetch', 'cache', 'response') |
|
健康检查
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
name |
是 |
字符串 |
|
check_interval |
否 |
整数 |
|
comment |
否 |
字符串 |
'' |
expected_response |
否 |
整数 |
200 |
host |
是 |
字符串 |
|
http_version |
否 |
字符串 |
1.1 |
initial |
否 |
整数 |
|
method |
否 |
字符串 |
HEAD |
path |
否 |
字符串 |
'/' |
threshold |
否 |
整数 |
|
timeout |
否 |
整数 |
|
window |
否 |
整数 |
|
请求设置
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
name |
是 |
字符串 |
|
request_condition |
否 |
字符串 |
|
action |
否 |
枚举 ('lookup', 'pass') |
|
xff |
否 |
枚举 ('clear', 'leave', 'append', 'append_all', 'overwrite') |
|
hash_keys |
否 |
字符串 |
|
default_host |
否 |
字符串 |
|
max_stale_age |
否 |
整数 |
0 |
force_miss |
否 |
整数 |
0 |
force_ssl |
否 |
整数 |
0 |
timer_support |
否 |
整数 |
0 |
geo_headers |
否 |
整数 |
0 |
bypass_busy_wait |
否 |
整数 |
0 |
响应对象
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
name |
是 |
字符串 |
|
request_condition |
否 |
字符串 |
|
response |
否 |
字符串 |
Ok |
status |
否 |
整数 |
200 |
content |
否 |
字符串 |
|
content_type |
否 |
字符串 |
|
VCL 片段
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
name |
是 |
字符串 |
|
dynamic |
否 |
整数 |
0 |
type |
否 |
字符串 |
"init" |
content |
是 |
字符串 |
|
priority |
否 |
整数 |
100 |
S3 日志记录
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
name |
是 |
字符串 |
|
access_key |
否 |
字符串 |
|
bucket_name |
否 |
字符串 |
|
domain |
否 |
字符串 |
|
format |
否 |
字符串 |
%{%Y-%m-%dT%H:%M:%S}t %h "%r" %>s %b |
format_version |
否 |
整数 |
2 |
gzip_level |
否 |
整数 |
0 |
message_type |
否 |
枚举 ('classic', 'loggly', 'logplex', 'blank') |
classic |
path |
否 |
字符串 |
/ |
period |
否 |
整数 |
3600 |
placement |
否 |
字符串 |
|
redundancy |
否 |
字符串 |
|
response_condition |
否 |
字符串 |
'' |
secret_key |
否 |
字符串 |
|
server_side_encryption_kms_key_id |
否 |
字符串 |
|
server_side_encryption |
否 |
字符串 |
|
timestamp_format |
否 |
字符串 |
%Y-%m-%dT%H |
Syslog 日志记录
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
name |
是 |
字符串 |
|
address |
是 |
字符串 |
|
format |
否 |
字符串 |
%{%Y-%m-%dT%H:%M:%S}t %h "%r" %>s %b |
format_version |
否 |
整数 |
2 |
hostname |
否 |
字符串 |
|
ipv4 |
否 |
字符串 |
|
message_type |
否 |
枚举 ('classic', 'loggly', 'logplex', 'blank') |
classic |
placement |
否 |
字符串 |
|
port |
是 |
整数 |
|
response_condition |
否 |
字符串 |
'' |
tls_ca_cert |
否 |
字符串 |
|
tls_hostname |
否 |
字符串 |
|
token |
否 |
字符串 |
|
use_tls |
否 |
整数 |
0 |
设置
Fastly 文档
字段 |
必需 |
类型 |
默认值 |
general.default_ttl |
否 |
整数 |
3600 |
示例
在 Playbook 中使用 fastly_service 模块
---
- hosts: localhost
connection: local
gather_facts: False
roles:
- Jimdo.fastly
tasks:
- fastly_service:
name: Redirect service
domains:
- name: test1.example.net
comment: redirect domain
backends:
- name: localhost
port: 80
address: 127.0.0.1
headers:
- name: Set Location header
dst: http.Location
type: response
action: set
src: http://test3.example.net req.url.path
ignore_if_set: 0
priority: 10
response_objects:
- name: Set 301 status code
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 密钥才能录制工作。