Cloud init and static ip

Hi, we have got a video where the cloud init is presented. Everything ok, working with dhcp, but what in situation when we must setup static ip? Is this possible?
I can setup static ip but when i restart a server dhcp working again. Any ideas what to do?

I have never used cloud-init myself, but I believe the point of it is to have a single configuration for users, network and SSH keys that can be set up on multiple machines, so basically like a template that you don’t need to mess around with, like booting a new instance of the server and doing manual changes.

However, you will probably be able to modify cloud-init for static IP address once you boot onto one system. Give Techno Tim’s video a watch:

He’s using proxmox, which gives a nice GUI for cloud-init, but you can do it manually. However, the cloud-init file will always get generated by cloud-init automatically after every reboot, which is likely why you are seeing this issue.

All the answers telling you to directly edit /etc/netplan/50-cloud-init.yaml are wrong since CloudInit is used and will generate that file. In Ubuntu 18.04.2 it is clearly written inside the file :

$ cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource.  Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
            dhcp4: true
    version: 2

So you should not edit that file but the one under /etc/cloud/cloud.cfg.d/ if you still want to use CloudInit.

So you probably have to edit the disk containing the cloud-init image to get a static IP assigned. Someone in the same page said this:

If still using CloudInit, you need to do a sudo cloud-init clean -r to get the change to take [effect.]

Unsure if that helps, I’m no cloud-init guru, I’d rather make a template with all I need, then clone it and just slightly modify it, like setting a new static IP and a new hostname, cloud-init be damned!