--- - name: Deploy spring petclinic as Linux Service hosts: appserver become: yes tasks: - name: Fail the execution when the distribution is not ubuntu and centos fail: msg: "This playbook will work only on ubuntu instances. Support for other OS will be added soon" when: ansible_facts['distribution'] != "Ubuntu" and ansible_facts['distribution'] != "CentOS" - name: install java package: name: "{{ java_package }}" state: present - name: Create a spring petclinic directory file: path: "{{ app_dir }}" state: directory notify: - debug message for directory creation - name: download spring petclinic get_url: url: "{{ app_download_url }}" dest: "{{ app_file_name }}" - name: Create springbootuser user: name: "{{ app_username }}" password: "{{ app_username }}" state: present notify: - Change ownership of jar file - name: Copy the spring petclinic service file copy: dest: /etc/systemd/system/springpetclinic.service src: springpetclinic.service - name: Enable and start spring petclinic systemd: name: springpetclinic.service enabled: yes state: started handlers: - name: Change ownership of jar file file: path: "{{ app_file_name }}" owner: "{{ app_username }}" mode: '500' state: file - name: debug message for java debug: msg: "java with package {{ java_package }} is installed" - name: debug message for directory creation debug: msg: "Directory created at {{ app_dir }}"