Automation Assembler で vSphere に展開する場合は固定 IP アドレスを割り当てることができますが、cloudConfig 初期化コマンドとカスタマイズ仕様の間に競合が発生しないように注意する必要があります。
デザインのサンプル
次に示すデザインでは、クラウド テンプレートの初期化コマンドとカスタマイズ仕様の間に競合が発生しないように、固定 IP アドレスを安全に適用しています。すべてのサンプルに、assignment: static ネットワーク設定が含まれています。
| デザイン | クラウド テンプレート コードのサンプル |
|---|---|
| cloud-init コードのない Linux マシンに固定 IP アドレスを割り当てる場合 |
resources:
wpnet:
type: Cloud.Network
properties:
name: wpnet
networkType: public
constraints:
- tag: sqa
DBTier:
type: Cloud.vSphere.Machine
properties:
flavor: small
image: linux-template
networks:
- name: '${wpnet.name}'
assignment: static
network: '${resource.wpnet.id}'
|
| ネットワーク割り当てコマンドを含まない cloud-init コードを使用して Linux マシンに固定 IP アドレスを割り当てる場合。 注:vSphere カスタマイズ仕様は、customizeGuestOs プロパティを True に設定しても省略しても適用されます。 |
Ubuntu のサンプル resources:
wpnet:
type: Cloud.Network
properties:
name: wpnet
networkType: public
constraints:
- tag: sqa
DBTier:
type: Cloud.vSphere.Machine
properties:
flavor: small
image: ubuntu-template
customizeGuestOs: true
cloudConfig: |
#cloud-config
ssh_pwauth: yes
chpasswd:
list: |
root:Pa$$w0rd
expire: false
write_files:
- path: /tmpFile.txt
content: |
${resource.wpnet.dns}
runcmd:
- hostnamectl set-hostname --pretty ${self.resourceName}
- touch /etc/cloud/cloud-init.disabled
networks:
- name: '${wpnet.name}'
assignment: static
network: '${resource.wpnet.id}'
CentOS のサンプル resources:
wpnet:
type: Cloud.Network
properties:
name: wpnet
networkType: public
constraints:
- tag: sqa
DBTier:
type: Cloud.vSphere.Machine
properties:
flavor: small
image: centos-template
customizeGuestOs: true
cloudConfig: |
#cloud-config
write_files:
- path: /test.txt
content: |
deploying in power off.
then rebooting.
networks:
- name: '${wpnet.name}'
assignment: static
network: '${resource.wpnet.id}'
|
| ネットワーク割り当てコマンドを含む cloud-init コードを使用して Linux マシンに固定 IP アドレスを割り当てる場合。 customizeGuestOs プロパティは、False にする必要があります。 |
Ubuntu のサンプル resources:
wpnet:
type: Cloud.Network
properties:
name: wpnet
networkType: public
constraints:
- tag: sqa
DBTier:
type: Cloud.vSphere.Machine
properties:
flavor: small
image: ubuntu-template
customizeGuestOs: false
cloudConfig: |
#cloud-config
write_files:
- path: /etc/netplan/99-installer-config.yaml
content: |
network:
version: 2
renderer: networkd
ethernets:
ens160:
addresses:
- ${resource.DBTier.networks[0].address}/${resource.wpnet.prefixLength}
gateway4: ${resource.wpnet.gateway}
nameservers:
search: ${resource.wpnet.dnsSearchDomains}
addresses: ${resource.wpnet.dns}
runcmd:
- netplan apply
- hostnamectl set-hostname --pretty ${self.resourceName}
- touch /etc/cloud/cloud-init.disabled
networks:
- name: '${wpnet.name}'
assignment: static
network: '${resource.wpnet.id}'
CentOS のサンプル resources:
wpnet:
type: Cloud.Network
properties:
name: wpnet
networkType: public
constraints:
- tag: sqa
DBTier:
type: Cloud.vSphere.Machine
properties:
flavor: small
image: centos-template
customizeGuestOs: false
cloudConfig: |
#cloud-config
ssh_pwauth: yes
chpasswd:
list: |
root:VMware1!
expire: false
runcmd:
- nmcli con add type ethernet con-name 'custom ens192' ifname ens192 ip4 ${self.networks[0].address}/${resource.wpnet.prefixLength} gw4 ${resource.wpnet.gateway}
- nmcli con mod 'custom ens192' ipv4.dns "${join(resource.wpnet.dns,' ')}"
- nmcli con mod 'custom ens192' ipv4.dns-search "${join(resource.wpnet.dnsSearchDomains,',')}"
- nmcli con down 'System ens192' ; nmcli con up 'custom ens192'
- nmcli con del 'System ens192'
- hostnamectl set-hostname --static `dig -x ${self.networks[0].address} +short | cut -d "." -f 1`
- hostnamectl set-hostname --pretty ${self.resourceName}
- touch /etc/cloud/cloud-init.disabled
networks:
- name: '${wpnet.name}'
assignment: static
network: '${resource.wpnet.id}'
|
| 参照イメージを基に展開を行うときに、ネットワーク割り当てコマンドを含む cloud-init コードを使用して Linux マシンに固定 IP アドレスを割り当てる場合。 customizeGuestOs プロパティは、False にする必要があります。 また、カスタマイズをブロックする ovfProperties プロパティをクラウド テンプレートに含めることはできません。 |
resources:
wpnet:
type: Cloud.Network
properties:
name: wpnet
networkType: public
constraints:
- tag: sqa
DBTier:
type: Cloud.vSphere.Machine
properties:
flavor: small
imageRef: 'https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.ova'
customizeGuestOs: false
cloudConfig: |
#cloud-config
ssh_pwauth: yes
chpasswd:
list: |
root:Pa$$w0rd
ubuntu:Pa$$w0rd
expire: false
write_files:
- path: /etc/netplan/99-netcfg-vrac.yaml
content: |
network:
version: 2
renderer: networkd
ethernets:
ens192:
dhcp4: no
dhcp6: no
addresses:
- ${resource.DBTier.networks[0].address}/${resource.wpnet.prefixLength}
gateway4: ${resource.wpnet.gateway}
nameservers:
search: ${resource.wpnet.dnsSearchDomains}
addresses: ${resource.wpnet.dns}
runcmd:
- netplan apply
- hostnamectl set-hostname --pretty ${self.resourceName}
- touch /etc/cloud/cloud-init.disabled
networks:
- name: '${wpnet.name}'
assignment: static
network: '${resource.wpnet.id}'
|
Day 2 カスタマイズ
初期展開と同様に、Day 2 アクションにもネットワーク構成が含まれる場合があります。Day 2 アクション中にカスタマイズをスキップするには、次のプロパティを追加します。
customizeGuestOsDay2: false
機能しない、または望ましくない結果が発生する可能性があるデザイン
- cloud-init コードにネットワーク割り当てコマンドが含まれておらず、customizeGuestOs プロパティが False である。
ネットワーク設定を構成するための初期化コマンドもカスタマイズ仕様もない。
- cloud-init コードにネットワーク割り当てコマンドが含まれておらず、ovfProperties プロパティが設定されている。
初期化コマンドはなく、ovfProperties がカスタマイズ仕様をブロックした。
- cloud-init コードにネットワーク割り当てコマンドが含まれており、customizeGuestOs プロパティが見つからないか True に設定されている。
カスタマイズ仕様を適用すると初期化コマンドと競合する。
cloud-init およびカスタマイズ仕様に関するその他の回避策
vSphere に展開する際には、cloud-init とカスタマイズ仕様の競合を回避するようにイメージをカスタマイズすることもできます。詳細については、次の外部リポジトリを参照してください。