Skip to content

Commit 4eaf110

Browse files
committed
Initial ansible playbook.
Uses Python 2 for now. Python 3 supported via an Ansible variable. (See README for details)
1 parent ab8d34e commit 4eaf110

File tree

17 files changed

+147
-21
lines changed

17 files changed

+147
-21
lines changed

README.markdown

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ Files for the PythonKC.com website.
44

55
## Development Quickstart Option 1 (vagrant)
66

7+
First, copy `pythonkc_site/.env.example` to `pythonkc_site/.env` and add
8+
your own [meetup api key][] and a unique [django secret key][] (`.env` will
9+
be ignored by git)
10+
11+
Then you have to install some vagrant plugins and build your vagrant box:
12+
713
```
814
vagrant plugin install vagrant-hostmanager
915
vagrant plugin install vagrant-hostsupdater
@@ -23,6 +29,25 @@ cd ~/vagrant/ansible
2329
ansible-playbook vagrant.yml
2430
```
2531

32+
To run the Django development server:
33+
34+
```
35+
vagrant ssh
36+
django-admin runserver 192.168.100.101:8000
37+
```
38+
39+
Now go to `http://192.168.100.101:8000` in your browser. You can edit the files
40+
on your local machine and the server should reload automatically.
41+
42+
For now, this is a Python 2 project. If you want to start using Python 3
43+
and help us fix our problems, set Ansible's `python_version` variable to 3
44+
and it will build the virtualenv using Python 3:
45+
46+
```
47+
ansible-playbook vagrant.yml -e python_version=3
48+
```
49+
50+
2651
## Development Quickstart Option 2 (virtualenv)
2752

2853
```
@@ -38,3 +63,8 @@ Profit! $$$
3863
## More Detailed Instructions
3964

4065
See: docs/local_development
66+
67+
68+
69+
[meetup api key]: https://secure.meetup.com/meetup_api/key/
70+
[django secret key]: http://www.miniwebtool.com/django-secret-key-generator/

ansible/group_vars/all.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
example: true # TODO, put any common variables in here
2+
virtualenv: ~/virtualenvs/pythonkc

ansible/group_vars/production.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
---
22
user: pythonkc
3+
pythonpath: /TODO
4+
project_root: /TODO/pythonkc_site

ansible/group_vars/vagrant.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
---
22
user: vagrant
3+
pythonpath: /home/vagrant/vagrant
4+
project_root: /home/vagrant/vagrant/pythonkc_site
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
python_version: 2
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
- name: Create virtualenvs directory
3+
file: dest=~/virtualenvs state=directory owner={{ user }} group={{ user }}
4+
5+
6+
- name: Install requirements into Python 2.7 virtualenv
7+
pip:
8+
requirements: "{{ project_root }}/requirements/project.txt"
9+
virtualenv: "{{ virtualenv }}"
10+
virtualenv_command: /usr/bin/virtualenv -p python2.7
11+
when: python_version == 2
12+
13+
14+
- name: Install requirements into Python 3 virtualenv
15+
pip:
16+
requirements: "{{ project_root }}/requirements/project.txt"
17+
virtualenv: "{{ virtualenv }}"
18+
virtualenv_command: python3 /usr/lib/python3/dist-packages/virtualenv.py -p python3
19+
when: python_version == 3
20+
21+
22+
- name: Set some env vars when activating virtualenv
23+
lineinfile:
24+
dest: "{{ virtualenv }}/bin/activate"
25+
regexp: "^export {{ item.name }}="
26+
line: "export {{ item.name }}={{ item.value }}"
27+
state: present
28+
insertafter: EOF
29+
with_items:
30+
- {name: DJANGO_SETTINGS_MODULE, value: pythonkc_site.settings}
31+
- {name: PYTHONPATH, value: "{{ pythonpath }}"}
32+
33+
34+
- name: Automatically activate the virtualenv in bashrc
35+
lineinfile:
36+
dest: ~/.bashrc
37+
line: "source {{ virtualenv }}/bin/activate"
38+
state: present
39+
insertafter: EOF
40+
41+
42+
- name: Run migrations
43+
django_manage:
44+
command: migrate
45+
app_path: "{{ project_root }}"
46+
pythonpath: "{{ pythonpath }}"
47+
virtualenv: "{{ virtualenv }}"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
- {include: python2.yml, tags: python, when: python_version == 2}
3+
- {include: python3.yml, tags: python, when: python_version == 3}
4+
- include: tools.yml tags=tools
5+
- include: django.yml tags=django
6+
7+
# TODO
8+
# vim + vim configuration for python?
9+
# postgres? (for now just using sqlite for development)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
- name: Update apt
3+
apt: update_cache=yes cache_valid_time=3600
4+
become: yes
5+
tags: apt
6+
7+
- name: Install some base packages
8+
apt: pkg="{{item}}" state=latest
9+
become: yes
10+
tags: apt
11+
with_items:
12+
- build-essential
13+
- libpq-dev
14+
- python-dev
15+
- python-pip
16+
- python-software-properties
17+
- python-virtualenv
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
---
22
- name: Update apt
33
apt: update_cache=yes cache_valid_time=3600
4+
become: yes
45
tags: apt
56

67
- name: Install some base packages
78
apt: pkg="{{item}}" state=latest
9+
become: yes
810
tags: apt
911
with_items:
1012
- build-essential
13+
- libpq-dev
1114
- python3
1215
- python3-dev
1316
- python3-pip
1417
- python3-software-properties
15-
- vim-nox
16-
- htop
17-
18-
# What else should go in here?
19-
# vim + vim configuration for python?
18+
- python3-virtualenv
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
- name: Update apt
3+
apt: update_cache=yes cache_valid_time=3600
4+
become: yes
5+
tags: apt
6+
7+
8+
- name: Install some dev tools packages
9+
apt: pkg="{{item}}" state=latest
10+
become: yes
11+
tags: apt
12+
with_items:
13+
- vim-nox
14+
- htop
15+
16+
# TODO basic vimrc with python plugins?

0 commit comments

Comments
 (0)