--- - name: Create agentdvr. become: yes user: name: agentdvr system: yes home: /home/agentdvr shell: /bin/bash append: yes groups: video - name: Add {{ ansible_user }} to agentdvr group. become: yes user: name: "{{ ansible_user }}" append: yes groups: agentdvr - name: Create /home/agentdvr/. become: yes file: path: /home/agentdvr state: directory owner: agentdvr group: agentdvr mode: u=rwx,g=rwxs,o=rx - name: Test for AgentDVR directory. stat: path: /home/agentdvr/AgentDVR register: agentdvr - debug: msg: "/home/agentdvr/AgentDVR/ does not yet exist" when: not agentdvr.stat.exists - name: Install AgentDVR.service. become: yes copy: content: | [Unit] Description=AgentDVR [Service] WorkingDirectory=/home/agentdvr/AgentDVR ExecStart=/home/agentdvr/AgentDVR/Agent # fix memory management issue with dotnet core Environment="MALLOC_TRIM_THRESHOLD_=100000" # to query logs using journalctl, set a logical name here SyslogIdentifier=AgentDVR User=agentdvr # ensure the service automatically restarts Restart=always # amount of time to wait before restarting the service RestartSec=5 [Install] WantedBy=multi-user.target dest: /etc/systemd/system/AgentDVR.service when: agentdvr.stat.exists - name: Enable/Start AgentDVR.service. become: yes systemd: service: AgentDVR enabled: yes state: started when: agentdvr.stat.exists - name: Create /DVR/AgentDVR/. become: yes file: state: directory path: /DVR/AgentDVR owner: agentdvr group: agentdvr mode: u=rwx,g=rxs,o= - name: Create /DVR/AgentDVR/video/. become: yes file: state: directory path: /DVR/AgentDVR/video owner: agentdvr group: agentdvr mode: u=rwx,g=rxs,o=