Depending upon the init system of your underlying box (init.d or systemctl) there are two approaches.
init.d
With ansible you can create a symlink of your application jar under
/etc/init.d/<your_service_name>
You can then use ansible's service module to manage the state of the
service
- service:
name: <your_service_name>
state: restarted
More info: Ansible service module documentation
systemctl
If your init method is systemd you will have to create a very simple Unit file
[Unit]
Description=<Description>
[Service]
ExecStart=/path/to/<your_app>.jar
[Install]
WantedBy=multi-user.target
Copy the unit file to
/etc/systemd/service/<your_unit_file>.service
Then you can use ansible's systemd module to manage the state of the service
- name: Start Service
systemd:
name: <your service name>
state: started
More info: Ansible systemd module documentation