Created
November 27, 2017 07:11
-
-
Save kmurudi/239595a9b13c55e99f424e8e66157d8f to your computer and use it in GitHub Desktop.
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: localhost | |
become: yes | |
gather_facts: no | |
tasks: | |
- name: install boto | |
command: sudo apt-get -y install python-boto | |
- name: Get credentials from vault | |
include_vars: | |
file: password.yml | |
name: vault | |
- name: set variables | |
set_fact: | |
hostname: service | |
py_path: /usr/bin/python3 | |
- name: Create a new EC2 host | |
ec2: | |
aws_access_key: "{{ vault['aws_access_key'] }}" | |
aws_secret_key: "{{ vault['aws_secret_key'] }}" | |
key_name: skey | |
instance_type: t2.micro | |
image: ami-da05a4a0 | |
wait: yes | |
region: us-east-1 | |
vpc_subnet_id: subnet-c36b5fef | |
count: 1 | |
assign_public_ip: yes | |
register: ec2 | |
- debug: | |
var: ec2.instances[0].public_ip | |
- name: add ec2 host | |
add_host: | |
name: "{{ ec2.instances[0].public_ip }}" | |
groups: "{{ hostname }}" | |
ansible_ssh_user: ubuntu | |
ansible_ssh_private_key_file: /home/ubuntu/keys/skey.pem | |
ansible_python_interpreter: "{{ py_path }}" | |
host_key_checking: false | |
- name: Wait for ec2 instance to bootup | |
wait_for: | |
host: "{{ ec2.instances[0].public_ip }}" | |
port: 22 | |
delay: 60 | |
timeout: 320 | |
state: started | |
- name: accept new ssh fingerprints | |
shell: ssh-keyscan -H {{ ec2.instances[0].public_ip }} >> ~/.ssh/known_hosts | |
- name: install pexpect module | |
apt: | |
name: python-pexpect | |
state: present | |
- name: git clone | |
expect: | |
command: git clone https://github.ncsu.edu/rmuddur/Scrumster.git | |
responses: | |
"Username for 'https://github.ncsu.edu':": "{{ vault['user'] }}" | |
"Password for 'https://[email protected]':": "{{ vault['password'] }}" | |
- name: Add Java repository | |
apt_repository: repo='ppa:webupd8team/java' state=present update_cache=yes | |
become: true | |
- name: Add license for java | |
debconf: name='oracle-java8-installer' question='shared/accepted-oracle-license-v1-1' value=true vtype=select | |
become: true | |
- name: Install java and maven | |
apt: name={{item}} state=present | |
with_items: | |
- oracle-java8-installer | |
- oracle-java8-set-default | |
- maven | |
become: true | |
- name: run mvn clean install on repo | |
command: mvn clean install | |
ignore_errors: True | |
failed_when: False | |
args: | |
chdir: "/home/ubuntu/Scrumster/Alexa-service/ScrumsterService/" | |
- hosts: service | |
gather_facts: no | |
tasks: | |
- name: installing python 2 | |
apt: | |
name: python | |
state: present | |
become: true | |
- name: Add Java repository | |
apt_repository: repo='ppa:webupd8team/java' state=present update_cache=yes | |
become: true | |
- name: Add license for java | |
debconf: name='oracle-java8-installer' question='shared/accepted-oracle-license-v1-1' value=true vtype=select | |
become: true | |
- name: Install java | |
apt: name={{item}} state=present | |
with_items: | |
- oracle-java8-installer | |
- oracle-java8-set-default | |
become: true | |
- name: copy jar file to vm | |
copy: | |
src: "/home/ubuntu/Scrumster/Alexa-service/ScrumsterService/target/ScrumsterService-1.0-SNAPSHOT.jar" | |
dest: "/home/ubuntu/ScrumsterService-1.0-SNAPSHOT.jar" | |
become: true | |
- name: copy sec file to vm | |
copy: | |
src: "/home/ubuntu/vagrant_data/client-secret.p12" | |
dest: "/opt/client-secret.p12" | |
become: true | |
- name: start the jar file as a nohup process | |
shell: nohup java -jar ScrumsterService-1.0-SNAPSHOT.jar & | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment