How can I set a static IP for juju machines?

This as a askubuntu question

I found a similar question from 2014, How to give a Juju charm a static ip address - wordpress, but the answer only says it’s not possible, but will be in 15.04, which doesn’t help much.

Currently the juju machines are set a IP from DHCP. I would like to set a static IP so that it doesn’t change; do I just SSH into the machine and modify the /etc/network/interfaces?

Edit:
I found bionical is using netplan instead of ifupdown, but this “doesn’t persist accross instances”:
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}
network:
    version: 2
    ethernets:
        ens192:
            dhcp4: true
            match:
                macaddress: <MAC>
            set-name: ens192

Is there a way to specify it in the bundle?

This is done at the provider level. For example, use MAAS to set the interface method to ‘static’ not ‘dhcp’.

modifed /etc/netplan/50-cloud-init.yaml (shown below), not sure if this is the right way to do it but communications still work between machines.
juju status shows wrong dns entries/public address for a while but eventually updates.

# 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}
network:
    version: 2
    ethernets:
        ens192:
            match:
                macaddress: <mac>
            set-name: ens192
            addresses:
              - 192.168.1.10/24
            gateway4: 192.168.1.1
            nameservers:
                search: [<domain>]
                addresses: [192.168.1.2,192.168.1.3]

It would depend heavily on the provider.
For example, if you are running on AWS, you’d have to use the dashboard to request a fixed IP address. As AWS won’t allow routing traffic to an IP address that it doesn’t understand.

If you are talking about MAAS, it already has support for defining static addresses for machines.

VMWare is a bit more tricky, as we only currently support DHCP based, because VMWare itself doesn’t seem to have support for defining static addresses for machines. In that case, editing /etc/netplan probably is the most straightforward way. Juju itself shouldn’t rewrite the file after starting.

I’ve encountered a problem where etcd certificate won’t update to the new IP

failed to check the health of member 1edf4e6f9264548 on https://192.168.1.73:2379: Get https://192.168.1.73:2379/health: x509: certificate is valid for 192.168.1.147, not 192.168.1.73

We might have to check with the folks that do the etcd charm to see if they’re picking up the changes and generating new certs that get handed out.

I’ve created a ticket on the GitHub etcd layers page, is there anywhere else I can get in contact with them?

So if you check out the charm homepage for the charm you can see in the right side links for the charm homepage and bug url.

Hopefully @kos.tsakalozos or @kwmonroe can provide some feedback in the near future.

Thanks for the bug!