---
- name: Debug cgroup permissions
  hosts: germany
  become: yes
  tasks:
    - name: Check permissions of /sys/fs/cgroup/cpuset/
      stat:
        path: /sys/fs/cgroup/cpuset/
      register: cpuset_dir

    - name: Display cpuset dir stats
      debug:
        var: cpuset_dir.stat

    - name: Check for nomad subdir in cpuset
      stat:
        path: /sys/fs/cgroup/cpuset/nomad
      register: nomad_cpuset_dir
      ignore_errors: true

    - name: Display nomad cpuset dir stats
      debug:
        var: nomad_cpuset_dir.stat
      when: nomad_cpuset_dir.stat.exists is defined and nomad_cpuset_dir.stat.exists

    - name: List contents of /sys/fs/cgroup/cpuset/
      command: ls -la /sys/fs/cgroup/cpuset/
      register: ls_cpuset
      changed_when: false

    - name: Display contents of /sys/fs/cgroup/cpuset/
      debug:
        var: ls_cpuset.stdout_lines