--- # Ansible Playbook for Go # # Installs a production-like envrionment with: # - MySQL # - nginx # - uwsgi + Emperor # - Django - hosts: all 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: "" tasks: - name: Install Python 3.4.3 and related packages apt: name: "{{ item }}" update_cache: yes state: present with_items: - python3 - python3-dev - python3-pip - git - name: Move pip command: mv /usr/bin/pip3 /usr/bin/pip ignore_errors: true - name: Install virtualenv pip: name: virtualenv - name: Create the virtualenv command: virtualenv -p python3 /vagrant/venv ignore_errors: true - name: Install go packages apt: name: "{{ item }}" state: latest update_cache: yes with_items: - mysql-server - mysql-client - libmysqlclient-dev - python-mysqldb - name: install site packages to virtual env pip: requirements: "{{ django['requirements_path'] }}" virtualenv: "{{ django['venv_path'] }}" virtualenv_python: /usr/bin/python3 - name: create mysql user mysql_user: name: "{{ mysql['user'] }}" password: "{{ mysql['pass'] }}" login_password: "{{ mysql['root_pass'] }}" login_user: "{{ mysql['root_user'] }}" state: present host: localhost priv: "{{ mysql['db'] }}.*:ALL" - name: create mysql database mysql_db: name: "{{ mysql['db'] }}" state: present login_user: "{{ mysql['root_user'] }}" login_password: "{{ mysql['root_pass'] }}" - name: give mysql user access to test db 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 - name: setup django database django_manage: command: "{{ item }}" app_path: "{{ django['app_path'] }}" virtualenv: "{{ django['venv_path'] }}" with_items: - flush - makemigrations - makemigrations go - 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: install env variable convenience script template: src: templates/sourceme.j2 dest: "{{ django['sourceme_dest'] }}/sourceme.sh" backup: yes - 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; python3 manage.py runserver 0.0.0.0:8000;"