1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

AnsibleでVMwareにあるtemplateからの起動及び設定を自動化

Last updated at Posted at 2020-08-06

はじめに

VMwareをAnsibleで操作する機会があったのでメモ。
vmware_guestモジュールを使用して、VMWwareのテンプレートを展開し、設定するという動作を自動化します。
Jekinsとかでジョブ化すると便利です。

前提事項

vCenterがないと、vmware_guestモジュールは使えないです。

vmware_guestモジュール

---
- name: VM from Template and customize
  vmware_guest:
  # vCenterの情報
    hostname: "{{ vcenter_hostname }}" 
    username: "{{ vcenter_username  }}" 
    password: "{{ vcenter_password }}" 
  # 仮想マシンの設定
    validate_certs: False                   # 初回SSHの確認をしない。
    datacenter: "{{ datacenter_name }}"    # データセンターの指定
    esxi_hostname: "{{ esxi_host }}"        # 仮想マシン起動するesxiを指定    
    folder: "{{ vm_folder }}"              # フォルダを指定
    template: "{{ vm_template }}"           # templateを指定 
    name: "{{ vm_name }}"                   # 仮想マシン名を指定    
    state: poweredon                        # パワーオンして起動
    wait_for_ip_address: yes                # 起動していることを確認

  # ディスクの設定
    disk:
    - size_gb: "{{ vm_storage }}" 
      type: thin
      datastore: "{{ datastore_name }}"     # 使用するデータストア

  # メモリ、CPUの設定
    hardware:
      memory_mb: "{{ vm_memory }}" 
      num_cpu_cores_per_socket: "{{ vm_cpu }}"      # 1ソケットあたりのコア数

  # ネットワークの設定
    networks:
    - name: VM Network
      type: static
      ip: "{{ vm_ip }}" 
      netmask: "{{ netmask }}" 
      gateway: "{{ gateway }}" 

   # DNSの設定     
    customization:
      dns_servers:
      - "{{ dns_servers }}"

  delegate_to: localhost             # コントロールノードで実行                  

delegate_to: localhost でコントロールノードを指定して実行する必要があります。

まとめ

内部的にVCenterのAPIをたたきに行っているようなので、VCenterの性能を越える処理をできない。
いっぺんにたくさんのノードを起動するのにはあまり向いていない。良い方法はないだろうか。
Ansibleは公式ドキュメントが分かりやすい。それだけで、Ansibleが好きになりそう。

参考文献

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?