- hosts: - numquam tasks: - become: yes copy: dest: /etc/systemd/system/docker.odoo.service content: | [Unit] After=docker.service Requires=docker.service [Service] TimeoutStartSec=0 Restart=always ExecStartPre=-/usr/bin/docker stop odoo ExecStartPre=-/usr/bin/docker rm odoo ExecStartPre=/usr/bin/docker pull odoo ExecStart=/usr/bin/docker run \ -e HOST=172.17.0.1 \ -e PORT=5432 \ -e USER=odoo \ -e PASSWORD=odoo \ -p 8069:8069 \ --name odoo -t \ odoo [Install] WantedBy=multi-user.target register: service_file - become: yes systemd: daemon_reload: yes when: service_file.changed - become: yes systemd: unit: docker.odoo.service enabled: yes state: started when: not service_file.changed - become: yes systemd: unit: docker.odoo.service enabled: yes state: restarted when: service_file.changed