How to manage images versions via docker-compose with Ansible
The best way is of course (like Zeitounator comments) to use a inventory var. Either you use the version number in the docker-compose task as a variable or you create a Jinja2 template docker-compose.yml.j2 and use the variable there. That's what I do.

Example:

all:
  hosts:
    host1.prod:
      image: "xyz/12"
    host2.dev:
      image: "xyz/latest"


And the docker-compose.yml.j2 contains the variable:

version: '2.1'

services:
  myservice:
    image: "{{ image }}"
    ...