[VMware] Ansible を使用して vCenter Server をデプロイする

今回は Ansible を使用して vCenter Server 8.0 U3d をデプロイした際の内容を記事にします。

クライアント OS: AlmaLinux 9.5
デプロイする vCSA のネットワーク: DHCP で IP 割り当て
Ansible バージョン: core 2.18.4rc1
VMware Collection:community.vmware 5.5.0

vi deploy_vcsa.yml

vars の値や networks のポートグループ名について、適宜変更が必要となります。

---
- name: Deploy vCSA 8.0 with DHCP-based FQDN
  hosts: localhost
  connection: local
  gather_facts: false
  collections:
    - community.vmware

  vars:
    #=== デプロイ先 vSphere 接続情報
    # デプロイ先 vCSA/ESXi のホスト名/IP
    deploy_hostname: "192.168.17.17"
    # 接続ユーザ
    deploy_username: "administrator@vsphere.local"
    # 上記ユーザのパスワード
    deploy_password: "VMware1!"
    # SSL 証明書の検証を行うかどうか
    validate_certs: no

    #=== デプロイ先 vSphere リソース情報
    # デプロイ先の Datacenter 名
    datacenter_name: "Datacenter"
    # デプロイ先の Cluster 名
    cluster_name: "cluster"
    # デプロイ先の VMフォルダ名 (空文字=デフォルト)
    folder_name: ""
    # デプロイ先のデータストア名
    datastore_name: "WD_BlackSN750"
    # ディスクのプロビジョニングモード
    disk_mode: "thin"

    #=== OVA/VM 名など
    # vCSA OVA ファイルのパス
    vcsa_ova_path: "/mnt/vcsa_iso/vcsa/VMware-vCenter-Server-Appliance-8.0.3.00400-24322831_OVF10.ova"
    # デプロイする vCSA の仮想マシン名
    vcsa_vm_name: "test-vcsa-dhcp"

    #=== デプロイする vCSA の root パスワード + SSO
    # vCSA アプライアンス(OS)の root パスワード
    vcsa_root_password: "VMware1!"
    # SSO 管理者のユーザ名
    vcsa_sso_username: "administrator@vsphere.local"
    # 上記 SSO 管理者のパスワード
    vcsa_sso_password: "VMware1!"
    # SSO ドメイン名 (デフォルト vsphere.local など)
    vcsa_sso_domain: "vsphere.local"

  tasks:
    - name: Deploy vCSA OVA (DHCPでホスト名取得) with enable_hidden_properties
      community.vmware.vmware_deploy_ovf:
        # vCSA/ESXi に接続するためのホスト名/IP
        hostname: "{{ deploy_hostname }}"
        # 接続に使用する認証情報
        username: "{{ deploy_username }}"
        password: "{{ deploy_password }}"
        # SSL 証明書の検証を実施しない
        validate_certs: "{{ validate_certs }}"
        # デプロイ先 Datacenter 名
        datacenter: "{{ datacenter_name }}"
        # デプロイ先 Cluster 名
        cluster: "{{ cluster_name }}"
        # VM を配置するフォルダ (空文字=デフォルト)
        folder: "{{ folder_name }}"
        # デプロイ先のデータストア名
        datastore: "{{ datastore_name }}"
        # OVA ファイルのパス
        ovf: "{{ vcsa_ova_path }}"
        # 作成される仮想マシンの名前
        name: "{{ vcsa_vm_name }}"
        # ディスクプロビジョニングモード
        disk_provisioning: "{{ disk_mode }}"
        # デプロイ後に VM の電源を ON にする
        power_on: yes
        # タスクが完了するまで待機 (OVA展開含む)
        wait: yes
        # デプロイ完了後、VMware Tools 経由で IP取得を待機
        wait_for_ip_address: yes
        # ovf ファイル内の userConfigurable="false" プロパティを上書き
        enable_hidden_properties: true

        # ovf ファイル内の "Network 1" を "17v" に変更
        networks:
          "Network 1": "17v"

        # OVF プロパティの設定
        properties:
          # Stage2 を自動実行させるフラグ
          guestinfo.cis.deployment.autoconfig: "True"
          # アプライアンス root パスワード
          guestinfo.cis.appliance.root.passwd: "{{ vcsa_root_password }}"
          # SSH 有効化 (userConfigurable="false"の可能性あり)
          guestinfo.cis.appliance.ssh.enabled: "True"
          # IPv4/IPv6 指定
          guestinfo.cis.appliance.net.addr.family: "ipv4"
          # DHCP で IP を取得
          guestinfo.cis.appliance.net.mode: "dhcp"
          # IP 未指定時は空文字
          guestinfo.cis.appliance.net.addr: ""
          guestinfo.cis.appliance.net.prefix: ""
          guestinfo.cis.appliance.net.gateway: ""
          guestinfo.cis.appliance.net.dns.servers: ""
          # PNID (FQDN/IP) 未指定(空文字) -> DHCP 取得
          guestinfo.cis.appliance.net.pnid: ""
          # VMware Tools の時刻同期を有効化
          guestinfo.cis.appliance.time.tools-sync: "True"
          # NTP ーバ (今回空文字)
          guestinfo.cis.appliance.ntp.servers: ""
          # SSO 管理者ユーザ名(本来変更不可の場合もある)
          guestinfo.cis.vmdir.username: "{{ vcsa_sso_username }}"
          # SSO 管理者パスワード
          guestinfo.cis.vmdir.password: "{{ vcsa_sso_password }}"
          # SSO ドメイン名(デフォルトvsphere.local)
          guestinfo.cis.vmdir.domain-name: "{{ vcsa_sso_domain }}"
          # CEIP (改善プログラム)の無効化
          guestinfo.cis.ceip_enabled: "False"
          # デプロイサイズ (tiny/small/medium/large 等)
          guestinfo.cis.appliance.deployment.option: "tiny"

      register: deploy_result

    - name: Debug deploy_result
      # デプロイ結果を変数 deploy_result から出力
      debug:
        var: deploy_result

    - name: Wait for vCSA VM to obtain IP address (re-check)
      # vCSA が IP 取得しているか再確認
      community.vmware.vmware_guest_info:
        hostname: "{{ deploy_hostname }}"
        username: "{{ deploy_username }}"
        password: "{{ deploy_password }}"
        validate_certs: no
        name: "{{ vcsa_vm_name }}"
      register: guest_info
      # IP が取れるまでリトライ(30秒ごと 最大60回)
      until: >
        guest_info.instance is defined
        and guest_info.instance.ipv4 is defined
        and guest_info.instance.ipv4 | length > 0
      retries: 60
      delay: 30

    - name: Debug discovered IP
      # 取得した IP を表示
      debug:
        msg: >
          "Deployed vCSA IP = {{ guest_info.instance.ipv4 }}"

    - name: Wait for vCenter Stage2 completion
      # vCenter の Stage2(初期構成)完了をAPI応答で判断
      community.vmware.vmware_about_info:
        hostname: "{{ guest_info.instance.ipv4 | default('') | trim }}"
        username: "{{ vcsa_sso_username }}"
        password: "{{ vcsa_sso_password }}"
        validate_certs: no
      register: about_info
      # 1分おき 最大 60分リトライ
      retries: 60
      delay: 60
      until: not about_info.failed

    - name: Debug about_info
      # Stage2 完了後、vCSA バージョン等を確認
      debug:
        var: about_info

ハマりポイントとして Playbook を実行した際に vSphere Client 上で
「プロパティ guestinfo.cis.vmdir.username はユーザー設定可能ではありません。」
のようなエラーが発生しました。(guestinfo.cis.vmdir.username は変わる可能性あり)

上記エラーは ova を展開した中にある ovf ファイル内で userConfigurable=”false” が
定義されているプロパティは値を設定を上書き出来ないというエラーみたいです。

Playbook 内で enable_hidden_properties: true を指定することで
userConfigurable=”false” が定義されているプロパティでも設定を上書きできるよう
になりました。

Ansible Community Documentation
-> enable_hidden_properties

ansible-playbook deploy_vcsa.yml

実行結果は以下のようになります。

[root@ss070 ansible_test]# ansible-playbook deploy_vcsa.yml
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [Deploy vCSA 8.0 with DHCP-based FQDN] ***********************************************************************************************

TASK [Deploy vCSA OVA (DHCPでホスト名取得) with enable_hidden_properties] *****************************************************************
changed: [localhost]

TASK [Debug deploy_result] ****************************************************************************************************************
ok: [localhost] => {
    "deploy_result": {
        "changed": true,
        "failed": false,
        "instance": {
            "advanced_settings": {
                "ethernet0.pciSlotNumber": "160",
                "guestinfo.ovfEnv": "",
                "hpet0.present": "TRUE",
                "migrate.hostLog": "test-vcsa-dhcp-7a2a0be5.hlog",
                "migrate.hostLogState": "none",
                "migrate.migrationId": "0",
                "monitor.phys_bits_used": "40",
                "nvram": "test-vcsa-dhcp.nvram",
                "pciBridge0.pciSlotNumber": "17",
                "pciBridge0.present": "TRUE",
                "pciBridge4.functions": "8",
                "pciBridge4.pciSlotNumber": "21",
                "pciBridge4.present": "TRUE",
                "pciBridge4.virtualDev": "pcieRootPort",
                "pciBridge5.functions": "8",
                "pciBridge5.pciSlotNumber": "22",
                "pciBridge5.present": "TRUE",
                "pciBridge5.virtualDev": "pcieRootPort",
                "pciBridge6.functions": "8",
                "pciBridge6.pciSlotNumber": "23",
                "pciBridge6.present": "TRUE",
                "pciBridge6.virtualDev": "pcieRootPort",
                "pciBridge7.functions": "8",
                "pciBridge7.pciSlotNumber": "24",
                "pciBridge7.present": "TRUE",
                "pciBridge7.virtualDev": "pcieRootPort",
                "sched.swap.derivedName": "/vmfs/volumes/676f401f-3613fa60-dd23-d094663b9e70/test-vcsa-dhcp/test-vcsa-dhcp-4082eae7.vswp",
                "scsi0.pciSlotNumber": "16",
                "scsi0:0.redo": "",
                "scsi0:1.redo": "",
                "scsi0:10.redo": "",
                "scsi0:11.redo": "",
                "scsi0:12.redo": "",
                "scsi0:13.redo": "",
                "scsi0:14.redo": "",
                "scsi0:15.redo": "",
                "scsi0:2.redo": "",
                "scsi0:3.redo": "",
                "scsi0:4.redo": "",
                "scsi0:5.redo": "",
                "scsi0:6.redo": "",
                "scsi0:8.redo": "",
                "scsi0:9.redo": "",
                "scsi1.pciSlotNumber": "32",
                "scsi1:0.redo": "",
                "scsi1:1.redo": "",
                "scsi2.pciSlotNumber": "33",
                "softPowerOff": "FALSE",
                "svga.present": "TRUE",
                "viv.moid": "92aae6c1-5064-4eba-b696-e5f15aca5533:vm-40170:hvaFUErVIg02Q6s8V1CTXAMXYXKdlMb0BhBvSE0tZCE=",
                "vmotion.checkpointFBSize": "4194304",
                "vmware.tools.internalversion": "12389",
                "vmware.tools.requiredversion": "12448",
                "vmxstats.filename": "test-vcsa-dhcp.scoreboard"
            },
            "annotation": "VMware vCenter Server Appliance",
            "current_snapshot": null,
            "customvalues": {},
            "guest_consolidation_needed": false,
            "guest_question": null,
            "guest_tools_status": "guestToolsNotRunning",
            "guest_tools_version": "12389",
            "hw_cluster": "cluster",
            "hw_cores_per_socket": 1,
            "hw_datastores": [
                "WD_BlackSN750"
            ],
            "hw_esxi_host": "192.168.17.21",
            "hw_eth0": {
                "addresstype": "assigned",
                "ipaddresses": null,
                "label": "Network adapter 1",
                "macaddress": "00:50:56:a6:1e:ba",
                "macaddress_dash": "00-50-56-a6-1e-ba",
                "portgroup_key": null,
                "portgroup_portkey": null,
                "summary": "17v"
            },
            "hw_files": [
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp.vmx",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp.vmsd",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp.nvram",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_1.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_2.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_3.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_4.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_5.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_6.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_7.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_8.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_9.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_10.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_11.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_12.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_13.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_14.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_15.vmdk",
                "[WD_BlackSN750] test-vcsa-dhcp/test-vcsa-dhcp_16.vmdk"
            ],
            "hw_folder": "/Datacenter/vm",
            "hw_guest_full_name": null,
            "hw_guest_ha_state": null,
            "hw_guest_id": null,
            "hw_interfaces": [
                "eth0"
            ],
            "hw_is_template": false,
            "hw_memtotal_mb": 14336,
            "hw_name": "test-vcsa-dhcp",
            "hw_power_status": "poweredOn",
            "hw_processor_count": 2,
            "hw_product_uuid": "4226d7a1-563d-b42c-be7f-03d47a0533c5",
            "hw_version": "vmx-10",
            "instance_uuid": "50264e80-fd01-190b-f652-c902563a3a2f",
            "ipv4": null,
            "ipv6": null,
            "module_hw": true,
            "moid": "vm-40170",
            "snapshots": [],
            "tpm_info": {
                "provider_id": null,
                "tpm_present": false
            },
            "vimref": "vim.VirtualMachine:vm-40170",
            "vnc": {}
        }
    }
}

TASK [Wait for vCSA VM to obtain IP address (re-check)] ***********************************************************************************
ok: [localhost]

TASK [Debug discovered IP] ****************************************************************************************************************
ok: [localhost] => {
    "msg": "\"Deployed vCSA IP = 192.168.17.232\"\n"
}

TASK [Wait for vCenter Stage2 completion] *************************************************************************************************
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (60 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (59 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (58 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (57 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (56 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (55 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (54 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (53 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (52 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (51 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (50 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (49 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (48 retries left).
FAILED - RETRYING: [localhost]: Wait for vCenter Stage2 completion (47 retries left).
ok: [localhost]

TASK [Debug about_info] *******************************************************************************************************************
ok: [localhost] => {
    "about_info": {
        "about_info": {
            "api_type": "VirtualCenter",
            "api_version": "8.0.3.0",
            "build": "24322831",
            "instance_uuid": "092d2929-6694-433e-9761-3f609c24b5bc",
            "license_product_name": "VMware VirtualCenter Server",
            "license_product_version": "8.0",
            "locale_build": "000",
            "locale_version": "INTL",
            "os_type": "linux-x64",
            "product_full_name": "VMware vCenter Server 8.0.3 build-24322831",
            "product_line_id": "vpx",
            "product_name": "VMware vCenter Server",
            "vendor": "VMware, Inc.",
            "version": "8.0.3"
        },
        "attempts": 15,
        "changed": false,
        "failed": false
    }
}

PLAY RECAP ********************************************************************************************************************************
localhost                  : ok=6    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

タイトルとURLをコピーしました