virtualization:lxd:cloud-init

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
virtualization:lxd:cloud-init [2026/09/27 21:11] – ilyasavirtualization:lxd:cloud-init [2026/09/28 02:46] (current) – ilyasa
Line 1: Line 1:
-====== Cloud-Init: Dokumentasi Umum ======+{{indexmenu_n> 0010}} 
 +====== LXD: Cloud-Init ======
  
 ===== Apa itu Cloud-Init? ===== ===== Apa itu Cloud-Init? =====
Line 13: Line 14:
  
 Semua bisa disiapkan **sebelum** instance dinyalakan. Semua bisa disiapkan **sebelum** instance dinyalakan.
 +
 +{{ :images:capture:lxd-cloud-initscreenshot_2026-09-28_02-40-25.png?nolink&800 |}}
 +
  
 ===== 3 Komponen Utama ===== ===== 3 Komponen Utama =====
Line 180: Line 184:
       addresses:       addresses:
         - 10.14.3.53         - 10.14.3.53
 +</code>
 +
 +===== Parameter Tambahan yang Berguna =====
 +
 +Selain contoh dasar di atas, berikut parameter lain yang sering dipakai.
 +
 +==== User Data — Parameter Lain ====
 +
 +**Konfigurasi user lebih lanjut:**
 +
 +<code yaml>
 +#cloud-config
 +
 +users:
 +  - name: ilyasa
 +    groups: sudo
 +    shell: /bin/bash
 +    sudo: ALL=(ALL) NOPASSWD:ALL
 +    lock_passwd: false          # izinkan login password (default: true = dikunci)
 +    passwd: $6$rounds=4096$...  # hash password (bukan plaintext)
 +    primary_group: ilyasa
 +    expiredate: '2026-12-31'    # akun expired otomatis
 +</code>
 +
 +**Set password tanpa hash manual (auto-generate/plaintext):**
 +
 +<code yaml>
 +chpasswd:
 +  list: |
 +    ilyasa:password123
 +  expire: false
 +</code>
 +
 +**Hostname & FQDN:**
 +
 +<code yaml>
 +hostname: server-001
 +fqdn: server-001.ilyasa.id
 +manage_etc_hosts: true
 +</code>
 +
 +**Tulis file langsung ke instance:**
 +
 +<code yaml>
 +write_files:
 +  - path: /etc/motd
 +    content: |
 +      Selamat datang di server saya.
 +    owner: root:root
 +    permissions: '0644'
 +</code>
 +
 +**Jalankan command saat boot:**
 +
 +<code yaml>
 +bootcmd:
 +  - echo "jalan paling awal, bahkan sebelum network up" >> /var/log/boot-note.log
 +
 +runcmd:
 +  - systemctl enable --now nginx
 +  - ufw allow 22/tcp
 +</code>
 +
 +**Matikan/reboot otomatis setelah cloud-init selesai:**
 +
 +<code yaml>
 +power_state:
 +  mode: reboot     # pilihan: poweroff, reboot, halt
 +  timeout: 30
 +  message: Rebooting setelah provisioning
 +</code>
 +
 +**Lain-lain yang sering dipakai:**
 +
 +  * ''disable_root: true'' → nonaktifkan login root langsung
 +  * ''final_message: "Provisioning selesai dalam $UPTIME detik"'' → pesan di akhir proses
 +
 +==== Vendor Data — Parameter Lain ====
 +
 +Vendor Data pada dasarnya bisa memakai **modul yang sama** dengan User Data, tapi biasanya diisi hal-hal default/umum untuk semua instance.
 +
 +**Locale & NTP:**
 +
 +<code yaml>
 +locale: en_US.UTF-8
 +
 +ntp:
 +  enabled: true
 +  servers:
 +    - 0.id.pool.ntp.org
 +    - 1.id.pool.ntp.org
 +</code>
 +
 +**Resize disk otomatis (berguna kalau disk image lebih kecil dari alokasi):**
 +
 +<code yaml>
 +growpart:
 +  mode: auto
 +  devices: ['/']
 +</code>
 +
 +**Mount tambahan (misal swap):**
 +
 +<code yaml>
 +mounts:
 +  - [ /dev/sdb1, /mnt/data, ext4, "defaults,nofail", "0", "2" ]
 +
 +swap:
 +  filename: /swapfile
 +  size: 1073741824    # 1GB dalam byte
 +</code>
 +
 +**Upgrade & reboot otomatis kalau perlu:**
 +
 +<code yaml>
 +package_upgrade: true
 +package_reboot_if_required: true
 +</code>
 +
 +==== Network Config — Parameter Lain ====
 +
 +Network Config v2 mengikuti sintaks **Netplan**, jadi parameter-parameter Netplan berikut ini berlaku juga.
 +
 +**MTU custom:**
 +
 +<code yaml>
 +version: 2
 +ethernets:
 +  eth0:
 +    dhcp4: true
 +    mtu: 1400
 +</code>
 +
 +**Match interface berdasarkan MAC address (berguna kalau nama interface tidak konsisten):**
 +
 +<code yaml>
 +version: 2
 +ethernets:
 +  nic0:
 +    match:
 +      macaddress: "00:16:3e:xx:xx:xx"
 +    set-name: eth0
 +    dhcp4: true
 +</code>
 +
 +**DNS search domain:**
 +
 +<code yaml>
 +nameservers:
 +  addresses: [10.14.3.53]
 +  search: [fopens.example, lab.local]
 +</code>
 +
 +**Kontrol DHCP lebih detail (dhcp4-overrides):**
 +
 +<code yaml>
 +version: 2
 +ethernets:
 +  eth0:
 +    dhcp4: true
 +    dhcp4-overrides:
 +      use-dns: false        # abaikan DNS dari DHCP, pakai nameservers manual
 +      route-metric: 100
 +</code>
 +
 +**Interface opsional (boot tidak nunggu link up, cocok untuk lab/testing):**
 +
 +<code yaml>
 +version: 2
 +ethernets:
 +  eth0:
 +    dhcp4: true
 +    optional: true
 +</code>
 +
 +**VLAN tagging:**
 +
 +<code yaml>
 +version: 2
 +ethernets:
 +  eth0:
 +    dhcp4: false
 +vlans:
 +  vlan100:
 +    id: 100
 +    link: eth0
 +    addresses:
 +      - 10.100.0.10/24
 +</code>
 +
 +**Bridge (berguna untuk lab virtualisasi/container):**
 +
 +<code yaml>
 +version: 2
 +ethernets:
 +  eth0:
 +    dhcp4: false
 +bridges:
 +  br0:
 +    interfaces: [eth0]
 +    addresses:
 +      - 10.14.3.50/24
 +    routes:
 +      - to: default
 +        via: 10.14.3.1
 </code> </code>
  
  • virtualization/lxd/cloud-init.1790518288.txt.gz
  • Last modified: 2026/10/08 04:33
  • (external edit)