Reading Time: 2 minutes

In this blog, I will be demonstrating how to create an AWS instance and how to deploy your play application on that AWS instance using Ansible.

First let’s see how to make an AWS instance:-

  1. Login to AWS console
  2. Click on launch instance on top and select the free instance
  3. Select the machine which you want to set up.
  4. Click on Configure Instance Details -> Select the number of instances -> Click Add Storage ->Add tags ->Next configure Security group
  5. Here we have to add a rule as our play application works on 9000 port
  6. Click on Add Rule ->Select Type =Custom TCP Port, Port Range=9000, Source= Anywhere and click Review and launch.
  7. Here you will get a key pair to log in to your machine. Download it so that in future you can use it.
  8. Now make an ssh connection with your machine

Command ssh -i abc.pem ec2-user@IP

Here abc.pem is the key which you have Downloaded and IP is the IP of your machine.

Now open your terminal and write command to create an executable file.

Command sbt dist

This command will create a zip file in ./target/universal/  folder

Now let’s see the script that we will write to deploy the application on AWS.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters

– hosts: test-servers
become: yes
become_user: root
– name: Check whether the executable file exists or not
path: /home/ec2-user/assignment-1.0-SNAPSHOT
register: stat_result
– name: "Unzip module"
unarchive: src=/home/knoldus/play/target/universal/ dest=/home/ec2-user
when: stat_result.stat.exists == False
– name: "Deploy website"
action: "shell sh /home/ec2-user/assignment-1.0-SNAPSHOT/bin/assignment >> /dev/null &"
async: 60
poll: 0
when: stat_result.stat.exists == False
view raw


hosted with ❤ by GitHub

Here I have used the 

stat module:- to see whether the file exists or not and store the result in variable stat_result which I have used in the next task.

If the file is found then I skip the task else I have used

unarchive module:-  to copy and extract the zip file in target destination.

Now to deploy play website I have used

action plugin: which is used to run my desired task in the background.

Async:– is used to asynchronous complete the task.

polling:-  is in how much time should I poll to see whether the task is completed or not.

Now we can run our application on IP:9000  port.

Written by 

Sachin is a software consultant having more than 0.5 years of experience. He loves to learn trending technologies. Sachin is familiar with languages such as Java, Scala and is currently working on DevOps technologies /tools like Kubernetes, Jenkins, Ansible, Docker, Bamboo.


  1. It would be nice to see the setup of the dependencies in the Playbook as well. Like installing/setting up a JDK. Also any thoughts on doing a Play app inside a Docker container?

    1. you can create a image of your play app and Deploy it on DockerHub and then pull that image in you aws

Comments are closed.