Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
cloud-init "nocloud" networking setup

cloud-init is absolute cancer. Its code is horrible. It has no documentation at all.

It took me 5 fucking hours to figure out how to properly configure networking on recent cloud-init (Ubuntu 16.04 cloud image) with local datasource.

It's not mentioned anywhere you need to provide dsmode: local. (but only if you need network-config, besides that everything is fine; someone below noted that -m flag does the same thing, good to know) Of course nobody needs documentation for network-config format either. (cloudinit/net/__init__.py is a protip, enjoy the feces dive)

Oh, and by the way - no, it's not possible to provide network-config to uvt-kvm without patching shit.

Use -N flag for cloud-localds for network-config.

dsmode: local
# ↑ THIS. SHIT.
---
version: 1
config:
- type: physical
name: ens3
subnets:
- control: auto
type: static
address: |
192.168.21.37
pre-up echo xD > /tmp/yesitsthereyo # quality configuration injection, real thing
#cloud-config
chpasswd:
list: |
root:password
expire: False
write_files:
- content: |
You don't really need that, just a bloody test.
path: /root/test.txt
@craig-bishop

This comment has been minimized.

Show comment
Hide comment
@craig-bishop

craig-bishop Aug 30, 2016

Thank you for posting this! You literally saved our day. The Cloud Init project's documentation is utter crap right now. Unfortunately, since it's open-source, the usual response is "so work on the docs" :P

Thank you for posting this! You literally saved our day. The Cloud Init project's documentation is utter crap right now. Unfortunately, since it's open-source, the usual response is "so work on the docs" :P

@jowolf

This comment has been minimized.

Show comment
Hide comment
@jowolf

jowolf Sep 19, 2016

You say:

Use -H flag for cloud-localds for network-config.

But the -H flag for cloud-localds is to set the hostname -

How do I get the 'network-config' section above into cloud-localds? Do I just append it to meta-data?
(That would make sense, since it starts with '----', the yaml separator)

j

jowolf commented Sep 19, 2016

You say:

Use -H flag for cloud-localds for network-config.

But the -H flag for cloud-localds is to set the hostname -

How do I get the 'network-config' section above into cloud-localds? Do I just append it to meta-data?
(That would make sense, since it starts with '----', the yaml separator)

j

@willbryant

This comment has been minimized.

Show comment
Hide comment
@willbryant

willbryant Nov 8, 2016

Instead of network-config, you can pass dsmode: local and network-interfaces config to uvt-kvm using the --meta-data option.

Instead of network-config, you can pass dsmode: local and network-interfaces config to uvt-kvm using the --meta-data option.

@shawnmbradley

This comment has been minimized.

Show comment
Hide comment
@shawnmbradley

shawnmbradley Dec 15, 2016

I am using Ubuntu 16.04 server on a Raspberry Pi from here, I believe the cloud-init configuration is keeping a lot of my network configs from working such as creating a VLAN interface.

Just a note that I do have the kernel module for 802.1q loaded.

Everything works fine if I manually configure the VLAN interfaces after boot:

ip link add link eth0 name eth0.13 type vlan id 13
ip addr add 192.168.13.11/24 dev eth0.13
ip link set eth0.13 up

networking.service fails if I configure the interface in /etc/network/interfaces.d/10-eth0.cfg:

auto eth0
iface eth0 inet static
  address 192.168.1.11
  netmask 255.255.255.0
  gateway 192.168.1.1

auto eth0.13
iface eth0.13 inet static
    vlan-raw-device eth0
    address 192.168.13.12
    netmask 255.255.255.0

So my question is where should I change the meta-data and user-data files or add the network-config file?

There are multiple files in the /var/lib/cloud/ directory:

root@shawn-node02:/var/lib/cloud# tree

├── data
│   ├── instance-id
│   ├── previous-datasource
│   ├── previous-hostname
│   ├── previous-instance-id
│   ├── result.json
│   └── status.json
├── handlers
├── instance -> /var/lib/cloud/instances/nocloud
├── instances
│   └── nocloud
│       ├── boot-finished
│       ├── cloud-config.txt
│       ├── datasource
│       ├── handlers
│       ├── obj.pkl
│       ├── scripts
│       ├── sem
│       │   ├── config_apt_configure
│       │   ├── config_apt_pipelining
│       │   ├── config_byobu
│       │   ├── config_ca_certs
│       │   ├── config_chef
│       │   ├── config_disk_setup
│       │   ├── config_fan
│       │   ├── config_grub_dpkg
│       │   ├── config_keys_to_console
│       │   ├── config_landscape
│       │   ├── config_locale
│       │   ├── config_lxd
│       │   ├── config_mcollective
│       │   ├── config_mounts
│       │   ├── config_ntp
│       │   ├── config_package_update_upgrade_install
│       │   ├── config_phone_home
│       │   ├── config_power_state_change
│       │   ├── config_puppet
│       │   ├── config_rightscale_userdata
│       │   ├── config_rsyslog
│       │   ├── config_runcmd
│       │   ├── config_salt_minion
│       │   ├── config_scripts_per_instance
│       │   ├── config_scripts_user
│       │   ├── config_scripts_vendor
│       │   ├── config_seed_random
│       │   ├── config_set_hostname
│       │   ├── config_set_passwords
│       │   ├── config_snap_config
│       │   ├── config_snappy
│       │   ├── config_ssh
│       │   ├── config_ssh_authkey_fingerprints
│       │   ├── config_ssh_import_id
│       │   ├── config_timezone
│       │   ├── config_ubuntu_init_switch
│       │   ├── config_users_groups
│       │   ├── config_write_files
│       │   └── consume_data
│       ├── user-data.txt
│       ├── user-data.txt.i
│       ├── vendor-data.txt
│       └── vendor-data.txt.i
├── scripts
│   ├── per-boot
│   ├── per-instance
│   ├── per-once
│   └── vendor
├── seed
│   └── nocloud-net
│       ├── meta-data
│       └── user-data
└── sem
    ├── config_apt_pipelining.once
    └── config_scripts_per_once.once

and in /etc/cloud:


root@shawn-node02:/etc/cloud# tree
.
├── build.info
├── cloud.cfg
├── cloud.cfg.d
│   ├── 05_logging.cfg
│   ├── 90_dpkg.cfg
│   ├── 99-fake_cloud.cfg
│   └── README
└── templates
    ├── chef_client.rb.tmpl
    ├── hosts.debian.tmpl
    ├── hosts.freebsd.tmpl
    ├── hosts.redhat.tmpl
    ├── hosts.suse.tmpl
    ├── ntp.conf.debian.tmpl
    ├── ntp.conf.fedora.tmpl
    ├── ntp.conf.rhel.tmpl
    ├── ntp.conf.sles.tmpl
    ├── ntp.conf.ubuntu.tmpl
    ├── resolv.conf.tmpl
    ├── sources.list.debian.tmpl
    └── sources.list.ubuntu.tmpl

Thank you in advance for any advice or help, sorry for such a long post, I wanted to make sure I shared as much information as possible.

Regards,
Shawn

I am using Ubuntu 16.04 server on a Raspberry Pi from here, I believe the cloud-init configuration is keeping a lot of my network configs from working such as creating a VLAN interface.

Just a note that I do have the kernel module for 802.1q loaded.

Everything works fine if I manually configure the VLAN interfaces after boot:

ip link add link eth0 name eth0.13 type vlan id 13
ip addr add 192.168.13.11/24 dev eth0.13
ip link set eth0.13 up

networking.service fails if I configure the interface in /etc/network/interfaces.d/10-eth0.cfg:

auto eth0
iface eth0 inet static
  address 192.168.1.11
  netmask 255.255.255.0
  gateway 192.168.1.1

auto eth0.13
iface eth0.13 inet static
    vlan-raw-device eth0
    address 192.168.13.12
    netmask 255.255.255.0

So my question is where should I change the meta-data and user-data files or add the network-config file?

There are multiple files in the /var/lib/cloud/ directory:

root@shawn-node02:/var/lib/cloud# tree

├── data
│   ├── instance-id
│   ├── previous-datasource
│   ├── previous-hostname
│   ├── previous-instance-id
│   ├── result.json
│   └── status.json
├── handlers
├── instance -> /var/lib/cloud/instances/nocloud
├── instances
│   └── nocloud
│       ├── boot-finished
│       ├── cloud-config.txt
│       ├── datasource
│       ├── handlers
│       ├── obj.pkl
│       ├── scripts
│       ├── sem
│       │   ├── config_apt_configure
│       │   ├── config_apt_pipelining
│       │   ├── config_byobu
│       │   ├── config_ca_certs
│       │   ├── config_chef
│       │   ├── config_disk_setup
│       │   ├── config_fan
│       │   ├── config_grub_dpkg
│       │   ├── config_keys_to_console
│       │   ├── config_landscape
│       │   ├── config_locale
│       │   ├── config_lxd
│       │   ├── config_mcollective
│       │   ├── config_mounts
│       │   ├── config_ntp
│       │   ├── config_package_update_upgrade_install
│       │   ├── config_phone_home
│       │   ├── config_power_state_change
│       │   ├── config_puppet
│       │   ├── config_rightscale_userdata
│       │   ├── config_rsyslog
│       │   ├── config_runcmd
│       │   ├── config_salt_minion
│       │   ├── config_scripts_per_instance
│       │   ├── config_scripts_user
│       │   ├── config_scripts_vendor
│       │   ├── config_seed_random
│       │   ├── config_set_hostname
│       │   ├── config_set_passwords
│       │   ├── config_snap_config
│       │   ├── config_snappy
│       │   ├── config_ssh
│       │   ├── config_ssh_authkey_fingerprints
│       │   ├── config_ssh_import_id
│       │   ├── config_timezone
│       │   ├── config_ubuntu_init_switch
│       │   ├── config_users_groups
│       │   ├── config_write_files
│       │   └── consume_data
│       ├── user-data.txt
│       ├── user-data.txt.i
│       ├── vendor-data.txt
│       └── vendor-data.txt.i
├── scripts
│   ├── per-boot
│   ├── per-instance
│   ├── per-once
│   └── vendor
├── seed
│   └── nocloud-net
│       ├── meta-data
│       └── user-data
└── sem
    ├── config_apt_pipelining.once
    └── config_scripts_per_once.once

and in /etc/cloud:


root@shawn-node02:/etc/cloud# tree
.
├── build.info
├── cloud.cfg
├── cloud.cfg.d
│   ├── 05_logging.cfg
│   ├── 90_dpkg.cfg
│   ├── 99-fake_cloud.cfg
│   └── README
└── templates
    ├── chef_client.rb.tmpl
    ├── hosts.debian.tmpl
    ├── hosts.freebsd.tmpl
    ├── hosts.redhat.tmpl
    ├── hosts.suse.tmpl
    ├── ntp.conf.debian.tmpl
    ├── ntp.conf.fedora.tmpl
    ├── ntp.conf.rhel.tmpl
    ├── ntp.conf.sles.tmpl
    ├── ntp.conf.ubuntu.tmpl
    ├── resolv.conf.tmpl
    ├── sources.list.debian.tmpl
    └── sources.list.ubuntu.tmpl

Thank you in advance for any advice or help, sorry for such a long post, I wanted to make sure I shared as much information as possible.

Regards,
Shawn

@Informatic

This comment has been minimized.

Show comment
Hide comment
@Informatic

Informatic Feb 21, 2017

@jowolf yup, I made a mistake, thanks for noting that, it was supposed to be -N...
@willbryant meta-data - fine, but network-config is (at least was back when I wrote this document) supposed to be a separate file, and that was missing from uvt-kvm. After all I just made my own tooling for that.

Too bad gist doesn't notify about comments by default...

Owner

Informatic commented Feb 21, 2017

@jowolf yup, I made a mistake, thanks for noting that, it was supposed to be -N...
@willbryant meta-data - fine, but network-config is (at least was back when I wrote this document) supposed to be a separate file, and that was missing from uvt-kvm. After all I just made my own tooling for that.

Too bad gist doesn't notify about comments by default...

@frisbee23

This comment has been minimized.

Show comment
Hide comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment