playbook.yml 3.53 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
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
  environment:
    GO_SECRET_KEY: "{{ django['secret_key'] }}"
    GO_ALLOWED_HOSTS: "{{ django['host'] }}"
    GO_EMAIL_DOMAIN: "{{ django['email_domain'] }}"
    GO_CAS_URL: "{{ django['cas_url'] }}"
    GO_DB_NAME: "{{ mysql['db'] }}"
    GO_DB_USER: "{{ mysql['user'] }}"
    GO_DB_PASSWORD: "{{ mysql['pass'] }}"
    GO_DB_HOST: localhost
    GO_DB_PORT: 3306
    GO_EMAIL_HOST: ""
    GO_EMAIL_PORT: ""
    GO_EMAIL_HOST_USER: ""
    GO_EMAIL_HOST_PASSWORD: ""
    GO_EMAIL_FROM: ""
    GO_EMAIL_TO: ""

David Haynes's avatar
David Haynes committed
28
  tasks:
29
    - name: Install Python 3.4.3 and related packages
30
31
32
33
34
35
36
37
      apt:
          name: "{{ item }}"
          update_cache: yes
          state: present
      with_items:
          - python3
          - python3-dev
          - python3-pip
38
          - git
39

40
41
42
    - name: Move pip
      command: mv /usr/bin/pip3 /usr/bin/pip
      ignore_errors: true
43
44
45
46
47
48
49

    - name: Install virtualenv
      pip:
        name: virtualenv

    - name: Create the virtualenv
      command: virtualenv -p python3 /vagrant/venv
50
      ignore_errors: true
51
52

    - name: Install go packages
David Haynes's avatar
David Haynes committed
53
54
55
      apt:
        name: "{{ item }}"
        state: latest
56
        update_cache: yes
57
58
59
60
61
62
      with_items:
        - mysql-server
        - mysql-client
        - libmysqlclient-dev
        - python-mysqldb

63
64
65
66
67
68
    - name: install site packages to virtual env
      pip:
        requirements: "{{ django['requirements_path'] }}"
        virtualenv: "{{ django['venv_path'] }}"
        virtualenv_python: /usr/bin/python3

69
    - name: create mysql user
David Haynes's avatar
David Haynes committed
70
71
72
73
74
75
76
      mysql_user:
        name: "{{ mysql['user'] }}"
        password: "{{ mysql['pass'] }}"
        login_password: "{{ mysql['root_pass'] }}"
        login_user: "{{ mysql['root_user'] }}"
        state: present
        host: localhost
David Haynes's avatar
David Haynes committed
77
        priv: "{{ mysql['db'] }}.*:ALL"
78
79

    - name: create mysql database
David Haynes's avatar
David Haynes committed
80
81
82
83
84
      mysql_db:
        name: "{{ mysql['db'] }}"
        state: present
        login_user: "{{ mysql['root_user'] }}"
        login_password: "{{ mysql['root_pass'] }}"
85

David Haynes's avatar
David Haynes committed
86
    - name: give mysql user access to test db
David Haynes's avatar
David Haynes committed
87
88
89
90
91
92
93
94
      mysql_user:
        name: "{{ mysql['user'] }}"
        login_password: "{{ mysql['root_pass'] }}"
        login_user: "{{ mysql['root_user'] }}"
        state: present
        host: localhost
        priv: test_{{ mysql['db'] }}.*:ALL
        append_privs: yes
David Haynes's avatar
David Haynes committed
95

96
    - name: setup django database
David Haynes's avatar
David Haynes committed
97
98
99
100
      django_manage:
        command: "{{ item }}"
        app_path: "{{ django['app_path'] }}"
        virtualenv: "{{ django['venv_path'] }}"
101
102
103
      with_items:
        - flush
        - makemigrations
David Haynes's avatar
David Haynes committed
104
        - makemigrations go
105
106
107
        - migrate

    - name: create python superuser (defaults to dhaynes3)
David Haynes's avatar
David Haynes committed
108
109
110
111
      django_manage:
        command: "createsuperuser --noinput --username={{ django['superuser'] }} --email={{ django['superuser'] }}@masonlive.gmu.edu"
        app_path: "{{ django['app_path'] }}"
        virtualenv: "{{ django['venv_path'] }}"
112
113
114
115
116

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

117
118
119
120
121
122
    - name: install env variable convenience script
      template:
        src: templates/sourceme.j2
        dest: "{{ django['sourceme_dest'] }}/sourceme.sh"
        backup: yes

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