Passing an nvidia GPU to a container launched via Ansible

I recently built an addition to my lab that is intended to mostly replace my Synology NAS1, and give a better home to my Plex container than my 2018 Mac mini. The comptuer is running Ubuntu 20.04 and has a nvidia Geforce GTX 1060. I chose the 1060 after refrring to this tool which gives nice estimates of of the Plex-specific capabilities enabled by the card. I wanted something that was available secondhand, had hardware h.265 support, and could handle a fair number of streams. 1060 ticked the right boxes.

After rsyncing my media and volumes, I spent some time last night working on the Ansible role for launching the plex container while passing the GPU to the contiainer. I spent a bunch of time in Ansible’s documentation and with this guide by Samuel Kadolph.

 
   - name: "Deploy Plex container"
    docker\_container:
        name: plex
        hostname: plex
        image: plexinc/pms-docker:plexpass
        restart\_policy: unless-stopped
        state: started
        ports: 
          - 32400:32400
          - 32400:32400/udp
          - 3005:3005
          - 8324:8324
          - 32469:32469
          - 32469:32469/udp
          - 1900:1900
          - 1900:1900/udp
          - 32410:32410
          - 32410:32410/udp
          - 32412:32412
          - 32412:32412/udp
          - 32413:32413
          - 32413:32413/udp
          - 32414:32414
          - 32414:32414/udp
        mounts:
          - source: /snoqualmie/media
            target: /media
            read\_only: no
            type: bind
          - source: /seatac/plex/config
            target: /config
            read\_only: no
            type: bind         
          - source: /seatac/plex/transcode
            target: /transcode
            read\_only: no
            type: bind
          - source: /seatac/plex/backups
            target: /data/backups
            read\_only: no
            type: bind
          - source: /seatac/plex/certs
            target: /data/certs
            read\_only: no
            type: bind
        env:
            TZ: "America/Los_Angeles"
            PUID: "1001"
            PGID: "997"
            PLEX\_CLAIM: "[claim key]"
            ADVERTISE\_IP: "[public URL]"
        device\_requests: 
          - device\_ids: 0
            driver: nvidia
            capabilities: 
              - gpu
              - compute
              - utility
        comparisons:
            env: strict

This is the part relevant to passing the GPU to the container, and the (lacking) documentation can be found [in the device_requests section, here].(https://docs.ansible.com/ansible/latest/collections/community/general/docker_container_module.html#parameter-device_requests)

        device_requests: 
          - device_ids: 0
            driver: nvidia
            capabilities: 
              - gpu
              - compute
              - utility

device_ids is the ID of the GPU that is obtained from nvidia-smi -L, capabilties are spelled out on nvidia’s repo, but all doesn’t seem to work.

Hope this helps the next poor soul who decides this is a rabbit worth chasing.


  1. I’ll keep Surveilance Station on my Syno for the time being. ↩︎

*****
Written on