infrastructure as code lt aws + ansibleのお悩み相談

9
AWS + Ansibleお悩み相談 Infrastructure as Code現状確認会 LT @ クックパッド @sechiro

Upload: seiichiro-ishida

Post on 10-Jun-2015

3.330 views

Category:

Software


6 download

DESCRIPTION

クックパッドで開催されたInfrastructure as codeのLT資料です。

TRANSCRIPT

Page 1: Infrastructure as code LT AWS + Ansibleのお悩み相談

AWS + Ansibleの お悩み相談

Infrastructure as Code現状確認会 LT @ クックパッド

@sechiro

Page 2: Infrastructure as code LT AWS + Ansibleのお悩み相談

せちろー (@sechiro)

• qpstudyスタッフ(2010~)

• サーバ擬人化エヴァンジェリスト(2011/

02~)

• 双六工場長(2011/12~)

• シャッツキステポイントカード 63枚目

• クックパッドプレミアム会員(2010/04~)

時代の斜め先ゆく、サーバ擬人化エヴァンジェリスト

Illustration by @ayakomuro

Page 3: Infrastructure as code LT AWS + Ansibleのお悩み相談

相談内容

Page 4: Infrastructure as code LT AWS + Ansibleのお悩み相談

相談内容

• EC2インスタンス作成の時の変数設定

• EC2ホストを追加した時のホスト名自動採番

Page 5: Infrastructure as code LT AWS + Ansibleのお悩み相談

EC2インスタンス起動時のつらみ

- name: Create a sandbox instance hosts: localhost gather_facts: False vars: key_name: my_keypair instance_type: m1.small security_group: my_securitygroup image: my_ami_id region: us-east-1 tasks: - name: Launch instance local_action: ec2 key_name={{ keypair }} group={{ security_group }} instance_type={{ instance_type }} image={{ image }} wait=true region={{ region }} register: ec2

• EC2などのAWS系モジュールは「hosts: localhost」で動作

• 素直にPlaybookを実行しようと思うと、EC2を操作するPlaybookは「-i localhost」で実行

• “staging”, “production”などのインベントリ管理とか変数管理ができなくてつらい

AnsibleのEC2モジュールページより

Page 6: Infrastructure as code LT AWS + Ansibleのお悩み相談

対応1 group_vars/all 案

• group_vars/allに書いてあると、すべてのプレイブックから読み込めるので、ファイルを複数用意してシンボリックリンクで切替 • group_vars/all.staging.yml • group_vars/all.production.yml

• Ansibleの世界で完結できないので、結局つらみが残る

Page 7: Infrastructure as code LT AWS + Ansibleのお悩み相談

対応2 ダミーグループ

• EC2用のインベントリファイル作成

• “staging-ec2”, “production-ec2”を容易

!

!

!

!

!

• これだと”-i staging-ec2”みたいにかける

[ec2-webserver] localhost ![ec2-webserver:vars] region=ap-northeast-1 ssh_key=xxxxxx

- name: Create a instance hosts: ec2-webserver gather_facts: False …

inventory playbook

Page 8: Infrastructure as code LT AWS + Ansibleのお悩み相談

ホスト名自動採番のつらみ

• ホスト名を自動採番したい(OpsWorksではできた)

• homura01 • homura02 • ….

• Ansibleで、こういうカウンターをどう持つのか

• そのほかにもRDSのEndpointを動的に設定する場合とか

• 現状は、Playbookの中でYAMLを書き換えてインクリメントしててつらい

Page 9: Infrastructure as code LT AWS + Ansibleのお悩み相談

ありがとうございました。