name: Upgrade to debian bullseye
systems:
    node: foonode

always:
    - has_zfs=python: NODES.node.has_bundle('zfs')

pipeline:
    - manual: "set icinga2 downtime: https://icinga.franzi.business/monitoring/host/schedule-downtime?host={SYSTEMS.node}"

    # apply first so we only see the upgrade changes later
    - local: bw apply {SYSTEMS.node}
    - manual: update debian version in node groups
    - local: "bw apply -o bundle:apt -s symlink:/usr/bin/python pkg_apt: -- {SYSTEMS.node}"

    # double time!
    - remote@node: DEBIAN_FRONTEND=noninteractive apt-get -y -q -o Dpkg::Options::=--force-confold dist-upgrade
    - remote@node: DEBIAN_FRONTEND=noninteractive apt-get -y -q -o Dpkg::Options::=--force-confold dist-upgrade

    # reboot into bullseye
    - remote@node: systemctl reboot
    - local: |
        exit=1
        while [[ $exit -ne 0 ]];
        do
            sleep 1
            ssh {SYSTEMS.node} true
            exit=$?
        done

    # fix zfs and reboot again
    - has_zfs?remote@node: zpool import tank -f
    - has_zfs?remote@node: zpool upgrade -a
    - has_zfs?remote@node: systemctl reboot
    - has_zfs?local: |
        exit=1
        while [[ $exit -ne 0 ]];
        do
            sleep 1
            ssh {SYSTEMS.node} true
            exit=$?
        done

    # final apply
    - local: bw apply {SYSTEMS.node}
