--- - name: Install Docker packages community.general.pacman: name: - docker - docker-compose - name: Create docker user user: name: docker group: docker - name: Create docker-compose directory ansible.builtin.file: path: "{{ docker_compose_dir }}" owner: "{{ admin_username }}" group: "{{ admin_username }}" state: directory - name: Generate docker-compose.yml template: src: "docker-compose.yml.j2" dest: "{{ docker_compose_dir }}/docker-compose.yml" register: docker-comp - name: Create systemd unit file template: src: "docker-compose.service.j2" dest: "/etc/systemd/system/docker-compose.service" - name: Compose up systemd: name: docker-compose state: "{{ 'restarted' if docker-comp.changed else 'started' }}" enabled: true # for some reason port mappings don't work without this? - name: Restart docker for good measure systemd: name: docker state: restarted when: docker-comp.changed