---
- name: "cgroups v2"
  lineinfile:
    path: /etc/default/grub
    insertafter: 'GRUB_CMDLINE_LINUX_DEFAULT='
    regex: 'GRUB_CMDLINE_LINUX_DEFAULT="[$]GRUB_CMDLINE_LINUX_DEFAULT systemd[.]unified_cgroup_hierarchy=1"'
    line: 'GRUB_CMDLINE_LINUX_DEFAULT="$GRUB_CMDLINE_LINUX_DEFAULT systemd.unified_cgroup_hierarchy=1"'
  register: grub_cgroups

- command: update-grub
  when: grub_cgroups.changed

- name: Enable user namespaces
  sysctl:
    name: kernel.unprivileged_userns_clone
    value: "1"
    state: present
    reload: true

- name: Add apt-key for podman
  apt_key:
      data: |
          -----BEGIN PGP PUBLIC KEY BLOCK-----
          Version: GnuPG v1.4.5 (GNU/Linux)

          mQENBFtkV0cBCADStSTCG5qgYtzmWfymHZqxxhfwfS6fdHJcbGUeXsI5dxjeCWhs
          XarZm6rWZOd5WfSmpXhbKOyM6Ll+6bpSl5ICHLa6fcpizYWEPa8fpg9EGl0cF12G
          GgVLnnOZ6NIbsoW0LHt2YN0jn8xKVwyPp7KLHB2paZh+KuURERG406GXY/DgCxUx
          Ffgdelym/gfmt3DSq6GAQRRGHyucMvPYm53r+jVcKsf2Bp6E1XAfqBrD5r0maaCU
          Wvd7bi0B2Q0hIX0rfDCBpl4rFqvyaMPgn+Bkl6IW37zCkWIXqf1E5eDm/XzP881s
          +yAvi+JfDwt7AE+Hd2dSf273o3WUdYJGRwyZABEBAAG0OGRldmVsOmt1YmljIE9C
          UyBQcm9qZWN0IDxkZXZlbDprdWJpY0BidWlsZC5vcGVuc3VzZS5vcmc+iQE+BBMB
          CAAoBQJfcJJOAhsDBQkIKusHBgsJCAcDAgYVCAIJCgsEFgIDAQIeAQIXgAAKCRBN
          ZDkDdQYKpB0xCACmtCT6ruPiQa4l0DEptZ+u3NNbZfSVGH4fE4hyTjLbzrCxqcoh
          xJvDKxspuJ85wWFWMtl57+lFFE1KP0AX2XTT+/v2vN1PIfwgOSw3yp2sgWuIXFAi
          89YSjSh8G0SGAH90A9YFMnTbllzGoGURjSX03iasW3A408ljbDehA6rpS3t3FD7P
          PnUF6204orYu00Qvc54an/xVJzxupb69MKW5EeK7x8MJnIToT8hIdOdGVD6axsis
          x+1U71oMK1gBke7p4QPUdhJFpSUd6kT8bcO+7rYouoljFNYkUfwnqtUn7525fkfg
          uDqqXvOJMpJ/sK1ajHOeehp5T4Q45L/qUCb3iEYEExECAAYFAltkV0cACgkQOzAR
          t2udZSOoswCdF44NTN09DwhPFbNYhEMb9juP5ykAn0bcELvuKmgDwEwZMrPQkG8t
          Pu9n
          =42uC
          -----END PGP PUBLIC KEY BLOCK-----

- name: Podman repository for Buster
  apt_repository:
      repo: "deb https://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/Debian_11/ /"
      filename: podman
      state: present

- apt:
    pkg:
      - libseccomp2
      - systemd
    state: latest
- apt:
    pkg:
      - podman
      - fuse-overlayfs

- apt:
    pkg:
      - slirp4netns
      - libslirp0
    state: absent

- copy:
    src: bin/slirp4netns-x86_64-v1.1.9
    dest: /usr/local/bin/slirp4netns
    mode: 0755

- copy:
    src: bin/fuse-overlayfs-x86_64-v1.4.0
    dest: /usr/local/bin/fuse-overlayfs
    mode: 0755

- name: Podman storage directory
  file:
    state: directory
    mode: 01777
    path: /var/obj/podman

- copy:
    dest: /etc/containers/storage.conf
    content: |
      [storage]
        driver = "overlay"
        runroot = "/var/obj/podman/storage"
        graphroot = "/var/obj/podman/storage"
        rootless_storage_path = "/var/obj/podman/$USER/storage"
      [storage.options]
        mount_program = "/usr/local/bin/fuse-overlayfs"
...
