playbook.yml 2.5 KB
Newer Older
1
2
---
# Ansible Playbook for Go
David Haynes's avatar
David Haynes committed
3
#
4
5
6
7
8
9
10
# Installs a production-like envrionment with:
# - MySQL
# - nginx
# - uwsgi + Emperor
# - Django

- hosts: all
David Haynes's avatar
David Haynes committed
11
  tasks:
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
    - name: install go packages
      apt: name={{ item }} state=latest
      with_items:
        - python
        - python-dev
        - python-virtualenv
        - python-pip
        - git
        - libldap2-dev
        - mysql-server
        - mysql-client
        - libmysqlclient-dev
        - python-mysqldb
        - libsasl2-dev
        - libjpeg-dev

    - name: create mysql user
      mysql_user: >
David Haynes's avatar
David Haynes committed
30
31
32
33
34
35
36
        name={{ mysql['user'] }}
        password={{ mysql['pass'] }}
        login_password={{ mysql['root_pass'] }}
        login_user={{ mysql['root_user'] }}
        state=present
        host=localhost
        priv={{ mysql['db'] }}.*:ALL
37
38
39

    - name: create mysql database
      mysql_db: >
David Haynes's avatar
David Haynes committed
40
41
        name={{ mysql['db'] }}
        state=present
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
        login_user={{ mysql['root_user'] }}
        login_password={{ mysql['root_pass'] }}

    - name: install site packages to virtual env
      pip: >
        requirements={{ django['requirements_path'] }}
        virtualenv={{ django['venv_path'] }}
        virtualenv_python=python2.7

    - name: install django settings.py
      template: >
        src=templates/settings.py.j2
        dest={{ django['settings_path'] }}/settings.py
        backup=yes

    - name: install django secret.py
      template: >
        src=templates/secret.py.j2
        dest={{ django['settings_path'] }}/secret.py

62
    - name: refresh migrations
David Haynes's avatar
David Haynes committed
63
       file: path=/vagrant/go/go/migrations state=absent
64

65
66
67
68
69
70
71
72
    - name: setup django database
      django_manage: >
        command={{ item }}
        app_path={{ django['app_path'] }}
        virtualenv={{ django['venv_path'] }}
      with_items:
        - flush
        - makemigrations
David Haynes's avatar
David Haynes committed
73
        - makemigrations go
74
75
76
77
78
79
80
81
82
83
84
85
86
87
        - migrate

    - name: create python superuser (defaults to dhaynes3)
      django_manage: >
        command="createsuperuser --noinput --username={{ django['superuser'] }} --email={{ django['superuser'] }}@masonlive.gmu.edu"
        app_path={{ django['app_path'] }}
        virtualenv={{ django['venv_path'] }}

    - name: killing old screen sessions
      shell: screen -ls | grep -q django && screen -X -S django quit
      ignore_errors: true

    - name: start django runserver (access via localhost:8000)
      command: screen -dmS django bash -c "echo Starting on port {{ nginx['port'] }}; cd /vagrant/go; source ../venv/bin/activate; python manage.py runserver 0.0.0.0:8000;"