--- - name: test docker setup block: - name: run hello-world container become: true register: docker_test community.docker.docker_container: state: started name: hello-world image: hello-world - name: remove hello-world container become: true when: docker_test is changed community.docker.docker_container: state: absent name: hello-world image: hello-world