Ansible2.1がARMに対応したので"少しだけ"試してみた #2

先日、Ansible2.1でARMを試した記事を書きましたが、その後もう少し深くいじってみました。

kaz29.hatenablog.com

前回はリソースグループを作っただけでしたが、今回は、牛尾さん(id:simplearchitect)の以下の記事でTerraformを使ってやっていることをなぞってみました。

qiita.com

設定内容

設定した内容はこんな感じ。yamlでかけるのは読みやすくていいですね。

---

azure_resource_group:
  - name: Testing
    region: japanwest
    state: present
    tags:
      testing: testing
      delete: never

azure_virtual_network:
  - name: test
    state: present
    resource_group: Testing
    address_prefixes_cidr:
        - "10.1.0.0/16"
    dns_servers: []
    tags:
        testing: testing
        delete: on-exit

azure_subnet:
  - name: acctsub
    state: present
    virtual_network_name: test
    resource_group: Testing
    address_prefix_cidr: "10.1.2.0/24"

azure_publicipaddress:
  - name: ansibletestip
    state: present
    resource_group: Testing
    allocation_method: Static
    domain_name: ansibletestlinux
    tags:
        testing: testing
        environment: Production

azure_networkinterface:
  - name: testnic1
    state: present
    resource_group: Testing
    virtual_network_name: test
    subnet_name: acctsub
    security_group_name: 
    public_ip_address_name: ansibletestip
    private_ip_allocation_method: Static
    private_ip_address: 10.1.2.10
    tags:
        testing: testing

azure_storage_account:
  - name: accsa1971eey
    state: present
    resource_group: Testing
    type: Standard_LRS
    tags:
        testing: testing

azure_storage_container:
  - name: vhds
    state: present
    resource_group: Testing
    storage_account_name: accsa1971eey
    tags:
      testing: testing

azure_virtualmachine:
  - name: AnsibleVM02
    state: present
    resource_group: Testing
    vm_size: Standard_A0
    storage_account: accsa1971eey
    storage_container_name: vhds
    network_interfaces: testnic1
    admin_username: kaz
    remove_on_absent:
      - virtual_storage
    image:
      offer: UbuntuServer
      publisher: Canonical
      sku: '14.04.2-LTS'
      version: latest
    tags:
      testing: testing

Ansibleを使用して実行してる内容は以下。

  1. ストレージクループの作成
  2. 仮想ネットワークの作成
  3. サブネットの作成
  4. パブリックIPアドレスの作成
  5. ネットワークI/Fを作成
  6. ストレージアカウントの作成
  7. ストレージコンテナの作成
  8. VMの作成

今回作ったものはGithubにあげましたので参考になれば。

github.com

ポータルを使わないで、いつものAnsibleで構築して何回でもやり直せるのはかなり便利ですね。

まとめ

まだ理解しきてれていないので、VMを削除しようとしたらエラーが出てうまく削除できませんでした。VM削除時に自動で消されるものがあるようなので、その辺りが原因(`remove_on_absent`)かなと思うので、もう少し調べようと思います。

とはいえ、ポータルをポチポチしないで良いのはとても便利なので今後 Terraformとどっちを使うかも含めて色々検討しようと思います。