-
Notifications
You must be signed in to change notification settings - Fork 2
/
playbook.yml
97 lines (85 loc) · 2.53 KB
/
playbook.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
---
- name: Provision ec2 instance
hosts: localhost
connection: local
gather_facts: False
tasks:
- name: an ec2 security group
ec2_group:
name: sandbox1
description: sandbox1 ec2 security group
rules:
- { proto: "tcp", from_port: 80, to_port: 80, cidr_ip: "0.0.0.0/0" }
- { proto: "tcp", from_port: 22, to_port: 22, cidr_ip: "0.0.0.0/0" }
rules_egress:
- { proto: "all", cidr_ip: "0.0.0.0/0" }
- name: Launch instance
ec2:
instance_type: t1.micro
image: ami-cf7a12b8 # ubuntu 14.04 eu-west-1 64-bit ebs
wait: yes
key_name: sandbox1
group: sandbox1
instance_tags:
sandbox-ansible: true
Name: sandbox1
exact_count: 1
count_tag: sandbox-ansible
register: ec2_instance
- name: Add new instance to host group
add_host:
hostname: "{{ item.public_ip }}"
ansible_ssh_user: ubuntu
ansible_ssh_private_key_file: sandbox1.pem
groupname: launched
with_items: ec2_instance.tagged_instances
- name: Wait until SSH is available
local_action:
module: wait_for
host: "{{ item.public_ip }}"
port: 22
delay: 5
search_regex: OpenSSH
with_items: ec2_instance.tagged_instances
- name: Configure server
hosts: launched
vars:
repo_path: /home/ubuntu/voting/
project_path: /home/ubuntu/voting/voting/
tasks:
- name: global packages
apt: name={{item}} state=installed
with_items:
- python-virtualenv
- git
- uwsgi
- uwsgi-plugin-python
- nginx
sudo: yes
- name: python dependencies
pip: name=django version=1.6.6
sudo: yes
- template:
src=files/voting.conf.j2
dest=/etc/nginx/sites-enabled/default
owner=root
sudo: yes
notify: restart nginx
- name: application code
git: repo=https://[email protected]/gowtier/voting.git dest={{repo_path}}
- django_manage: command=collectstatic app_path={{ project_path }}
- django_manage: command=syncdb app_path={{ project_path }}
- name: uwsgi configuration
template:
src=files/voting.ini.j2
dest=/etc/uwsgi/apps-enabled/voting.ini
owner=root
notify: restart uwsgi
sudo: yes
handlers:
- name: restart uwsgi
service: name=uwsgi state=restarted
sudo: yes
- name: restart nginx
service: name=nginx state=restarted
sudo: yes