0

Let's say an ansible task performs docker-compose pull, and reports the result like this:

changed_when: "'... pull complete' in result.stderr |default('')"

That works because stdout shows "... pull complete" only the first time - if the image exists then it does not.

Is there an similar way to deal with docker-compose build?

- name: foo
  shell: "docker-compose build"
  args:
    chdir: "{{FOO_PATH}}"
  register: result
  changed_when: "'???' in result.stderr |default('')"    # <----------- ?

Whether I'm building an image for the first time, or it already exists, stdout always shows me:

Successfully built fbd38aa5b45a
Successfully tagged foo/bar:latest

I also checked "$?" which is always 0. Is there a way to detect whether the build occurred or not?

lonix
  • 757
  • 9
  • 20
  • Any particular reason not to use the [`docker_compose` module](https://docs.ansible.com/ansible/latest/modules/docker_compose_module.html) ? It should be able to manage all this in a single task and manage idempotency for you. – Zeitounator May 22 '20 at 21:31
  • @Zeitounator I'm gonna try your way. Thanks for the tip. – lonix May 23 '20 at 03:25

0 Answers0