# Netplan configuration & Cloudinit

**Cloud-init** is a tool used to automate the initial configuration of a cloud instance (e.g., a virtual machine or server) during its first boot. It is widely used in cloud environments like AWS, Azure, and OpenStack to configure the operating system and software packages automatically.

Key tasks that Cloud-init can perform include:

* Setting up networking (e.g., static IP addresses or DHCP)
* Configuring users and groups (e.g., creating user accounts)
* Installing and configuring software packages
* Running custom scripts
* Managing system settings like timezone, locale, etc.

Cloud-init reads configuration files (like YAML or scripts) and applies these settings to the instance automatically when it is first booted or during subsequent reboots, ensuring that the system is properly set up without manual intervention.

***

#### To resolve the issue where Cloud-init resets your Netplan configuration on reboot, follow these steps:

#### 1. **Disable Cloud-init's Network Configuration**

You can disable Cloud-init's network configuration to prevent it from overwriting your Netplan file.

1. **Edit Cloud-init configuration:**

   Open the file `/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg` (you may need to create this file if it doesn't exist) and add the following line:

   ```bash
   network: {config: disabled}
   ```

   This setting will tell Cloud-init to not touch the network configuration.
2. **Reboot or restart Cloud-init:**

   After making the change, you can either reboot the machine or run:

   ```bash
   sudo cloud-init clean
   ```

   This will clear Cloud-init's data and allow it to re-run on the next boot without affecting the network config.

#### 2. **Modify the Netplan Configuration Directly**

Make sure your `/etc/netplan/*.yaml` configuration files are correct and persistent. For example, if you want to use a static IP address, your `00-installer-config.yaml` or another Netplan config file should look something like this:

```yaml
network:
  version: 2
  renderer: networkd
  ethernets:
    enp3s0:
      dhcp4: false
      addresses:
        - 192.168.1.100/24
      gateway4: 192.168.1.1
      nameservers:
        addresses:
          - 8.8.8.8
          - 8.8.4.4
```

#### 3. **Ensure Netplan is Active**

After editing the Netplan configuration, run the following command to apply it:

```bash
sudo netplan apply
```

This will ensure that your network settings are applied immediately.

#### 4. **Make Sure Cloud-init Does Not Revert Changes**

If you want to prevent Cloud-init from overwriting the `/etc/netplan` configurations completely, you can stop Cloud-init from processing at all:

1. **Prevent Cloud-init from running network configuration**:

   If you want to ensure Cloud-init never modifies anything related to the network, you can stop the network configuration part of Cloud-init altogether by disabling Cloud-init's networking config as described in step 1.
2. **You can also disable the Cloud-init service** (but this is less recommended unless you are sure you don't need Cloud-init at all):

   ```bash
   sudo systemctl stop cloud-init
   sudo systemctl disable cloud-init
   ```

#### 5. **Check the Logs for Debugging**

If you're still having issues, it’s useful to check the Cloud-init logs for any errors or messages related to the network configuration. You can find the logs at:

* `/var/log/cloud-init.log`
* `/var/log/cloud-init-output.log`

Look for messages indicating network configurations are being overwritten or any errors that might provide a clue.

#### Summary

* Disable Cloud-init’s network config by adding `network: {config: disabled}` to `/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg`.
* Modify the Netplan configuration to match your desired network settings.
* Apply the changes using `netplan apply`.
* Optionally, prevent Cloud-init from running entirely if it’s not needed on your system.

***

#### Completly removing cloud init configuration
