1
votes

I want to deploy a Ninja app to an EC2 Amazon Linux instance using Ansible.

Being a Linux noob and completely new to Ansible, I wonder what the best way would be to start the app via Ansible as a service, rather than just starting a java process, which is what I do for now: java -jar [path to my jar].

This works for now, but it's not idempotent. I.e., I don't think Ansible can figure out a way to only to start the app if it's not already running.

I know Ansible has a service module. Would this be the one to use?

Update:

There's a role called fatjar-service on Ansible Galaxy looking like what I need, but it works only for Ubuntu servers. My server has Amazon Linux.

2

2 Answers

1
votes

I've always found it best to wrap the application (be it java or node or whatever) using something like Upstart, and use the standard start/stop commands or Ansible module to control the application from that point.

Ansible can easily deploy an upstart wrapper (its a conf file that is placed in /etc/init) alongside the copy of the application file. Once 'installed', start/stop work well.

Substitute Upstart (init) for System V (init.d) or SystemD as desired - there are many other options out there as well of course.

1
votes

Ansible service module is for managing existing OS services. Ansible doesn't have builtin modules that "create" services because there could be many different ways of creating such scripts for various OS/distros. Ansible can ensure that your registered services are enabled and running, but there're no builtin modules to create a service from arbitrary files.