#cloud-config
hostname: lab-web-01
preserve_hostname: false
manage_etc_hosts: true
timezone: Asia/Seoul

disable_root: true
ssh_pwauth: false
users:
  - name: ops
    groups: [adm, sudo]
    shell: /bin/bash
    lock_passwd: true
    sudo: ['ALL=(ALL:ALL) NOPASSWD:ALL']
    ssh_authorized_keys:
      - REPLACE_WITH_YOUR_SSH_PUBLIC_KEY

package_update: true
packages:
  - nginx
  - curl

write_files:
  - path: /var/www/html/index.html
    owner: root:root
    permissions: '0644'
    content: |
      <!doctype html>
      <html lang="en">
      <meta charset="utf-8">
      <title>cloud-init lab</title>
      <h1>lab-web-01 ready</h1>
      </html>
  - path: /usr/local/sbin/bootstrap-web
    owner: root:root
    permissions: '0750'
    content: |
      #!/bin/sh
      set -eu
      nginx -t
      systemctl enable --now nginx
      curl --retry 5 --retry-connrefused --retry-delay 1 -fsS \
        http://127.0.0.1/ | grep -Fq 'lab-web-01 ready'
      install -d -m 0755 /var/lib/maruops
      date -Iseconds > /var/lib/maruops/bootstrap.done

runcmd:
  - [sh, -eu, /usr/local/sbin/bootstrap-web]
