将静态 IP 地址分配给没有 cloud-init 代码的 Linux 计算机 |
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}'
|
将静态 IP 地址分配给具有 cloud-init 代码但代码不含网络分配命令的 Linux 计算机。 注意:无论是将 customizeGuestOs 自定义规范设置为 true 还是省略 customizeGuestOs 属性,都会应用 vSphere 自定义规范。 |
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}'
|
将静态 IP 地址分配给具有 cloud-init 代码同时代码包含网络分配命令的 Linux 计算机。 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}'
|
基于引用映像部署时,将静态 IP 地址分配给具有 cloud-init 代码同时代码包含网络分配命令的 Linux 计算机。 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}'
|