LoginSignup
6
7

More than 5 years have passed since last update.

ansibleのroute53モジュールで指定するalias_hosted_zone_idは固定値だよ

Last updated at Posted at 2016-02-14

概要

ansibleでs3の独自ドメインwebsite公開をしようとして、Management Consoleでやっていたら素直にできるんだけど、ansibleで自動化しようとしたら alias_hosted_zone_id ってどっから取ってくるんだよと小一時間悩んでいた。

結論

公式ページに書いてあったわ。

Asia Pacific (Tokyo)は Z2M4EHUR26P7ZW
他リージョンも上記ページ内に書いてある。

ELBなどではユーザごとに作るからIDを自分で取ってくるというのはわかるけれど
Route53のDNSは自分で作れるものじゃないから
IDは固定に決まってるじゃん、と問題が解決した後に気がついた。

playbook

こんな感じになった。

- name: "create bucket {{ bucket_name }}"
  s3: bucket="{{ bucket_name }}" region="ap-northeast-1" mode="create" permission="public-read"

- name: "setup bucket {{ bucket_name }}"
  s3_bucket:
    name:   "{{ bucket_name }}"
    region: "ap-northeast-1" 
    policy: |
      {   
        "Version":"2012-10-17",
        "Statement":[{
            "Sid":"AddPerm",
            "Effect":"Allow",
            "Principal": "*",
            "Action":["s3:GetObject"],
            "Resource":[
              "arn:aws:s3:::{{ bucket_name }}/*"
            ]   
        }]  
      }   

- name: "static web setting {{ bucket_name }}"
  command: "aws s3 website s3://{{ bucket_name }} --index-document index.html --error-document error.html"

- name: "dns setting: {{ bucket_name }}"
  route53:
    command: create
    zone:    "mogemoge.com."
    type:    "A" 
    record:  "site.mogemoge.com."
    value:   "s3-website-ap-northeast-1.amazonaws.com."
    alias:   yes 
    # Asia Tokyo's hosted zone id.
    # see http://docs.aws.amazon.com/general/latest/gr/rande.html#s3_region
    alias_hosted_zone_id: Z2M4EHUR26P7ZW

参照

詳しいセットアップ方法は丁寧に書いてある下記サイトをご参照。

6
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
7