--- - name: Build portainer compose dirs ansible.builtin.file: state: directory dest: '{{ portainer_base }}/{{ item.path }}' with_filetree: '../templates' when: item.state == 'directory' - name: Build portainer compose files ansible.builtin.template: src: '{{ item.src }}' dest: '{{ portainer_base }}/{{ item.path }}' with_filetree: '../templates' when: item.state == 'file' - name: Deploy Portainer stack ansible.builtin.command: cmd: "docker stack deploy -c {{ portainer_base }}/stacks/docker-compose.yml portainer"