playbook.yml 2.78 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
    - name: install go packages
David Haynes's avatar
David Haynes committed
13 14 15
      apt:
        name: "{{ item }}"
        state: latest
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
      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
David Haynes's avatar
David Haynes committed
31 32 33 34 35 36 37
      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
38
        priv: "{{ mysql['db'] }}.*:ALL"
39 40

    - name: create mysql database
David Haynes's avatar
David Haynes committed
41 42 43 44 45
      mysql_db:
        name: "{{ mysql['db'] }}"
        state: present
        login_user: "{{ mysql['root_user'] }}"
        login_password: "{{ mysql['root_pass'] }}"
46

David Haynes's avatar
David Haynes committed
47
    - name: give mysql user access to test db
David Haynes's avatar
David Haynes committed
48 49 50 51 52 53 54 55
      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
56

57
    - name: install site packages to virtual env
David Haynes's avatar
David Haynes committed
58 59 60 61
      pip:
        requirements: "{{ django['requirements_path'] }}"
        virtualenv: "{{ django['venv_path'] }}"
        virtualenv_python: python2.7
62 63

    - name: install django settings.py
David Haynes's avatar
David Haynes committed
64 65 66 67
      template:
        src: templates/settings.py.j2
        dest: "{{ django['settings_path'] }}/settings.py"
        backup: yes
68 69

    - name: install django secret.py
David Haynes's avatar
David Haynes committed
70 71 72
      template:
        src: templates/secret.py.j2
        dest: "{{ django['settings_path'] }}/secret.py"
73 74

    - name: setup django database
David Haynes's avatar
David Haynes committed
75 76 77 78
      django_manage:
        command: "{{ item }}"
        app_path: "{{ django['app_path'] }}"
        virtualenv: "{{ django['venv_path'] }}"
79 80 81
      with_items:
        - flush
        - makemigrations
David Haynes's avatar
David Haynes committed
82
        - makemigrations go
83 84 85
        - migrate

    - name: create python superuser (defaults to dhaynes3)
David Haynes's avatar
David Haynes committed
86 87 88 89
      django_manage:
        command: "createsuperuser --noinput --username={{ django['superuser'] }} --email={{ django['superuser'] }}@masonlive.gmu.edu"
        app_path: "{{ django['app_path'] }}"
        virtualenv: "{{ django['venv_path'] }}"
90 91 92 93 94 95 96

    - 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;"