Git Product home page Git Product logo

cloud-init-vmware-guestinfo's Introduction

Cloud-Init Datasource for VMware GuestInfo

This project provides a cloud-init datasource for pulling meta, user, and vendor data from VMware vSphere's GuestInfo interface.


❗❗ This repository is deprecated ❗❗

This datasource has been merged into cloud-init as DataSourceVMware (canonical/cloud-init#953):

Component Source Tests
Datasource DataSourceVMware.py test_vmware.py
Identification ds-identify test_ds_identify.py
Documentation vmware.rst

Despite the name change, the new datasource is backwards compatible with all configurations for the datasource in this repository. Still, anyone with build scripts or tooling that packages DataSourceVMwareGuestInfo into images should stop once cloud-init 21.3 is released with DataSourceVMware. In order to participate in the growth of this datasource moving forward, please:

Once again, many thanks to the wonderful community that has grown around this datasource, and I look forward to seeing everyone in the new cloud-init forums!


Installation

There are multiple methods of installing the data source.

Installing on RHEL/CentOS 7

There is an RPM available for installing on RedHat/CentOS:

yum install https://github.com/vmware/cloud-init-vmware-guestinfo/releases/download/v1.1.0/cloud-init-vmware-guestinfo-1.1.0-1.el7.noarch.rpm

Installing on other Linux distributions

The VMware GuestInfo datasource can be installed on any Linux distribution where cloud-init is already present. To do so, simply execute the following:

curl -sSL https://raw.githubusercontent.com/vmware/cloud-init-vmware-guestinfo/master/install.sh | sh -

Configuration

The data source is configured by setting guestinfo properties on a VM's extraconfig data or a customizable vApp's properties data.

Property Description
guestinfo.metadata A YAML or JSON document containing the cloud-init metadata.
guestinfo.metadata.encoding The encoding type for guestinfo.metadata.
guestinfo.userdata A YAML document containing the cloud-init user data.
guestinfo.userdata.encoding The encoding type for guestinfo.userdata.
guestinfo.vendordata A YAML document containing the cloud-init vendor data.
guestinfo.vendordata.encoding The encoding type for guestinfo.vendordata.

All guestinfo.*.encoding property values may be set to base64 or gzip+base64.

Walkthrough

The following series of steps is a demonstration on how to configure a VM with cloud-init and the VMX GuestInfo datasource.

Create a metadata file

First, create the metadata file for the VM. Save the following YAML to a file named metadata.yaml:

instance-id: cloud-vm
local-hostname: cloud-vm
network:
  version: 2
  ethernets:
    nics:
      match:
        name: ens*
      dhcp4: yes

Create a userdata file

Finally, create the userdata file userdata.yaml:

#cloud-config

users:
  - default
  - name: akutz
    primary_group: akutz
    sudo: ALL=(ALL) NOPASSWD:ALL
    groups: sudo, wheel
    ssh_import_id: None
    lock_passwd: true
    ssh_authorized_keys:
    - ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQDE0c5FczvcGSh/tG4iw+Fhfi/O5/EvUM/96js65tly4++YTXK1d9jcznPS5ruDlbIZ30oveCBd3kT8LLVFwzh6hepYTf0YmCTpF4eDunyqmpCXDvVscQYRXyasEm5olGmVe05RrCJSeSShAeptv4ueIn40kZKOghinGWLDSZG4+FFfgrmcMCpx5YSCtX2gvnEYZJr0czt4rxOZuuP7PkJKgC/mt2PcPjooeX00vAj81jjU2f3XKrjjz2u2+KIt9eba+vOQ6HiC8c2IzRkUAJ5i1atLy8RIbejo23+0P4N2jjk17QySFOVHwPBDTYb0/0M/4ideeU74EN/CgVsvO6JrLsPBR4dojkV5qNbMNxIVv5cUwIy2ThlLgqpNCeFIDLCWNZEFKlEuNeSQ2mPtIO7ETxEL2Cz5y/7AIuildzYMc6wi2bofRC8HmQ7rMXRWdwLKWsR0L7SKjHblIwarxOGqLnUI+k2E71YoP7SZSlxaKi17pqkr0OMCF+kKqvcvHAQuwGqyumTEWOlH6TCx1dSPrW+pVCZSHSJtSTfDW2uzL6y8k10MT06+pVunSrWo5LHAXcS91htHV1M1UrH/tZKSpjYtjMb5+RonfhaFRNzvj7cCE1f3Kp8UVqAdcGBTtReoE8eRUT63qIxjw03a7VwAyB2w+9cu1R9/vAo8SBeRqw== [email protected]

Assigning the userdate data to the VM's GuestInfo

Please note that this step requires that the VM be powered off. All of the commands below use the VMware CLI tool, govc.

Go ahead and assign the path to the VM to the environment variable VM:

export VM="/inventory/path/to/the/vm"

Next, power off the VM:

govc vm.power -off "${VM}"

Export the environment variables that contain the cloud-init metadata and userdata:

export METADATA=$(gzip -c9 <metadata.yaml | { base64 -w0 2>/dev/null || base64; }) \
       USERDATA=$(gzip -c9 <userdata.yaml | { base64 -w0 2>/dev/null || base64; })

Assign the metadata and userdata to the VM's extra configuration dictionary, guestinfo:

govc vm.change -vm "${VM}" \
  -e guestinfo.metadata="${METADATA}" \
  -e guestinfo.metadata.encoding="gzip+base64" \
  -e guestinfo.userdata="${USERDATA}" \
  -e guestinfo.userdata.encoding="gzip+base64"

Please note the above commands include specifying the encoding for the properties. This is important as it informs the datasource how to decode the data for cloud-init. Valid values for metadata.encoding and userdata.encoding include:

  • base64
  • gzip+base64

Using the cloud-init VMX GuestInfo datasource

Power the VM back on.

govc vm.power -vm "${VM}" -on

If all went according to plan, the CentOS box is:

  • Locked down, allowing SSH access only for the user in the userdata
  • Configured for a dynamic IP address via DHCP
  • Has a hostname of cloud-vm

Examples

This section reviews common configurations:

Setting the hostname

The hostname is set by way of the metadata key local-hostname.

Setting the instance ID

The instance ID may be set by way of the metadata key instance-id. However, if this value is absent then then the instance ID is read from the file /sys/class/dmi/id/product_uuid.

Providing public SSH keys

The public SSH keys may be set by way of the metadata key public-keys-data. Each newline-terminated string will be interpreted as a separate SSH public key, which will be placed in distro's default user's ~/.ssh/authorized_keys. If the value is empty or absent, then nothing will be written to ~/.ssh/authorized_keys.

Configuring the network

The network is configured by setting the metadata key network with a value consistent with Network Config Versions 1 or 2, depending on the Linux distro's version of cloud-init.

The metadata key network.encoding may be used to indicate the format of the metadata key "network". Valid encodings are base64 and gzip+base64.

Cleaning up the guestinfo keys

Sometimes the cloud-init userdata might contain sensitive information, and it may be desirable to have the guestinfo.userdata key (or other guestinfo keys) cleared as soon as its data is read by the datasource. This is possible by adding the following to the metadata:

cleanup-guestinfo:
- userdata
- vendordata

When the above snippet is added to the metadata, the datasource will iterate over the elements in the cleanup-guestinfo array and clear each of the keys. For example, the above snippet will cause the following commands to be executed:

vmware-rpctool "info-set guestinfo.userdata ---"
vmware-rpctool "info-set guestinfo.userdata.encoding  "
vmware-rpctool "info-set guestinfo.vendordata ---"
vmware-rpctool "info-set guestinfo.vendordata.encoding  "

Please note that keys are set to the valid YAML string --- as it is not possible remove an existing key from the guestinfo key-space. A key's analogous encoding property will be set to a single white-space character, causing the datasource to treat the actual key value as plain-text, thereby loading it as an empty YAML doc (hence the aforementioned ---).

Reading the local IP addresses

This datasource automatically discovers the local IPv4 and IPv6 addresses for a guest operating system based on the default routes. However, when inspecting a VM externally, it's not possible to know what the default IP address is for the guest OS. That's why this datasource sets the discovered, local IPv4 and IPv6 addresses back in the guestinfo namespace as the following keys:

  • guestinfo.local-ipv4
  • guestinfo.local-ipv6

It is possible that a host may not have any default, local IP addresses. It's also possible the reported, local addresses are link-local addresses. But these two keys may be used to discover what this datasource determined were the local IPv4 and IPv6 addresses for a host.

Waiting on the network

Sometimes cloud-init may bring up the network, but it will not finish coming online before the datasource's setup function is called, resulting in an /var/run/cloud-init/instance-data.json file that does not have the correct network information. It is possible to instruct the datasource to wait until an IPv4 or IPv6 address is available before writing the instance data with the following metadata properties:

wait-on-network:
  ipv4: true
  ipv6: true

If either of the above values are true, then the datasource will sleep for a second, check the network status, and repeat until one or both addresses from the specified families are available.

Building the RPM

Building the RPM locally is handled via Docker. Simple execute the following command:

make rpm

The resulting RPMs are located in rpmbuild/$OS/RPMS/noarch/. The list of supported $OS platforms are:

  • el7 (RHEL/CentOS 7)

Conclusion

To learn more about how to use cloud-init with CentOS, please see the cloud-init documentation for more examples and reference information for the cloud-config files.

cloud-init-vmware-guestinfo's People

Contributors

akutz avatar b-a-t avatar hieunba avatar keerthanakalyan avatar promaethius avatar sidharthsurana avatar spawnia avatar sshedi avatar yvespp avatar zuzzas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cloud-init-vmware-guestinfo's Issues

vmware-rpctool info-get guestinfo.userdata returns no value but works for ovfEnv

Hello,
I have setup my virtual machines with vApp options properties such as guestinfo.userdata, to comply with what is asked in the Configuration section:

The data source is configured by setting guestinfo properties on a VM's extraconfig data or a customizable vApp's properties data.

The OVF environment transport is set to VMware Tools

when I do in the guest VM
vmtoolsd --cmd "info-get guestinfo.ovfEnv" or vmware-rpctool "info-get guestinfo.ovfEnv" I get data back and I see my properties in the form

<PropertySection><Property oe:key="guestinfo.userdata" oe:value="<base64\_value"/></PropertySection>

but when doing

vmtoolsd --cmd "info-get guestinfo.userdata" or vmware-rpctool "info-get guestinfo.userdata" I get No value found

What am I doing wrong?
vmtoolsd -v returns VMware Tools daemon, version 11.2.5.26209 (build-17337674) and i'm using Ubuntu 20.04.2

My problem seems to be related to the other issue #67

Looking for your guidance here. Would like not to have to put those properties in the VM's extraconfig

SUCCESS: found local data from DataSourceVMwareGuestInfo when no data is provided

We have installed VMwareGuestInfo and updated the datasource_list to allow more than the override provided. One issue is even if we don't provide any guestinfo data it still counts the datasource as success and doesn't move onto the others.

I would expect it to move onto the next datasource since each returned nothing. I know I can fix this by moving the VMwareGuestInfo to be checked last but that seems like just a workaround.

2020-02-10 15:27:57,631 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting guestinfo value for key metadata
2020-02-10 15:27:57,631 - util.py[DEBUG]: Running command ['/usr/bin/vmtoolsd', '--cmd', 'info-get guestinfo.metadata'] with allowed return codes [0] (shell=False, capture=True)
2020-02-10 15:27:57,664 - DataSourceVMwareGuestInfo.py[DEBUG]: No value found for key metadata
2020-02-10 15:27:57,665 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting guestinfo value for key userdata
2020-02-10 15:27:57,665 - util.py[DEBUG]: Running command ['/usr/bin/vmtoolsd', '--cmd', 'info-get guestinfo.userdata'] with allowed return codes [0] (shell=False, capture=True)
2020-02-10 15:27:57,677 - DataSourceVMwareGuestInfo.py[DEBUG]: No value found for key userdata
2020-02-10 15:27:57,677 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting guestinfo value for key vendordata
2020-02-10 15:27:57,677 - util.py[DEBUG]: Running command ['/usr/bin/vmtoolsd', '--cmd', 'info-get guestinfo.vendordata'] with allowed return codes [0] (shell=False, capture=True)
2020-02-10 15:27:57,687 - DataSourceVMwareGuestInfo.py[DEBUG]: No value found for key vendordata
2020-02-10 15:27:57,687 - handlers.py[DEBUG]: finish: init-local/search-VMwareGuestInfo: SUCCESS: found local data from DataSourceVMwareGuestInfo
2020-02-10 15:27:57,688 - stages.py[INFO]: Loaded datasource DataSourceVMwareGuestInfo - DataSourceVMwareGuestInfo

Terraform

This appears not to work with Terraform, I created an OVA with packer (installing the RPM) from the README, importing to a vcenter and marking it as a template. GOVC appears to use the Govmomi Toolbox and I am not clear that terraform does. Do I need to edit the OVF manifest, add in the deployment properties, update the sha sum and then push that? I guess the short version of this question is that does this only work with GOVC as written?

ImportError: cannot import name UnrewindableBodyError on RedHat 7.8

cat /etc/redhat-release
Red Hat Enterprise Linux Server release 7.8 (Maipo)

yum install https://github.com/vmware/cloud-init-vmware-guestinfo/releases/download/v1.1.0/cloud-init-vmware-guestinfo-1.1.0-1.el7.noarch.rpm

journalctl -u cloud-init-local
-- Logs begin at Mon 2020-11-30 08:46:03 MSK, end at Mon 2020-11-30 10:01:01 MSK. --
Nov 30 08:46:07 rhel-78-16g systemd[1]: Starting Initial cloud-init job (pre-networking)...
Nov 30 08:46:07 rhel-78-16g python2[773]: detected unhandled Python exception in '/usr/bin/cloud-init'
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: Traceback (most recent call last):
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/bin/cloud-init", line 9, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: load_entry_point('cloud-init==19.4', 'console_scripts', 'cloud-init')()
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: return get_distribution(dist).load_entry_point(group, name)
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: return ep.load()
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: entry = __import__(self.module_name, globals(),globals(), ['__name__'])
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/cloudinit/cmd/main.py", line 26, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from cloudinit import netinfo
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/cloudinit/netinfo.py", line 15, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from cloudinit.net.network_state import net_prefix_to_ipv4_mask
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/cloudinit/net/__init__.py", line 14, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from cloudinit.net.network_state import mask_to_net_prefix
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/cloudinit/net/network_state.py", line 16, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from cloudinit import util
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/cloudinit/util.py", line 48, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from cloudinit import url_helper
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/cloudinit/url_helper.py", line 14, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: import requests
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/requests/__init__.py", line 58, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from . import utils
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/requests/utils.py", line 32, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from .exceptions import InvalidURL
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/requests/exceptions.py", line 10, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from urllib3.exceptions import HTTPError as BaseHTTPError
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/urllib3/__init__.py", line 10, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from .connectionpool import (
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/urllib3/connectionpool.py", line 31, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from .connection import (
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/urllib3/connection.py", line 45, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from .util.ssl_ import (
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/urllib3/util/__init__.py", line 5, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from .request import SKIP_HEADER, SKIPPABLE_HEADERS, make_headers
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: File "/usr/lib/python2.7/site-packages/urllib3/util/request.py", line 5, in <module>
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: from ..exceptions import UnrewindableBodyError
Nov 30 08:46:08 rhel-78-16g cloud-init[773]: ImportError: cannot import name UnrewindableBodyError
Nov 30 08:46:08 rhel-78-16g systemd[1]: cloud-init-local.service: main process exited, code=exited, status=1/FAILURE
Nov 30 08:46:08 rhel-78-16g systemd[1]: Failed to start Initial cloud-init job (pre-networking).
Nov 30 08:46:08 rhel-78-16g systemd[1]: Unit cloud-init-local.service entered failed state.
Nov 30 08:46:08 rhel-78-16g systemd[1]: cloud-init-local.service failed.

CentOS 7 doesn't appear to be reading the GuestInfo Datasource

I've been working on building a CentOS 7 template that we can clone with terraform and use cloud-init scripts with. I'm seeing this error when we attempt to clone the template and pass cloud init data as metadata/userdata yamls:

2020-05-01 17:27:01,747 - util.py[WARNING]: Getting data from <class 'cloudinit.sources.DataSourceVMwareGuestInfo.DataSourceVMwareGuestInfo'> failed
2020-05-01 17:27:01,747 - util.py[DEBUG]: Getting data from <class 'cloudinit.sources.DataSourceVMwareGuestInfo.DataSourceVMwareGuestInfo'> failed
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cloudinit/sources/__init__.py", line 733, in find_source
    if s.update_metadata([EventType.BOOT_NEW_INSTANCE]):
  File "/usr/lib/python2.7/site-packages/cloudinit/sources/__init__.py", line 622, in update_metadata
    result = self.get_data()
  File "/usr/lib/python2.7/site-packages/cloudinit/sources/DataSourceVMwareGuestInfo.py", line 82, in get_data
    self.metadata = json.loads(metadata)
  File "/usr/lib64/python2.7/json/__init__.py", line 338, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 384, in raw_decode
    raise ValueError("No JSON object could be decoded")
ValueError: No JSON object could be decoded

Here's the relevant part of our Terraform config:

  clone {
    template_uuid = data.vsphere_virtual_machine.linux-vm-template.id
  }

  extra_config = {
      "guestinfo.metadata"          = base64gzip(file("${path.module}/templates/metadata.yaml"))
      "guestinfo.metadata.encoding" = "gzip+base64"
      "guestinfo.userdata"          = base64gzip(file("${path.module}/templates/userdata.yaml"))
      "guestinfo.userdata.encoding" = "gzip+base64"
  }
}

And finally, here's the packer packages we're installing into the template, along with the last step of the provisioner before it shuts down the vm and turns it into a vmware template:

%post
#sudo yum upgrade -y
chkconfig ntpd on
chkconfig sshd on
chkconfig ypbind on
chkconfig iptables off
chkconfig ip6tables off
chkconfig yum-updatesd off
chkconfig haldaemon off
chkconfig mcstrans off
chkconfig sysstat off
# Install vmware guest tools
echo "Installing VM Tools..."
# Install open-vm-tools, required to detect IP when building on ESXi
sudo yum -y install epel-release open-vm-tools perl python python3-pip openssh-server curl
sudo systemctl enable vmtoolsd
sudo systemctl start vmtoolsd
%end

and

  "provisioners": [

    {
      "type": "shell",
      "inline": [
        "sudo yum -y install https://github.com/vmware/cloud-init-vmware-guestinfo/releases/download/v1.1.0/cloud-init-vmware-guestinfo-1.1.0-1.el7.noarch.rpm"
      ]
    },

    {
      "type": "shell",
      "inline": [
        "sudo cloud-init clean"
      ]
    }

  ]
}

unexpected (and silent?) failure using newest cloud-init-vmware-guestinfo with cloud-init 20.2-x

Hey @akutz ,

I don't think this new version check is working the way you expect.

If the installed version of cloud-init is something like "20.2-45-g5f7825e2-0ubuntu1~18.04.1", you probably want to continue to use "util.subp" (rather than "util.subp.subp"), right?

Thanks.

PS: when I say the failure was "silent", I mean that terraform didn't think there was anything amiss when I subsequently tried to use "extra_config.guestinfo.userdata" on the vsphere image I had baked with current "master" of cloud-init-vmware-guestinfo and "20.2-45-g5f7825e2-0ubuntu1~18.04.1" of cloud-init ... although "ssh" certainly did think that something was amiss when it tried to connect 😜

DataSourceVMwareGuestInfo slow because of vmtoolsd hang

I'm trying to optimizing the boot times of a Ubuntu 18.04 Image with the DataSourceVMwareGuestInfo installed.
I notice that every other call to vmtoolsd hangs for about 2s and slows down the boot. If I add a sleep >= 50ms before vmtoolsd calls the hang goes away.
Is this something that is known about vmtoolsd, are calls to it somehow throttled? If yes, can we add a sleep into the DataSourceVMwareGuestInfo before the calls to speed up the data source?

Long version:

The slowest thing on the os currently is cloud-init:

root@create-test:/var/log# systemd-analyze blame
          5.419s cloud-init-local.service
          1.335s cloud-init.service
          1.206s cloud-config.service
           936ms docker.service
           803ms cloud-final.service

And the slowest thing in cloud-init is DataSourceVMwareGuestInfo. Here are 3 boot records showing only the init-local phase. DataSourceVMwareGuestInfo takes between 4 and 6 seconds.

cloud-init analyze show
-- Boot Record 01 --
The total time elapsed since completing an event is printed after the "@" character.
The time the event takes is printed after the "+" character.

Starting stage: init-local
|`->no cache found @00.00600s +00.00000s
|`->found local data from DataSourceVMwareGuestInfo @00.04000s +06.12200s
Finished stage: (init-local) 06.36500 seconds

-- Boot Record 02 --
The total time elapsed since completing an event is printed after the "@" character.
The time the event takes is printed after the "+" character.

Starting stage: init-local
|`->cache invalid in datasource: DataSourceVMwareGuestInfo @00.00400s +00.03000s
|`->found local data from DataSourceVMwareGuestInfo @00.03600s +04.09300s
Finished stage: (init-local) 04.19000 seconds

Starting stage: init-network

-- Boot Record 03 --
The total time elapsed since completing an event is printed after the "@" character.
The time the event takes is printed after the "+" character.

Starting stage: init-local
|`->cache invalid in datasource: DataSourceVMwareGuestInfo @00.00600s +00.04000s
|`->found local data from DataSourceVMwareGuestInfo @00.04900s +06.13300s
Finished stage: (init-local) 06.24700 seconds

In /var/log/cloud-init.log I can see that time gets lost in some calls to /usr/bin/vmtoolsd --cmd 'info-get guestinfo':

2019-10-06 07:39:50,377 - __init__.py[DEBUG]: Looking for data source in: ['VMwareGuestInfo', 'None'], via packages ['', 'cloudinit.sources'] that matches dependencies ['FILESYSTEM']
2019-10-06 07:39:50,427 - __init__.py[DEBUG]: Searching for local data source in: ['DataSourceVMwareGuestInfo']
2019-10-06 07:39:50,427 - handlers.py[DEBUG]: start: init-local/search-VMwareGuestInfo: searching for local data from DataSourceVMwareGuestInfo
2019-10-06 07:39:50,428 - __init__.py[DEBUG]: Seeing if we can get any data from <class 'cloudinit.sources.DataSourceVMwareGuestInfo.DataSourceVMwareGuestInfo'>
2019-10-06 07:39:50,428 - __init__.py[DEBUG]: Update datasource metadata and network config due to events: New instance first boot
2019-10-06 07:39:50,428 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting guestinfo value for key metadata
2019-10-06 07:39:50,428 - util.py[DEBUG]: Running command ['/usr/bin/vmtoolsd', '--cmd', 'info-get guestinfo.metadata'] with allowed return codes [0] (shell=False, capture=True)
2019-10-06 07:39:50,439 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting guestinfo value for key metadata.encoding
2019-10-06 07:39:50,439 - util.py[DEBUG]: Running command ['/usr/bin/vmtoolsd', '--cmd', 'info-get guestinfo.metadata.encoding'] with allowed return codes [0] (shell=False, capture=True)
2019-10-06 07:39:52,476 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting encoded data for key=guestinfo.metadata, enc=gzip+base64
2019-10-06 07:39:52,476 - DataSourceVMwareGuestInfo.py[DEBUG]: Decoding gzip+base64 format guestinfo.metadata
2019-10-06 07:39:52,478 - DataSourceVMwareGuestInfo.py[DEBUG]: loaded metadata {'instance-id': 'create-test.phoenix.mobicorp.test', 'network': 'H4sICP+ZmV0C/25ldHdvcmstY29uZmlnAGWOQQrDMAwE737F4mOhbqT4Uv9GJKLpIS5YJqW/b5xiKOQkaYcdtGmx5ysnsNO6aMlaLTlgP4Y2gVXqtPxWIMuqCZrtcgQyz0XN1Dq/gobAHChSIIo3jgd4SNW3fGKC/+PedaVp2fZHuuWkbeLWHMdA99ibp5z9F+7bmnDPAAAA', 'network.encoding': 'gzip+base64'}
2019-10-06 07:39:52,478 - DataSourceVMwareGuestInfo.py[DEBUG]: network data found
2019-10-06 07:39:52,478 - DataSourceVMwareGuestInfo.py[DEBUG]: network data to be decoded H4sICP+ZmV0C/25ldHdvcmstY29uZmlnAGWOQQrDMAwE737F4mOhbqT4Uv9GJKLpIS5YJqW/b5xiKOQkaYcdtGmx5ysnsNO6aMlaLTlgP4Y2gVXqtPxWIMuqCZrtcgQyz0XN1Dq/gobAHChSIIo3jgd4SNW3fGKC/+PedaVp2fZHuuWkbeLWHMdA99ibp5z9F+7bmnDPAAAA
2019-10-06 07:39:52,478 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting encoded data for key=metadata.network, enc=gzip+base64
2019-10-06 07:39:52,478 - DataSourceVMwareGuestInfo.py[DEBUG]: Decoding gzip+base64 format metadata.network
2019-10-06 07:39:52,480 - DataSourceVMwareGuestInfo.py[DEBUG]: network data {'config': {'version': 2, 'ethernets': {'eth0': {'match': {'name': 'ens*'}, 'addresses': ['10.22.141.114/24'], 'gateway4': '10.22.141.1', 'nameservers': {'addresses': ['10.33.194.1', '10.33.194.2']}}}}}
2019-10-06 07:39:52,480 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting guestinfo value for key userdata
2019-10-06 07:39:52,480 - util.py[DEBUG]: Running command ['/usr/bin/vmtoolsd', '--cmd', 'info-get guestinfo.userdata'] with allowed return codes [0] (shell=False, capture=True)
2019-10-06 07:39:52,488 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting guestinfo value for key userdata.encoding
2019-10-06 07:39:52,488 - util.py[DEBUG]: Running command ['/usr/bin/vmtoolsd', '--cmd', 'info-get guestinfo.userdata.encoding'] with allowed return codes [0] (shell=False, capture=True)
2019-10-06 07:39:54,520 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting encoded data for key=guestinfo.userdata, enc=gzip+base64
2019-10-06 07:39:54,521 - DataSourceVMwareGuestInfo.py[DEBUG]: Decoding gzip+base64 format guestinfo.userdata
2019-10-06 07:39:54,523 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting guestinfo value for key vendordata
2019-10-06 07:39:54,523 - util.py[DEBUG]: Running command ['/usr/bin/vmtoolsd', '--cmd', 'info-get guestinfo.vendordata'] with allowed return codes [0] (shell=False, capture=True)
2019-10-06 07:39:54,532 - DataSourceVMwareGuestInfo.py[DEBUG]: No value found for key vendordata
2019-10-06 07:39:54,533 - handlers.py[DEBUG]: finish: init-local/search-VMwareGuestInfo: SUCCESS: found local data from DataSourceVMwareGuestInfo
2019-10-06 07:39:54,533 - stages.py[INFO]: Loaded datasource DataSourceVMwareGuestInfo - DataSourceVMwareGuestInfo

I then played with vmtoolsd and I can get it to hang on every other call for about two seconds if I call it in a loop:

root@create-test:/var/log# while true; do
>   time /usr/bin/vmtoolsd --cmd 'info-get guestinfo.vendordata'
> done
No value found

real    0m0.009s
user    0m0.008s
sys     0m0.000s
No value found

real    0m2.019s
user    0m0.000s
sys     0m0.008s
No value found

real    0m0.008s
user    0m0.008s
sys     0m0.000s
No value found

real    0m2.040s
user    0m0.004s
sys     0m0.004s
No value found

real    0m0.012s
user    0m0.006s
sys     0m0.006s
No value found

real    0m0.012s
user    0m0.011s
sys     0m0.000s
No value found

If I add a sleep > 50 ms in the loop the command doesn't hang:

root@create-test:/var/log# while true; do
>   time /usr/bin/vmtoolsd --cmd 'info-get guestinfo.vendordata'
>   sleep 0.05
> done
No value found

real    0m0.010s
user    0m0.000s
sys     0m0.009s
No value found

real    0m0.009s
user    0m0.004s
sys     0m0.005s
No value found

real    0m0.012s
user    0m0.005s
sys     0m0.006s
No value found

real    0m0.008s
user    0m0.000s
sys     0m0.008s
No value found

real    0m0.008s
user    0m0.007s
sys     0m0.001s
No value found

real    0m0.008s
user    0m0.007s
sys     0m0.000s
No value found

real    0m0.009s
user    0m0.008s
sys     0m0.001s
No value found

I added the time.sleep(0.05) into the data source here: https://github.com/vmware/cloud-init-vmware-guestinfo/blob/master/DataSourceVMwareGuestInfo.py#L220
and now boots are faster:

cloud-init analyze show
-- Boot Record 04 --
The total time elapsed since completing an event is printed after the "@" character.
The time the event takes is printed after the "+" character.

Starting stage: init-local
|`->cache invalid in datasource: DataSourceVMwareGuestInfo @00.00700s +00.05600s
|`->found local data from DataSourceVMwareGuestInfo @00.06600s +00.30500s
Finished stage: (init-local) 00.45400 seconds

product_uuid format change in Linux v4.17 leads to surprises

If the kernel package (linux-image on Ubuntu) is updated from <4.17 to >=4.17 kernel, the product_uuid sysfs file will change, and this will restart the whole init and local-init stages, will change SSH id keys, and a whole lot of other unpleasantries.

The fix is simple: #19.

getfqdn overrides user provided hostname

The data source here always overrides the metadata's hostname and local-hostname fields using the socket.getfqdn(). Refer to the following lines:

Because of the above-mentioned, the user cannot set the hostname using metadata. The value of getfqdn is always set as the hostname.

This is creating a problem in projects like CAPV where CAPV expects to set the hostname but is unable to.

Enabling Customization through Datasource, Affects Terraform customization functionality

By enabling Datasource provider for cloud-init , Other customizations that are rendered through other provider utilities like using terraform fails since enabling the cloud-init data source provider enables all customization to be handled by cloud-init itself
There are some uses cases like remodifying filesystems and other operations which don't fit into post-processing stage of kickstart as process of moving towards the templates is done using cloud-init

Not sure if its an intended design since there is less documentation on the data source provider

CentOS7 Setting static IP address

This is my metadata file (its in json because for whatever reason the cloud-init process had an issue reading it as YAML).

metadata.json:

{
  "instance-id": "cloud-vm",
  "local-hostname": "cloud-vm",
  "network":{
    "version": 2,
    "ethernets":{
      "eth0":{
        "dhcp4": "no",
        "addresses": ["192.168.14.2/24"]
      }
    }
  }
}

Using this metadata file, the hostname is set but the IP is not, it has no address and is still DHCP.

I wasn't able to find any errors in /var/log/cloud-init.log that would indicate why this wasnt set.

Any idea why this would be happening?

KeyError when no ipv6 address

advertise_local_ip_addrs throws this error on our vms:

2019-12-11 11:47:07,544 - util.py[DEBUG]: failed stage init
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 653, in status_wrapper
    ret = functor(name, args)
  File "/usr/lib/python3/dist-packages/cloudinit/cmd/main.py", line 375, in main_init
    init.setup_datasource()
  File "/usr/lib/python3/dist-packages/cloudinit/stages.py", line 374, in setup_datasource
    self.datasource.setup(is_new_instance=self.is_new_instance())
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMwareGuestInfo.py", line 151, in setup
    advertise_local_ip_addrs(host_info)
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMwareGuestInfo.py", line 280, in advertise_local_ip_addrs
    local_ipv6 = host_info[LOCAL_IPV6]
KeyError: 'local-ipv6'

We have disable ipv6 on this host.

I suspect this was introduce with #26
I think the code here https://github.com/vmware/cloud-init-vmware-guestinfo/pull/26/files#diff-887b9ab215181ea8c8772e608c0408fdR275 should check if host_info has the keys local-ipv4 and local-ipv6 before accessing them.

Questions

I try to understand some parts of code and i have some questions :

  • It seems CentOS 7 have cloud-init 18.5, could we update docs and code ?
  • Could we use cloudinit.util.which to find vmtoolsd ?
  • Could we remove deepmerge and use cloudinit.util.mergemanydict ?
  • Why do you need netiface for ? May be cloud init is sufficent ?
  • Are you open to pull-request for adding deb package support ?
  • Without external dependency, What do you think of adding this to cloud-init sources ?

I spent some time to understand it because i like this datasource (used with photonOS and RancherOS). I will like to use it for others OSs.

distutils dependency

As already mentioned as a side-info in issue #17 : some OS do not have distutils installed. It would be nice to a) make this more visible in README or better b) solve dependency in install script

Br,
Sebastian

DataSourceVMwareGuestInfo.py is not ran.

99-DataSourceVMWareGuestInfo.cfg is in place.
DataSourceVmWareGuestInfo is in the source/ directory for cloud-init.

I have confirmed my metadata and userdata are available in base64 encoding using the same commands that are in the dscheck_VMwareGuestInfo and decoded it.

I am assuming these at the only pieces I need to confirm are in place and available.

When cloud init runs it says it is looking for data sources

 Looking for data source in : ['VMwareGuestInfo'. 'None'], via packages ['', u'cloudinit.sources'] that matches dependencies ['FILESYSTEM']

Searching for local data source in : []

No local datasource found

....

 Looking for data source in : ['VMwareGuestInfo'. 'None'], via packages ['', u'cloudinit.sources'] that matches dependencies ['FILESYSTEM', 'NETWORK']

Searching for local data source in : [u'DataSourceNone']

SUCESS: found network data from DataSourceNone

but it never runs the python script to gather the guest info that is available. When looking at the init.py in the /source directory for cloud-init I see that it is suppose to look for DataSource + VMwareGuestInfo.

Not sure what to try next of how to fix issue. Thanks

After updating to the latest cloud-init, errors with cloudinit.util

Hi, I've created a new ubuntu 20.04 VM template with packer, it automatically installs cloud-init 20.3-2-g371b392c-0ubuntu1~20.04.1. This latest version is incompatible with this datasource.

2020-08-29 15:05:34,869 - handlers.py[DEBUG]: finish: init-network/check-cache: SUCCESS: no cache found
2020-08-29 15:05:34,869 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/instance
2020-08-29 15:05:34,870 - stages.py[DEBUG]: Using distro class <class 'cloudinit.distros.ubuntu.Distro'>
2020-08-29 15:05:34,871 - __init__.py[DEBUG]: Looking for data source in: ['VMwareGuestInfo', 'None'], via packages ['', 'cloudinit.sources'] that matches dependencies ['FILESYSTEM', 'NETWORK']
2020-08-29 15:05:34,874 - __init__.py[DEBUG]: Searching for network data source in: ['DataSourceVMwareGuestInfo', 'DataSourceNone']
2020-08-29 15:05:34,874 - handlers.py[DEBUG]: start: init-network/search-VMwareGuestInfo: searching for network data from DataSourceVMwareGuestInfo
2020-08-29 15:05:34,874 - __init__.py[DEBUG]: Seeing if we can get any data from <class 'cloudinit.sources.DataSourceVMwareGuestInfo.DataSourceVMwareGuestInfo'>
2020-08-29 15:05:34,874 - __init__.py[DEBUG]: Update datasource metadata and network config due to events: New instance first boot
2020-08-29 15:05:34,874 - DataSourceVMwareGuestInfo.py[DEBUG]: Getting guestinfo value for key metadata
2020-08-29 15:05:34,874 - handlers.py[DEBUG]: finish: init-network/search-VMwareGuestInfo: FAIL: no network data found from DataSourceVMwareGuestInfo
2020-08-29 15:05:34,874 - util.py[WARNING]: Getting data from <class 'cloudinit.sources.DataSourceVMwareGuestInfo.DataSourceVMwareGuestInfo'> failed
2020-08-29 15:05:34,874 - util.py[DEBUG]: Getting data from <class 'cloudinit.sources.DataSourceVMwareGuestInfo.DataSourceVMwareGuestInfo'> failed
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMwareGuestInfo.py", line 319, in get_guestinfo_value
    (stdout, stderr) = util.subp(
TypeError: 'module' object is not callable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 770, in find_source
    if s.update_metadata([EventType.BOOT_NEW_INSTANCE]):
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 659, in update_metadata
    result = self.get_data()
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMwareGuestInfo.py", line 125, in get_data
    self.metadata = load_metadata()
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMwareGuestInfo.py", line 425, in load_metadata
    data = load(guestinfo('metadata'))
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMwareGuestInfo.py", line 399, in guestinfo
    data = get_guestinfo_value(key)
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMwareGuestInfo.py", line 327, in get_guestinfo_value
    except util.ProcessExecutionError as error:
AttributeError: module 'cloudinit.util' has no attribute 'ProcessExecutionError'

Thanks!

cleanup-guestinfo key not optional

With #25 it's now required that cleanup-guestinfo is set in the metadata, if it's not set this error is thrown and the datasource fails:

2019-12-11 10:18:15,420 - util.py[DEBUG]: Getting data from <class 'cloudinit.sources.DataSourceVMwareGuestInfo.DataSourceVMwareGuestInfo'> failed
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 760, in find_source
    if s.update_metadata([EventType.BOOT_NEW_INSTANCE]):
  File "/usr/lib/python3/dist-packages/cloudinit/sources/__init__.py", line 649, in update_metadata
    result = self.get_data()
  File "/usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMwareGuestInfo.py", line 128, in get_data
    clear_guestinfo_keys(self.metadata['cleanup-guestinfo'])
KeyError: 'cleanup-guestinfo'

As a workaround it can be set to empty:

cleanup-guestinfo: []

cleanup-guestinfo should be optional.

How change hostname in CentOS/RedHat in VmWare vcloud?

Hello! Thanks cloud-init-vmware-guestinfo!

How change hostname in CentOS/RedHat in VmWare vcloud?

Terraform code:

Terraform

resource "vcd_vapp_vm" "apatsev-env" {
  vapp_name     = vcd_vapp.apatsev.name
  name          = "rhel-78"
  catalog_name  = "xxxxxxxxx"
  template_name = "rhel-78"
  memory        = 8192
  cpus          = 4
  cpu_cores     = 2

  network {
    type               = "org"
    name               = vcd_vapp_org_network.vapp-network.org_network_name
    ip                 = "192.168.22.2"
    ip_allocation_mode = "MANUAL"

  }

  guest_properties = {
      "guestinfo.hostname" = "apatsev-test-vm"
  }

  customization {
    enabled                    = true
    allow_local_admin_password = true
    admin_password             = "xxxxxxxx"
    auto_generate_password     = false
    initscript = <<-EOT
    systemctl disable firewalld
    systemctl stop firewalld
    setenforce 0
    EOT
  }

  depends_on = [vcd_vapp.apatsev]

}
yum install cloud-init
Failed to set locale, defaulting to C
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager

This system is not registered with an entitlement server. You can use subscription-manager to register.

Package cloud-init-19.4-7.el7.centos.2.x86_64 already installed and latest version
Nothing to do

I installed cloud-init-vmware-guestinfo inside template_name.
But i not installed cloud-init inside template_name.
Hostname not changed.

Log
https://gist.github.com/patsevanton/226ec818beb76e6e89e56f2a4395a512

multiple datasources

Hi,

is it possible to run multiple datasources ?

for example:

00-xxx with datasource_list: [ "DataSourceOVF" ] which would do 1st config
99-xxx file datasource_list : [ "VmwareGuestInfo" ] which would do another config

Regards

example metadata

Just a heads up to this command

$(sed 's~NETWORK_CONFIG~'"$(gzip -c9 <network.config.yaml | \ base64)"'~' <metadata.json | gzip -9 | base64)

it was causing me issues and took me a while to figure it out. base64 needs a flag -w0 or else it might error out for some people.

VMware vCloudDirector

Please correct me if I am wrong and this is not meant to work with vCloudDirector. I see that all examples are based on vSphere.

Expected Behavior

The data source pulls userdata/metadata from guest properties of a VM in vcd and is selected by cloud-init.

Actual Behavior

The data source is recognized by cloud-init, but data is not pulled from guest properties. Cloud-init proceeds using default configuration files (data source none).

Steps to Reproduce

The following setup:

  • vCloud Director version: 10.0.0.15449638
  • Ubuntu Live Server 20.04.1
    • Custom .ova template prepared with Packer
    • open-vm-tools package is installed
    • vmware-guestinfo is installed using install.sh script

The steps:

  1. Provision a vApp with 1 VM in vcd using Terraform v0.13.2
  2. Supply userdata/metadata to VM, tried:
  guest_properties = {
    "metadata" = base64encode("# empty")
    "metadata.encoding" = "base64"
    "userdata" = base64encode(data.template_file.ubuntu-userdata.rendered)
    "userdata.encoding" = "base64"
  }

or:

  guest_properties = {
    "guestinfo.metadata" = base64encode("# empty")
    "guestinfo.metadata.encoding" = "base64"
    "guestinfo.userdata" = base64encode(data.template_file.ubuntu-userdata.rendered)
    "guestinfo.userdata.encoding" = "base64"
  }

Example userdata file:

#cloud-config
network:
  version: 2
  ethernets:
    id0:
      match:
        name: ens*
      dhcp4: false
      addresses:
        - ${address}
      gateway4: ${gateway}
      nameservers:
        addresses:
          - ${dns}
instance-id: ${computername}
local-hostname: ${computername}
users:
  - default
  - name: ${username}
    groups: users, admin
    lock_passwd: false
    passwd: ${passwd}
    sudo: ['ALL=(ALL) NOPASSWD:ALL']
    shell: /bin/bash
  1. After creation, login to VM through VM Remote Console, check /var/log/cloud-init.log
  2. See that, although the vmware-guestinfo data source is recognized, cloud-init proceeds with data source none:

image

Support EL6

EL6 comes with python 2.6 and from what I can tell python 2.7 is a prereq for this datasource which means EL6 is currently not supported.

Are their plans to support CentOS/RHEL 6?

works only about 1/10 times.

When im testing this out, it works flawless about 1/10th of the time.
other times it either partially works, eg.

  • configures the username but it seems the networking hasnt been setup yet. after a cloud-init clean && cloud-init init this usually works.
  • doesnt even fetch the metadata+userdata

vcenter version: 6.7
Compatibility: ESXi 6.7 and later (VM version 14)
Hypervisor: VMware ESXi, 6.7.0, 14320388
open-vm-tools 2:11.0.1-2ubuntu0.18.04.2
cloud-init 19.4-33-gbb4131a2-0ubuntu1~18.04.1
ubuntu bionic 18.04.4

extra_config = {
"guestinfo.userdata": base64encode(file("userdata.yaml")),
"guestinfo.userdata.encoding": "base64",
"guestinfo.metadata.encoding": "base64",
"guestinfo.metadata": base64encode(file("metadata.yaml"))
}

instance-id: test0123
local-hostname: test123
network:
  version: 2
  ethernets:
    ens160:
      nameservers:
        addresses: [8.8.8.8]
      match:
        name: ens160
      set-name: ens160
      dhcp4: no
      addresses: [ 10.1.25.171/24 ]
      gateway4: 10.1.25.1
#cloud-config
manage_etc_hosts: true
package_update: true
package_upgrade: true
package_reboot_if_required: true
timezone: Europe/Stockholm
users:
- name: ubuntu 
  plain_text_passwd: 'Password'
  home: /home/ubuntu
  shell: /bin/bash
  gecos: Ubuntu
  lock_passwd: false
  groups: [adm, sudo] 
  sudo: ALL=(ALL) NOPASSWD:ALL
output: {all: '| tee -a /var/log/cloud-init-output.log'}

Doesn't seem to execute on Ubuntu 18.04

Hi,

Sorry if this is the wrong place for support!

cloud-init 18.5-45-g3554ffe8-0ubuntu1~18.04.1

I followed the install instructions. I suspected the DataSource wasn't being run, so I edited /usr/lib/python3/dist-packages/cloudinit/sources/DataSourceVMwareGuestInfo.py to raise an exception in __init__. Then I ran

sudo rm -rf /var/lib/cloud/instances/ /var/lib/cloud/data/upgraded-network && sudo cloud-init -d init

I get no errors - beginning of the log is at https://gist.github.com/andrewpwade/c4bdad2cce4dd9d35486dbbeadc2d44c

There are only two config files in /etc/cloud/cloud.cfg.d/ : the one the installer created with datasource_list: [ "VMwareGuestInfo" ] and the logging config.

version 1.2.0 got function error when cloudinit is trying to get metadata and userdata

Hi ,

OS: RHEL 7.4
Cloud-init: 18.5 /19.4 (both version are tested, but not working)

after upgrade version 1.2.0, the cloudinit is stopping working, the error log from /var/log/cloud-init.log

2020-01-13 03:29:00,673 - util.py[DEBUG]: Cloud-init v. 18.5-71.el7 running 'init-local' at Mon, 13 Jan 2020 03:29:00 +0000. Up 13.83 seconds.
2020-01-13 03:29:00,673 - main.py[DEBUG]: No kernel command line url found.
2020-01-13 03:29:00,673 - main.py[DEBUG]: Closing stdin.
2020-01-13 03:29:00,688 - util.py[DEBUG]: Writing to /var/log/cloud-init.log - ab: [644] 0 bytes
2020-01-13 03:29:00,689 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/instance/boot-finished
2020-01-13 03:29:00,689 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/data/no-net
2020-01-13 03:29:00,689 - handlers.py[DEBUG]: start: init-local/check-cache: attempting to read from cache [check]
2020-01-13 03:29:00,689 - util.py[DEBUG]: Reading from /var/lib/cloud/instance/obj.pkl (quiet=False)
2020-01-13 03:29:00,689 - stages.py[DEBUG]: no cache found
2020-01-13 03:29:00,690 - handlers.py[DEBUG]: finish: init-local/check-cache: SUCCESS: no cache found
2020-01-13 03:29:00,690 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/instance
2020-01-13 03:29:00,715 - stages.py[DEBUG]: Using distro class <class 'cloudinit.distros.rhel.Distro'>
2020-01-13 03:29:00,715 - __init__.py[DEBUG]: Looking for data source in: ['VMwareGuestInfo'], via packages ['', u'cloudinit.sources'] that matches dependencies ['FILESYSTEM']
2020-01-13 03:29:00,757 - __init__.py[DEBUG]: Searching for local data source in: []
2020-01-13 03:29:00,757 - main.py[DEBUG]: No local datasource found
2020-01-13 03:29:00,758 - util.py[DEBUG]: Reading from /sys/class/net/ens192/name_assign_type (quiet=False)
2020-01-13 03:29:00,758 - __init__.py[DEBUG]: Found unstable nic names: ['ens192']; calling udevadm settle
2020-01-13 03:29:00,759 - util.py[DEBUG]: Running command ['udevadm', 'settle'] with allowed return codes [0] (shell=False, capture=True)
2020-01-13 03:29:00,764 - util.py[DEBUG]: Waiting for udev events to settle took 0.006 seconds
2020-01-13 03:29:00,765 - util.py[DEBUG]: Reading from /sys/class/net/ens192/carrier (quiet=False)
2020-01-13 03:29:00,765 - util.py[DEBUG]: Reading from /sys/class/net/ens192/dormant (quiet=False)
2020-01-13 03:29:00,765 - util.py[DEBUG]: Reading from /sys/class/net/ens192/operstate (quiet=False)
2020-01-13 03:29:00,765 - util.py[DEBUG]: Read 5 bytes from /sys/class/net/ens192/operstate
2020-01-13 03:29:00,766 - util.py[DEBUG]: Reading from /sys/class/net/ens192/address (quiet=False)
2020-01-13 03:29:00,766 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/ens192/address
2020-01-13 03:29:00,766 - util.py[DEBUG]: Reading from /sys/class/net/ens192/address (quiet=False)
2020-01-13 03:29:00,766 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/ens192/address
2020-01-13 03:29:00,766 - stages.py[DEBUG]: applying net config names for {'version': 1, 'config': [{'subnets': [{'type': 'dhcp'}], 'type': 'physical', 'name': 'ens192', 'mac_address': '00:50:56:ad:60:c8'}]}
2020-01-13 03:29:00,766 - util.py[DEBUG]: Reading from /sys/class/net/ens192/device/device (quiet=False)
2020-01-13 03:29:00,766 - util.py[DEBUG]: Read 7 bytes from /sys/class/net/ens192/device/device
2020-01-13 03:29:00,766 - util.py[DEBUG]: Reading from /sys/class/net/ens192/addr_assign_type (quiet=False)
2020-01-13 03:29:00,767 - util.py[DEBUG]: Read 2 bytes from /sys/class/net/ens192/addr_assign_type
2020-01-13 03:29:00,767 - util.py[DEBUG]: Reading from /sys/class/net/ens192/uevent (quiet=False)
2020-01-13 03:29:00,767 - util.py[DEBUG]: Read 27 bytes from /sys/class/net/ens192/uevent
2020-01-13 03:29:00,767 - util.py[DEBUG]: Reading from /sys/class/net/ens192/address (quiet=False)
2020-01-13 03:29:00,767 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/ens192/address
2020-01-13 03:29:00,767 - util.py[DEBUG]: Reading from /sys/class/net/ens192/device/device (quiet=False)
2020-01-13 03:29:00,767 - util.py[DEBUG]: Read 7 bytes from /sys/class/net/ens192/device/device
2020-01-13 03:29:00,767 - util.py[DEBUG]: Reading from /sys/class/net/lo/addr_assign_type (quiet=False)
2020-01-13 03:29:00,767 - util.py[DEBUG]: Read 2 bytes from /sys/class/net/lo/addr_assign_type
2020-01-13 03:29:00,768 - util.py[DEBUG]: Reading from /sys/class/net/lo/uevent (quiet=False)
2020-01-13 03:29:00,768 - util.py[DEBUG]: Read 23 bytes from /sys/class/net/lo/uevent
2020-01-13 03:29:00,768 - util.py[DEBUG]: Reading from /sys/class/net/lo/address (quiet=False)
2020-01-13 03:29:00,768 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/lo/address
2020-01-13 03:29:00,768 - util.py[DEBUG]: Reading from /sys/class/net/lo/device/device (quiet=False)
2020-01-13 03:29:00,768 - util.py[DEBUG]: Reading from /sys/class/net/ens192/operstate (quiet=False)
2020-01-13 03:29:00,768 - util.py[DEBUG]: Read 5 bytes from /sys/class/net/ens192/operstate
2020-01-13 03:29:00,768 - util.py[DEBUG]: Reading from /sys/class/net/lo/operstate (quiet=False)
2020-01-13 03:29:00,769 - util.py[DEBUG]: Read 8 bytes from /sys/class/net/lo/operstate
2020-01-13 03:29:00,769 - util.py[DEBUG]: Running command ['ip', '-6', 'addr', 'show', 'permanent', 'scope', 'global'] with allowed return codes [0] (shell=False, capture=True)
2020-01-13 03:29:00,793 - util.py[DEBUG]: Running command ['ip', '-4', 'addr', 'show'] with allowed return codes [0] (shell=False, capture=True)
2020-01-13 03:29:00,800 - __init__.py[DEBUG]: no work necessary for renaming of [['00:50:56:ad:60:c8', 'ens192', 'vmxnet3', '0x07b0']]
2020-01-13 03:29:00,801 - stages.py[INFO]: Applying network configuration from fallback bringup=False: {'version': 1, 'config': [{'subnets': [{'type': 'dhcp'}], 'type': 'physical', 'name': 'ens192', 'mac_address': '00:50:56:ad:60:c8'}]}
2020-01-13 03:29:00,804 - util.py[DEBUG]: Reading from /etc/os-release (quiet=False)
2020-01-13 03:29:00,804 - util.py[DEBUG]: Read 532 bytes from /etc/os-release
2020-01-13 03:29:00,807 - __init__.py[DEBUG]: Selected renderer 'sysconfig' from priority list: None
2020-01-13 03:29:00,812 - util.py[DEBUG]: Writing to /etc/sysconfig/network-scripts/ifcfg-ens192 - wb: [644] 193 bytes
2020-01-13 03:29:00,814 - util.py[DEBUG]: Reading from /etc/resolv.conf (quiet=False)
2020-01-13 03:29:00,814 - util.py[DEBUG]: Read 95 bytes from /etc/resolv.conf
2020-01-13 03:29:00,814 - util.py[DEBUG]: Writing to /etc/resolv.conf - wb: [644] 95 bytes
2020-01-13 03:29:00,815 - util.py[DEBUG]: Writing to /etc/udev/rules.d/70-persistent-net.rules - wb: [644] 98 bytes
2020-01-13 03:29:00,820 - util.py[DEBUG]: Writing to /etc/sysconfig/network - wb: [644] 86 bytes
2020-01-13 03:29:00,820 - main.py[DEBUG]: [local] Exiting without datasource
2020-01-13 03:29:00,832 - util.py[DEBUG]: Reading from /proc/uptime (quiet=False)
2020-01-13 03:29:00,832 - util.py[DEBUG]: Read 12 bytes from /proc/uptime
2020-01-13 03:29:00,832 - util.py[DEBUG]: cloud-init mode 'init' took 0.323 seconds (0.32)
2020-01-13 03:29:00,832 - handlers.py[DEBUG]: finish: init-local: SUCCESS: searching for local datasources
2020-01-13 03:29:01,114 - util.py[DEBUG]: Cloud-init v. 18.5-71.el7 running 'init' at Mon, 13 Jan 2020 03:29:01 +0000. Up 14.28 seconds.
2020-01-13 03:29:01,114 - main.py[DEBUG]: No kernel command line url found.
2020-01-13 03:29:01,114 - main.py[DEBUG]: Closing stdin.
2020-01-13 03:29:01,115 - util.py[DEBUG]: Writing to /var/log/cloud-init.log - ab: [644] 0 bytes
2020-01-13 03:29:01,115 - util.py[DEBUG]: Running command ['ip', 'addr', 'show'] with allowed return codes [0] (shell=False, capture=True)
2020-01-13 03:29:01,121 - util.py[DEBUG]: Running command ['ip', '-o', 'route', 'list'] with allowed return codes [0] (shell=False, capture=True)
2020-01-13 03:29:01,124 - util.py[DEBUG]: Running command ['ip', '--oneline', '-6', 'route', 'list', 'table', 'all'] with allowed return codes [0, 1] (shell=False, capture=True)
2020-01-13 03:29:01,129 - main.py[DEBUG]: Checking to see if files that we need already exist from a previous run that would allow us to stop early.
2020-01-13 03:29:01,129 - main.py[DEBUG]: Execution continuing, no previous run detected that would allow us to stop early.
2020-01-13 03:29:01,129 - handlers.py[DEBUG]: start: init-network/check-cache: attempting to read from cache [trust]
2020-01-13 03:29:01,129 - util.py[DEBUG]: Reading from /var/lib/cloud/instance/obj.pkl (quiet=False)
2020-01-13 03:29:01,130 - stages.py[DEBUG]: no cache found
2020-01-13 03:29:01,130 - handlers.py[DEBUG]: finish: init-network/check-cache: SUCCESS: no cache found
2020-01-13 03:29:01,130 - util.py[DEBUG]: Attempting to remove /var/lib/cloud/instance
2020-01-13 03:29:01,132 - stages.py[DEBUG]: Using distro class <class 'cloudinit.distros.rhel.Distro'>
2020-01-13 03:29:01,132 - __init__.py[DEBUG]: Looking for data source in: ['VMwareGuestInfo'], via packages ['', u'cloudinit.sources'] that matches dependencies ['FILESYSTEM', 'NETWORK']
2020-01-13 03:29:01,133 - __init__.py[DEBUG]: Searching for network data source in: []
2020-01-13 03:29:01,133 - util.py[WARNING]: No instance datasource found! Likely bad things to come!
2020-01-13 03:29:01,133 - util.py[DEBUG]: No instance datasource found! Likely bad things to come!
Traceback (most recent call last):
  File "/usr/lib/python2.7/site-packages/cloudinit/cmd/main.py", line 323, in main_init
    init.fetch(existing=existing)
  File "/usr/lib/python2.7/site-packages/cloudinit/stages.py", line 351, in fetch
    return self._get_data_source(existing=existing)
  File "/usr/lib/python2.7/site-packages/cloudinit/stages.py", line 261, in _get_data_source
    pkg_list, self.reporter)
  File "/usr/lib/python2.7/site-packages/cloudinit/sources/__init__.py", line 741, in find_source
    raise DataSourceNotFoundException(msg)
DataSourceNotFoundException: Did not find any data source, searched classes: ()
2020-01-13 03:29:01,167 - util.py[DEBUG]: Reading from /sys/class/net/ens192/name_assign_type (quiet=False)
2020-01-13 03:29:01,167 - __init__.py[DEBUG]: Found unstable nic names: ['ens192']; calling udevadm settle
2020-01-13 03:29:01,168 - util.py[DEBUG]: Running command ['udevadm', 'settle'] with allowed return codes [0] (shell=False, capture=True)
2020-01-13 03:29:01,177 - util.py[DEBUG]: Waiting for udev events to settle took 0.009 seconds
2020-01-13 03:29:01,177 - util.py[DEBUG]: Reading from /sys/class/net/ens192/carrier (quiet=False)
2020-01-13 03:29:01,177 - util.py[DEBUG]: Reading from /sys/class/net/ens192/dormant (quiet=False)
2020-01-13 03:29:01,178 - util.py[DEBUG]: Reading from /sys/class/net/ens192/operstate (quiet=False)
2020-01-13 03:29:01,178 - util.py[DEBUG]: Read 5 bytes from /sys/class/net/ens192/operstate
2020-01-13 03:29:01,178 - util.py[DEBUG]: Reading from /sys/class/net/ens192/address (quiet=False)
2020-01-13 03:29:01,178 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/ens192/address
2020-01-13 03:29:01,178 - util.py[DEBUG]: Reading from /sys/class/net/ens192/address (quiet=False)
2020-01-13 03:29:01,178 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/ens192/address
2020-01-13 03:29:01,179 - stages.py[DEBUG]: applying net config names for {'version': 1, 'config': [{'subnets': [{'type': 'dhcp'}], 'type': 'physical', 'name': 'ens192', 'mac_address': '00:50:56:ad:60:c8'}]}
2020-01-13 03:29:01,179 - util.py[DEBUG]: Reading from /sys/class/net/ens192/device/device (quiet=False)
2020-01-13 03:29:01,179 - util.py[DEBUG]: Read 7 bytes from /sys/class/net/ens192/device/device
2020-01-13 03:29:01,179 - util.py[DEBUG]: Reading from /sys/class/net/ens192/addr_assign_type (quiet=False)
2020-01-13 03:29:01,179 - util.py[DEBUG]: Read 2 bytes from /sys/class/net/ens192/addr_assign_type
2020-01-13 03:29:01,179 - util.py[DEBUG]: Reading from /sys/class/net/ens192/uevent (quiet=False)
2020-01-13 03:29:01,179 - util.py[DEBUG]: Read 27 bytes from /sys/class/net/ens192/uevent
2020-01-13 03:29:01,180 - util.py[DEBUG]: Reading from /sys/class/net/ens192/address (quiet=False)
2020-01-13 03:29:01,180 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/ens192/address
2020-01-13 03:29:01,180 - util.py[DEBUG]: Reading from /sys/class/net/ens192/device/device (quiet=False)
2020-01-13 03:29:01,180 - util.py[DEBUG]: Read 7 bytes from /sys/class/net/ens192/device/device
2020-01-13 03:29:01,180 - util.py[DEBUG]: Reading from /sys/class/net/lo/addr_assign_type (quiet=False)
2020-01-13 03:29:01,180 - util.py[DEBUG]: Read 2 bytes from /sys/class/net/lo/addr_assign_type
2020-01-13 03:29:01,180 - util.py[DEBUG]: Reading from /sys/class/net/lo/uevent (quiet=False)
2020-01-13 03:29:01,180 - util.py[DEBUG]: Read 23 bytes from /sys/class/net/lo/uevent
2020-01-13 03:29:01,181 - util.py[DEBUG]: Reading from /sys/class/net/lo/address (quiet=False)
2020-01-13 03:29:01,181 - util.py[DEBUG]: Read 18 bytes from /sys/class/net/lo/address
2020-01-13 03:29:01,181 - util.py[DEBUG]: Reading from /sys/class/net/lo/device/device (quiet=False)
2020-01-13 03:29:01,181 - util.py[DEBUG]: Reading from /sys/class/net/ens192/operstate (quiet=False)
2020-01-13 03:29:01,181 - util.py[DEBUG]: Read 5 bytes from /sys/class/net/ens192/operstate
2020-01-13 03:29:01,181 - util.py[DEBUG]: Reading from /sys/class/net/lo/operstate (quiet=False)
2020-01-13 03:29:01,181 - util.py[DEBUG]: Read 8 bytes from /sys/class/net/lo/operstate
2020-01-13 03:29:01,182 - util.py[DEBUG]: Running command ['ip', '-6', 'addr', 'show', 'permanent', 'scope', 'global'] with allowed return codes [0] (shell=False, capture=True)
2020-01-13 03:29:01,186 - util.py[DEBUG]: Running command ['ip', '-4', 'addr', 'show'] with allowed return codes [0] (shell=False, capture=True)
2020-01-13 03:29:01,190 - __init__.py[DEBUG]: no work necessary for renaming of [['00:50:56:ad:60:c8', 'ens192', 'vmxnet3', '0x07b0']]
2020-01-13 03:29:01,190 - stages.py[INFO]: Applying network configuration from fallback bringup=True: {'version': 1, 'config': [{'subnets': [{'type': 'dhcp'}], 'type': 'physical', 'name': 'ens192', 'mac_address': '00:50:56:ad:60:c8'}]}
2020-01-13 03:29:01,191 - util.py[DEBUG]: Reading from /etc/os-release (quiet=False)
2020-01-13 03:29:01,191 - util.py[DEBUG]: Read 532 bytes from /etc/os-release
2020-01-13 03:29:01,192 - __init__.py[DEBUG]: Selected renderer 'sysconfig' from priority list: None
2020-01-13 03:29:01,198 - util.py[DEBUG]: Writing to /etc/sysconfig/network-scripts/ifcfg-ens192 - wb: [644] 193 bytes
2020-01-13 03:29:01,199 - util.py[DEBUG]: Reading from /etc/resolv.conf (quiet=False)
2020-01-13 03:29:01,199 - util.py[DEBUG]: Read 95 bytes from /etc/resolv.conf
2020-01-13 03:29:01,199 - util.py[DEBUG]: Writing to /etc/resolv.conf - wb: [644] 95 bytes
2020-01-13 03:29:01,200 - util.py[DEBUG]: Writing to /etc/udev/rules.d/70-persistent-net.rules - wb: [644] 98 bytes
2020-01-13 03:29:01,201 - util.py[DEBUG]: Writing to /etc/sysconfig/network - wb: [644] 86 bytes
2020-01-13 03:29:01,202 - main.py[DEBUG]: [net] Exiting without datasource
2020-01-13 03:29:01,203 - util.py[DEBUG]: Reading from /proc/uptime (quiet=False)
2020-01-13 03:29:01,203 - util.py[DEBUG]: Read 12 bytes from /proc/uptime
2020-01-13 03:29:01,203 - util.py[DEBUG]: cloud-init mode 'init' took 0.149 seconds (0.15)
2020-01-13 03:29:01,204 - handlers.py[DEBUG]: finish: init-network: SUCCESS: searching for network datasources

vmtoolsd --cmd "info-get guestinfo.metadata" | base64 -d | zcat - and vmtoolsd --cmd "info-get guestinfo.userdata" | base64 -d | zcat - can get correct metadata and userdata, but not applied to system.

and this is working on release 1.1.0.

keep getting No value for guestinfo

hello,

i'm trying to get ovf customization working on a RHEL 8.2 VM :
standard deployment (using template) customiztion using cloud-init is working.

but when i try to get this working through OVF deployment, it is not working, OVF properties are set :

  • guestinfo.userdata and guestinfo.userdata.encoding.

which is confirmed by doing :
vmwre-rpctool 'info get guestinfo.ovfEnv'

i see in property section :

but when i try :
vware-rpctool 'info get guestinfo.userdata' (or guestinfo.userdata.encoding) i always get No Value Found.

so no customization....

i don't understand why , could you help me ?
thanks

regards

Installation of DataSourceVMWareGuestInfo overwrites used datasources

The installation script currently sets the datasources via the 99-DataSourceVMwareGuestInfo.cfg

Therefore cloud-init only trys to detect the VMWareGuetInfo datasource and not all other default datasources. Not sure what the best solution would be:

  1. Don't configure the datasource list in the install.sh script (this then would have to been done afterwards by the user)
  2. Adjust the list of default datasources instead of configuring the datasource list via the cloud.cfg.d folder
  3. Add a file with a lower number to cloud.cfg.d which contains all default datasources + VMwareGuestInfo

P.S. for more context: kubernetes-sigs/image-builder#96

@akutz what do you think?

Installation fails on CentOS 7 due to IP address validation error using Python 2.7.5

Hello,

Installing the VMware Guest Info provider for cloud-init on CentOS 7 fails as a result of a failure to correctly validate an IP address. The problem is the following line for the is_valid_ip_addr method in the DataSourceVMwareGuestInfo.py file.

addr = ipaddress.ip_address(val.encode('utf-8'))

The value is not being correctly encoded as a unicode string, which is required by the ipaddress module.

I managed to resolve the issue by changing the line to the following:

addr = ipaddress.ip_address(unicode(val))

Terraform vsphere guestinfo.metadata issue

# terraform version
Terraform v0.12.24
+ provider.local v1.4.0
+ provider.template v2.1.2
+ provider.vsphere v1.17.0

# rpm -qa | egrep "open-vm-tools|cloud-init|guestinfo" | sort
cloud-init-18.5-6.el7.x86_64
cloud-init-vmware-guestinfo-1.1.0-1.el7.noarch
open-vm-tools-10.3.10-2.el7.x86_64

Configured cloud-init-vmware-guestinfo in /etc/cloud/cloud.cfg.d to read guestinfo datasource as follows:

# cat /etc/cloud/cloud.cfg.d/99-DataSourceVMwareGuestInfo.cfg 

# Cloud-Init Datasource for VMware Guestinfo
#
# Copyright (c) 2018 VMware, Inc. All Rights Reserved.
#
# This product is licensed to you under the Apache 2.0 license (the "License").
# You may not use this product except in compliance with the Apache 2.0 License.
#
# This product may include a number of subcomponents with separate copyright
# notices and license terms. Your use of these subcomponents is subject to the
# terms and conditions of the subcomponent's license, as noted in the LICENSE
# file.

datasource_list: [ "VMwareGuestInfo" ]

Here is extra_config block defined in Terraform resource "vsphere_virtual_machine" :

  extra_config = {
    "guestinfo.userdata"          = "${var.userdata}"
    "guestinfo.userdata.encoding" = "gzip+base64"
    "guestinfo.metadata"          = <<-EOT
{
  "local-hostname": "${var.name}-${count.index}.${var.cluster_domain}",
  "instance-id": "${var.name}-${count.index}.${var.cluster_domain}",
  "network": {
    "version": 2,
    "ethernets": {
      "eth0": {
        "dhcp4": false,
        "addresses": [
          "${var.ip_addresses[count.index]}/${var.netmask}"
        ],
        "gateway4": "${var.gateway}",
        "nameservers": {
          "search": [
            "${var.cluster_domain}"
          ],
          "addresses": [
            "${var.dns}"
          ]
        }
      }
    }
  }
}
EOT

Both guestinfo.metadata and guestinfo.userdata are read in fine:

# vmware-rpctool "info-get guestinfo.metadata"
{
  "local-hostname": "bastion-0.ddcocp311.tamlab.brq.redhat.com",
  "instance-id": "bastion-0.ddcocp311.tamlab.brq.redhat.com",
  "network": {
    "version": 2,
    "ethernets": {
      "eth0": {
        "dhcp4": false,
        "addresses": [
          "10.37.198.140/25"
        ],
        "gateway4": "10.37.198.254",
        "nameservers": {
          "search": [
            "ddcocp311.tamlab.brq.redhat.com"
          ],
          "addresses": [
            "10.37.197.1"
          ]
        }
      }
    }
  }
}

Userdata consists of a multi-part (cloud-config + bash shell script).

# vmware-rpctool "info-get guestinfo.userdata" | base64 -d | gunzip
Content-Type: multipart/mixed; boundary="MIMEBOUNDARY"
MIME-Version: 1.0

--MIMEBOUNDARY
Content-Transfer-Encoding: 7bit
Content-Type: text/cloud-config
Mime-Version: 1.0

#cloud-config

ssh_authorized_keys:
  - ssh-rsa .... <redacted>

--MIMEBOUNDARY
Content-Transfer-Encoding: 7bit
Content-Type: text/x-shellscript
Mime-Version: 1.0

#!/usr/bin/env bash

.... <redacted>

--MIMEBOUNDARY--

The userdata is applied successfully to the system.

The issue is applying the static network information (above). It's successfully read in but not applied. The ifcfg-eth0 file is still set to dhcp as follows:

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=dhcp
DEVICE=eth0
HWADDR=00:50:56:8f:25:94
ONBOOT=yes
TYPE=Ethernet
USERCTL=no

The guestinfo documentation states that network config v2 is supported.

What am I missing or doing wrong here?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.