image:
  distribution: Springdale

source:
  downloader: springdalelinux-http
  url: https://mirror.math.princeton.edu/pub/springdale/puias/
  keys:
  - |-
    -----BEGIN PGP PUBLIC KEY BLOCK-----
    Version: GnuPG v2.0.14 (GNU/Linux)

    mQILBEzhkmYBEAD1+atknNh1ufb0QZNKl6uMnOnAL2bk8v6VmUjVTNTJ6JBXdREX
    omVRlEDv1Jw9/11tDEI0JzZieqogahJ3GDqENXhLlfpgev+YHES6jrH8XEYkin/T
    wxuUyKvqoAk60wqC6Uv/TkHpVOYP9WHtNbybl3Pu8f2tzqdrE20HmQgEzVjTyHEw
    33WeAXWlhb/rIMcJ/edk0/hQ0Yu1NR34g/R/1azfz4uyx0qtrTDvaS7qxX5ZSUYZ
    tHzS8JjFpzRHI3A++Jv6yXMdzekn54TYob+DeKoRsdtfI0KryOv+92tcw4yM35CK
    d4apq8t35v56wsRXhwVZWEYn3BfIsdDoCF4XXH8nx0B1KJii6uYo1iiyIU10cT+g
    YCPVIzT+B/FqAmltx3VJg87sZ6QVFp3oFtIOlu14NQBv3wqUneCNK88EZAxi/kqy
    kFLq4NfWpn2dVZYRlJddWTXZ+qqaYQ6aI9HyGx5/QTI1hsxcOykrm8woZvptYeRQ
    IfkDFPgqTmdTqFaL5TQc43FvOLss9kBJ2FSbi3WpRIJW0/AQGc9/97SUnC0T075O
    R3cK+dQvI3QV3/p1UEowXlSHDFc5CrqKT11zMG9KE4UGm08yDbz0d5IbH0Cpzuku
    vidjBlsaQ/+OldjSFjHhCFLz55lLya6eMpPaScEKqoWNYzuNv9kDgVWXNwAGKbRN
    UFVJQVMgTGludXggRGlzdHJpYnV0aW9uIChSUE0gSW50ZWdyaXR5IFNpZ25hdHVy
    ZSkgPHB1aWFzQG1hdGgucHJpbmNldG9uLmVkdT6JAjQEEwECAB4FAkzhkmYCGwMG
    CwkIBwMCAxUCAwMWAgECHgECF4AACgkQFs/DM0GkCUi22xAAtoeFPRpYAoaq6+Ru
    nRX5GCDQl6DlOtVxLVclNZzGpnw8Extid+AOLqDXcfncyf04YhlEHj4misz/rDCI
    a5bRWoNjPHAgHpzCX7+I6pNr1hY9SOW94BEdng9IGGK0XhFBzflmySLZEC9E2ZYe
    RgWKJcDbyM9sDc2g440ICkn8DOWTvKMcQ7f0AzYtARXfmAEMqgqzNV+0wDJmdEHY
    7rif51U8bCOKns/UFKSA3WqUKhn5v2xo4OVqkm+bVG3z04KRAIUWIZIK8RHEp6wk
    clls8afYSufJmmUeczbE/wDqEgMSE3qGlcQRxTO3EMORb3nwWo5QAA4I/QPFrFoC
    QZQbaLNOx8P7dnfDoarJrUPYBBUFmMKvHUnSwv696QZhz70RvgjTHcbSyrnmE76C
    /XU0zUpeWN6FEb77zA1pIlqVf4hqRs+PCaG2sytBQVYEpYgGnoUPSWIT4a6NJtn+
    WwJHOqRYrGGTM0Z6V7IgMAkqiwEECn5eDUXYhqwUsyuVkbeOBWTc6nhsPIH3QC86
    sL0X/1hztP5sDoCne6SY3X3IyglvApvsKn0TOcVCvbYNhbg2bfPdvfmtSAV3/iMU
    yPw2JgfcvLeF1tiMQ7i5PfgyOn0Y3/lZjcclYHa1P5PEoTCA2lU7jLm0lmgIrh4N
    vYD0DGRZTGNEJYUDZFgRyynIOxk=
    =mKoc
    -----END PGP PUBLIC KEY BLOCK-----

targets:
  lxc:
    create_message: |
      You just created a {{ image.description }} container.
    config:
    - type: all
      before: 5
      content: |-
        lxc.include = LXC_TEMPLATE_CONFIG/centos.common.conf

    - type: user
      before: 5
      content: |-
        lxc.include = LXC_TEMPLATE_CONFIG/centos.userns.conf

    - type: all
      after: 4
      content: |-
        lxc.include = LXC_TEMPLATE_CONFIG/common.conf

    - type: user
      after: 4
      content: |-
        lxc.include = LXC_TEMPLATE_CONFIG/userns.conf

    - type: all
      content: |-
        lxc.arch = {{ image.architecture_kernel }}

files:
- name: hostname
  path: /etc/hostname
  generator: hostname

- name: hosts
  path: /etc/hosts
  generator: hosts

- path: /etc/machine-id
  generator: dump

- path: /var/lib/dbus/machine-id
  generator: remove

- name: ifcfg-eth0
  path: /etc/sysconfig/network-scripts/ifcfg-eth0
  generator: dump
  templated: true
  content: |-
    DEVICE=eth0
    BOOTPROTO=dhcp
    ONBOOT=yes
    HOSTNAME=LXC_NAME
    NM_CONTROLLED=no
    TYPE=Ethernet
    MTU=
    DHCP_HOSTNAME=LXC_NAME
  releases:
  - 7
  types:
  - container

- name: ifcfg-eth0
  path: /etc/sysconfig/network-scripts/ifcfg-eth0
  generator: dump
  templated: true
  content: |-
    DEVICE=eth0
    BOOTPROTO=dhcp
    ONBOOT=yes
    HOSTNAME=LXC_NAME
    TYPE=Ethernet
    MTU=
    DHCP_HOSTNAME=LXC_NAME
  releases:
  - 8
  - 9
  types:
  - container

- name: ifcfg-eth0.incus
  path: /etc/sysconfig/network-scripts/ifcfg-eth0
  generator: template
  content: |-
    DEVICE=eth0
    BOOTPROTO=dhcp
    ONBOOT=yes
    HOSTNAME={{ container.name }}
    NM_CONTROLLED=no
    TYPE=Ethernet
    MTU=
    DHCP_HOSTNAME={{ container.name }}
  releases:
  - 7

- name: ifcfg-eth0.incus
  path: /etc/sysconfig/network-scripts/ifcfg-eth0
  generator: template
  content: |-
    DEVICE=eth0
    BOOTPROTO=dhcp
    ONBOOT=yes
    HOSTNAME={{ container.name }}
    TYPE=Ethernet
    MTU=
    DHCP_HOSTNAME={{ container.name }}
    IPV6INIT=yes
  releases:
  - 8
  - 9
  types:
  - container

- name: ifcfg-enp5s0.incus
  path: /etc/sysconfig/network-scripts/ifcfg-enp5s0
  generator: template
  content: |-
    DEVICE=enp5s0
    BOOTPROTO=dhcp
    ONBOOT=yes
    HOSTNAME={{ container.name }}
    TYPE=Ethernet
    MTU=
    DHCP_HOSTNAME={{ container.name }}
  releases:
  - 8
  - 9
  types:
  - vm

- path: /etc/default/grub
  generator: dump
  content: |-
    # Set the recordfail timeout
    GRUB_RECORDFAIL_TIMEOUT=0
    # Do not wait on grub prompt
    GRUB_TIMEOUT=0
    # Set the default commandline
    GRUB_CMDLINE_LINUX_DEFAULT="${GRUB_CMDLINE_LINUX_DEFAULT} console=tty1 console=ttyS0"
    # Set the grub console type
    GRUB_TERMINAL=console
    # Disable os-prober
    GRUB_DISABLE_OS_PROBER=true
  types:
  - vm

- path: /etc/dracut.conf.d/incus.conf
  generator: dump
  content: |-
    add_drivers+="virtio_scsi virtio_pci virtio_console"
  types:
  - vm
  releases:
  - 7

- path: /etc/dracut.conf.d/incus.conf
  generator: dump
  content: |-
    add_drivers+="virtio_scsi virtio_console sd_mod"
  types:
  - vm
  releases:
  - 8
  - 9

- generator: fstab
  types:
  - vm

- path: /etc/fstab
  generator: dump
  types:
  - container

- name: incus-agent-workaround.service
  path: /etc/systemd/system/incus-agent-workaround.service
  generator: dump
  content: |-
    [Unit]
    Description=LXD - agent (centos workaround)
    Before=incus-agent.service

    [Service]
    Type=oneshot
    ExecStart=-/bin/mkdir /run/incus_agent

    [Install]
    WantedBy=multi-user.target
  types:
  - vm
  releases:
  - 7

- name: incus-agent.override
  path: /etc/systemd/system/incus-agent.service.d/incus.conf
  generator: dump
  content: |-
    [Service]
    WorkingDirectory=/run/incus_agent
  types:
  - vm
  releases:
  - 7

- name: network
  path: /etc/sysconfig/network
  generator: dump
  templated: true
  content: |-
    NETWORKING=yes
    HOSTNAME=LXC_NAME

- name: network.incus
  path: /etc/sysconfig/network
  generator: template
  content: |-
    NETWORKING=yes
    HOSTNAME={{ container.name }}

- name: meta-data
  generator: cloud-init
  variants:
  - cloud

- name: network-config
  generator: cloud-init
  variants:
  - cloud
  releases:
  - 7

- name: network-config
  generator: cloud-init
  content: |-
    {% if config_get("user.network-config", "") == "" %}version: 1
    config:
      - type: physical
        name: {% if instance.type == "virtual-machine" %}enp5s0{% else %}eth0{% endif %}
        subnets:
          - type: {% if config_get("user.network_mode", "") == "link-local" %}manual{% else %}dhcp{% endif %}
            control: auto
          - type: dhcp6
            control: auto{% else %}{{ config_get("user.network-config", "") }}{% endif %}
  variants:
  - cloud
  releases:
  - 8
  - 9

- name: user-data
  generator: cloud-init
  variants:
  - cloud

- name: vendor-data
  generator: cloud-init
  variants:
  - cloud

- generator: incus-agent
  types:
  - vm

packages:
  manager: yum
  update: true
  cleanup: true
  sets:
  - packages:
    - cronie
    - cronie-noanacron
    - curl
    - dhclient
    - hostname
    - initscripts
    - openssh-clients
    - passwd
    - policycoreutils
    - rootfiles
    - rsyslog
    - sudo
    - vim-minimal
    action: install

  - packages:
    - network-scripts
    action: install
    types:
    - container
    variants:
    - default
    releases:
    - 8
    - 9

  - packages:
    - NetworkManager
    action: install
    types:
    - vm
    variants:
    - default

  - packages:
    - cloud-init
    - NetworkManager
    - openssh-server
    action: install
    variants:
    - cloud

  - packages:
    - shim
    action: install
    types:
    - vm

  - packages:
    - kernel-plus
    action: install
    types:
    - vm

  - packages:
    - grub2-efi-x64
    action: install
    types:
    - vm
    architectures:
    - x86_64

actions:
- trigger: post-unpack
  action: |-
    #!/bin/sh
    set -eux

    # Enable the centosplus repo which has a kernel with 9p support
    sed -i 's/^enabled=0/enabled=1/' /etc/yum.repos.d/CentOS-Base.repo
  types:
  - vm
  releases:
  - 7

- trigger: post-unpack
  action: |-
    #!/bin/sh
    set -eux

    # Enable the centosplus repo which has a kernel with 9p support
    sed -i 's/^enabled=0/enabled=1/' /etc/yum.repos.d/CentOS-Linux-Plus.repo
  types:
  - vm
  releases:
  - 8
  - 9

- trigger: post-unpack
  action: |-
    #!/bin/sh
    # Generate machine-id in order for the kernel stuff to be configured properly
    systemd-machine-id-setup
  types:
  - vm

- trigger: post-packages
  action: |-
    #!/bin/sh
    set -eux

    # Disable SELinux
    mkdir -p /selinux
    echo 0 > /selinux/enforce

    # Disable loginuid in PAM stack
    sed -i '/^session.*pam_loginuid.so/s/^session/# session/' /etc/pam.d/*

- trigger: post-files
  action: |-
    #!/bin/sh
    set -eux

    mount -t tmpfs tmpfs /sys/firmware
    mkdir /sys/firmware/efi

    # Regenerate initramfs
    kver=$(ls /boot/initramfs-*.img | sed -r 's#.*initramfs-(.+)\.img#\1#')
    dracut --kver "${kver}" -f

    target="$(readlink -f /etc/grub2-efi.cfg)"
    grub2-mkconfig -o "${target}"

    umount /sys/firmware

    sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"

    # Workaround for broken systemd in centos7
    systemctl enable incus-agent-workaround.service
  types:
  - vm
  releases:
  - 7

- trigger: post-files
  action: |-
    #!/bin/sh
    set -eux

    # Regenerate initramfs
    kver=$(ls /boot/initramfs-*.img | sed -r 's#.*initramfs-(.+)\.img#\1#')
    dracut --kver "${kver}" -f

    target="$(readlink -f /etc/grub2-efi.cfg)"
    grub2-mkconfig -o "${target}"

    sed -i "s#root=[^ ]*#root=/dev/sda2#g" "${target}"
  types:
  - vm
  releases:
  - 8
  - 9

- trigger: post-files
  action: |-
    #!/bin/sh
    set -eux

    systemctl enable NetworkManager.service
  types:
  - vm
  variants:
  - default

- trigger: post-files
  action: |-
    #!/bin/sh
    set -eux

    systemctl enable network
  types:
  - container
  variants:
  - default
  releases:
  - 8
  - 9
