---
- include: user.yml

- name: "Installing app {{app.name}}" 
  appmgr_app: upgrade={{upgrade}} coordinates={{app_coordinates}} name={{app.name}} maven_repository={{maven_repository}} user={{app_user}} group={{app_group}} base={{app_home}}
  sudo: yes
  sudo_user: "{{app_user}}"
  notify:
    - "restart app {{app.name}}"

- name: "Configuring app {{app.name}}"
  appmgr_config: name={{app.name}} key={{item.name}} value={{item.value}} base={{app_home}}
  with_items: app.config
  sudo_user: "{{app_user}}"
  when: app.config is defined
  sudo: yes

- name: "Handling environment variables"
  template: src=environment.j2 dest={{app_home}}/{{app.name}}/environment
  when: app.environment is defined
  sudo: yes

- name: Install init script
  template: src=skeleton.j2 dest=/etc/init.d/{{app_init_prefix}}{{app.name}} mode=0755 owner=root group=root
  sudo: yes
  when: ansible_distribution == "Debian"

- name: Install init script
  template: src=app.conf.j2 dest=/etc/init/{{app_init_prefix}}{{app.name}}.conf owner={{app_user}} group={{app_group}}
  sudo: yes
  when: ansible_distribution == "Ubuntu"

- name: "Enable application {{app.name}}"
  service: name={{app_init_prefix}}{{app.name}} enabled=yes
  sudo: yes

---
- include: user.yml

- name: "Installing app {{app.name}}" 
  appmgr_app: upgrade={{upgrade}} coordinates={{app_coordinates}} name={{app.name}} maven_repository={{maven_repository}} user={{app_user}} group={{app_group}} base={{app_home}}
  sudo: yes
  sudo_user: "{{app_user}}"
  notify:
    - "restart app {{app.name}}"

- name: "Configuring app {{app.name}}"
  appmgr_config: name={{app.name}} key={{item.name}} value={{item.value}} base={{app_home}}
  with_items: app.config
  sudo_user: "{{app_user}}"
  when: app.config is defined
  sudo: yes

- name: "Handling environment variables"
  template: src=environment.j2 dest={{app_home}}/{{app.name}}/environment
  when: app.environment is defined
  sudo: yes

- name: Install init script
  template: src=skeleton.j2 dest=/etc/init.d/{{app_init_prefix}}{{app.name}} mode=0755 owner=root group=root
  sudo: yes
  when: ansible_distribution == "Debian"

- name: Install init script
  template: src=app.conf.j2 dest=/etc/init/{{app_init_prefix}}{{app.name}}.conf owner={{app_user}} group={{app_group}}
  sudo: yes
  when: ansible_distribution == "Ubuntu"

- name: "Enable application {{app.name}}"
  service: name={{app_init_prefix}}{{app.name}} enabled=yes state=restarted
  sudo: yes

Set state of deployed app to restarted
Set state of deployed app to restarted

To make sure it is started on first deploy and restarted on further deploys