daniel-rhoades.aws-elb
aws-elb-role
============
AWSアカウント内でのELBのプロビジョニングと廃止を簡素化するためのAnsibleロールです。
詳細に関しては以下をご覧ください:
- Auto-scaling Groups: http://docs.ansible.com/ansible/ec2_elb_lb__module.html;
- Route 53: http://docs.ansible.com/ansible/route53_module.html.
このロールは、マルチAZ ELBを完全に設定し、指定したゾーンのRoute 53レコードに登録します。
必要条件
最新のAnsible EC2サポートモジュールとBotoが必要です。
AWSと共に使用するためにAnsible環境の設定も必要です。詳細は http://docs.ansible.com/ansible/guide_aws.html を参照してください。
ロール変数
デフォルト
- elb_purge_subnets: 指定されていないELBの既存リスナーを廃止、デフォルトはtrue;
- elb_cross_az_load_balancing: すべての構成されたアベイラビリティゾーンに負荷を分散、デフォルトはtrue;
- elb_connection_draining_timeout: インスタンスを終了する前に接続が切れるのを待つ指定されたタイムアウト、デフォルトは60秒;
- elb_listeners: ELBのリスナー、80:80はデフォルトで使用可能;
- elb_health_check: インスタンスの健康を判断するために実行するヘルスチェック、デフォルトはポート80へのTCP接続;
- route53_overwrite: 必要に応じて既存のエントリを上書き、デフォルトはtrue;
- route53_alias_evaluate_target_health: Route 53がターゲットの健康を監視するか、デフォルトはtrue;
- ec2_elb_state: ELBの状態、デフォルトは「present」;
- route53_zone_state: Route 53ゾーンの状態、デフォルトは「present」。
必須変数:
- elb_name: 作成したいELBの名前を指定する必要があります。例: my-elb;
- elb_security_groups: 作成するELBに適用するセキュリティグループを指定する必要があります。例のプレイブックをご参照ください;
- elb_region: ELBを作成するリージョンを指定する必要があります。例: eu-west-1;
- elb_subnets: ELBを利用可能にするサブネットを指定する必要があります。例のプレイブックをご参照ください;
- route53_zone: 定義するゾーンの名前を指定する必要があります。例: example.com;
- route53_host: ゾーンで定義するホストの名前を指定する必要があります。例: www.example.com。
依存関係
Galaxyにホスティングされている他のロールのリストをここに記載し、他のロールに必要なパラメータや使用される変数の詳細を記載してください。
例のプレイブック
このロールを使用する前に、ロールをインストールする必要があります。最も簡単な方法は、ansible-galaxy install daniel-rhoades.aws-elb-role
です。
完全性のために、例では以下を作成します:
- ECSクラスタを保持するためのVPC、ロールを使用:
daniel-rhoades.aws-vpc
; - EC2インスタンスに適用するためのEC2セキュリティグループ、ロールを使用:
daniel-rhoades.aws-security-group
.
作成後、EC2インスタンスをELBに登録できます。例ではmy_route53_zone
をコマンドライン環境変数として渡すことを想定しています。
- name: My System | すべての必要なインフラをプロビジョニング
hosts: localhost
connection: local
gather_facts: no
vars:
my_vpc_name: "my_example_vpc"
my_vpc_region: "eu-west-1"
my_vpc_cidr: "172.40.0.0/16"
everywhere_cidr: "0.0.0.0/0"
# VPC内のサブネット
my_vpc_subnets:
- cidr: "172.40.10.0/24"
az: "{{ my_vpc_region }}a"
- cidr: "172.40.20.0/24"
az: "{{ my_vpc_region }}b"
# サブネットが外部と通信できるようにする
my_public_subnet_routes:
- subnets:
- "{{ my_vpc_subnets[0].cidr }}"
- "{{ my_vpc_subnets[1].cidr }}"
routes:
- dest: "{{ everywhere_cidr }}"
gw: igw
# インバウンドセキュリティグループ、例: ロードバランサなどの公開サービス
my_inbound_security_groups:
- sg_name: inbound-web
sg_description: httpおよびhttpsアクセスを許可(公開)
sg_rules:
- proto: tcp
from_port: 80
to_port: 80
cidr_ip: "{{ everywhere_cidr }}"
- proto: tcp
from_port: 443
to_port: 443
cidr_ip: "{{ everywhere_cidr }}"
# VPC内からのSSHアクセスのみを許可、VPC内のサービスにアクセスするには一時的なバスティオンホストを作成する必要があります
- sg_name: inbound-ssh
sg_description: sshアクセスを許可
sg_rules:
- proto: tcp
from_port: 22
to_port: 22
cidr_ip: "{{ my_vpc_cidr }}"
# 内部のインバウンドセキュリティグループ、例: ロードバランサの背後にあるウェブサーバなど
my_internal_inbound_security_groups_file: "internal-securitygroups.yml"
# アウトバウンドルール、例: ウェブサーバが直接アクセスできるサービス
my_outbound_security_groups:
- sg_name: outbound-all
sg_description: すべてのIPアドレスへのアウトバウンドトラフィックを許可
sg_rules:
- proto: all
cidr_ip: "{{ everywhere_cidr }}"
# ELBの名前
my_elb_name: "my-elb"
# Route 53ゾーンに作成するホストの名前
my_route53_host: "my-service-test"
roles:
# ネットワークをプロビジョニング
- {
role: daniel-rhoades.aws-vpc,
vpc_name: "{{ my_vpc_name }}",
vpc_region: "{{ my_vpc_region }}",
vpc_cidr_block: "{{ my_vpc_cidr }}",
vpc_subnets: "{{ my_vpc_subnets }}",
public_subnet_routes: "{{ my_public_subnet_routes }}"
}
# セキュリティグループをプロビジョニング
- {
role: daniel-rhoades.aws-security-groups,
vpc_region: "{{ my_vpc_region }}",
vpc_id: "{{ vpc.vpc_id }}",
ec2_group_inbound_sg: "{{ my_inbound_security_groups }}",
ec2_group_internal_inbound_sg_file: "{{ my_internal_inbound_security_groups_file }}",
ec2_group_outbound_sg: "{{ my_outbound_security_groups }}"
}
# ELBをプロビジョニングし、Route 53でエイリアスとして登録
- {
role: aws-elb-role,
elb_name: "{{ my_elb_name }}",
vpc_name: "{{ my_vpc_name }}",
elb_security_groups: [
"{{ ec2_group_inbound_sg.results[0].group_id }}"
],
elb_region: "{{ my_vpc_region }}",
elb_subnets: [
"{{ vpc.subnets[0].id }}",
"{{ vpc.subnets[1].id }}"
],
route53_zone: "{{ my_route53_zone }}",
route53_host: "{{ my_route53_host }}"
}
例のinternal-securitygroups.yml
は以下のようになります:
ec2_group_internal_inbound_sg:
- sg_name: inbound-web-internal
sg_description: httpおよびhttpsアクセスを許可(ロードバランサからのみ)
sg_rules:
- proto: tcp
from_port: 80
to_port: 80
group_id: "{{ ec2_group_inbound_sg.results[0].group_id }}"
ELBを廃止するには:
- name: My System | すべての必要なインフラを廃止
hosts: localhost
connection: local
gather_facts: no
vars:
my_vpc_name: "my_example_vpc"
my_vpc_region: "eu-west-1"
my_vpc_cidr: "172.40.0.0/16"
everywhere_cidr: "0.0.0.0/0"
# VPC内のサブネット
my_vpc_subnets:
- cidr: "172.40.10.0/24"
az: "{{ my_vpc_region }}a"
- cidr: "172.40.20.0/24"
az: "{{ my_vpc_region }}b"
# サブネットが外部と通信できるようにする
my_public_subnet_routes:
- subnets:
- "{{ my_vpc_subnets[0].cidr }}"
- "{{ my_vpc_subnets[1].cidr }}"
routes:
- dest: "{{ everywhere_cidr }}"
gw: igw
# 作成するECSクラスタの名前
my_ecs_cluster_name: "my-cluster"
# ELBの名前
my_elb_name: "my-elb"
# Route 53ゾーンに作成するホストの名前
my_route53_host: "my-service-test"
roles:
# ネットワークをプロビジョニング
- {
role: daniel-rhoades.aws-vpc,
vpc_name: "{{ my_vpc_name }}",
vpc_region: "{{ my_vpc_region }}",
vpc_cidr_block: "{{ my_vpc_cidr }}",
vpc_subnets: "{{ my_vpc_subnets }}",
public_subnet_routes: "{{ my_public_subnet_routes }}"
}
# セキュリティグループをプロビジョニング
- {
role: daniel-rhoades.aws-security-groups,
vpc_region: "{{ my_vpc_region }}",
vpc_id: "{{ vpc.vpc_id }}",
ec2_group_inbound_sg: "{{ my_inbound_security_groups }}",
ec2_group_internal_inbound_sg_file: "{{ my_internal_inbound_security_groups_file }}",
ec2_group_outbound_sg: "{{ my_outbound_security_groups }}"
}
# ELBを廃止(RESTエンドポイント)
- {
role: aws-elb-role,
ec2_elb_state: "absent",
vpc_name: "{{ my_vpc_name }}",
elb_name: "{{ my_elb_name }}",
route53_zone: "{{ my_route53_zone }}",
route53_host: "{{ my_route53_host }}"
}
ライセンス
MIT
著者情報
Daniel Rhoades (https://github.com/daniel-rhoades)