<commit_before>---
- name: Create DefectDojo directory
  file: path={{ dd_install_dir }} state=directory owner={{ dd_user }} group=www-data

- name: Download DefectDojo
  git: repo={{ dd_git_repo }} dest={{ dd_install_dir }} accept_hostkey=yes version=master force=yes recursive=no key_file=/home/{{ dd_user }}/.ssh/id_rsa

- name: Give ownership to dd_user
  file: path={{ dd_install_dir }} recurse=yes owner={{ dd_user }} group=www-data state=directory

- name: Check if gunicorn log file exists
  stat: path={{ gunicorn_log_file }}
  register: glf

- name: Create gunicorn log file
  file: path={{ gunicorn_log_file }} state=touch owner={{ dd_user }} group=www-data
  when: glf.stat.exists == False

- name: Generate Django secret
  shell: 'cat /dev/urandom | tr -dc "a-zA-Z0-9" | head -c 128'
  args:
    creates: '{{ dd_install_dir }}/dojo/settings.py'
  register: django_secret

- name: Populate DefectDojo settings file
  template: src=seddings.j2 dest={{ dd_install_dir }}/dojo/settings.py owner={{ dd_user }} group=www-data

- name: Install virtualenv
  pip: name=virtualenv

- name: Setup virtualenv
  shell: virtualenv {{ venv_dir }} creates={{ venv_dir }}/bin/activate
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install Django
  pip: name=Django version=1.7.7 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install MySQL-Python
  pip: name=MySQL-python virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install Pillow
  pip: name=Pillow version=2.3.0 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-secure
  pip: name=django-secure version=1.0 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-tastypie
  pip: name=django-tastypie version=0.11.1 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install gunicorn
  pip: name=gunicorn version=19.1.1 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install Python-nmap
  pip: name=python-nmap version=0.3.4 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install pytz
  pip: name=pytz version=2013.9 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install requests
  pip: name=requests version=2.2.1 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install wsgiref
  pip: name=wsgiref version=0.1.2 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-tastypie-swagger
  pip: name=-e git+git@github.com:concentricsky/django-tastypie-swagger.git@v0.1.3#egg=django-tastypie-swagger virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-filter
  pip: name=django-filter virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install supervisor
  pip: name=supervisor state=present virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install humanize
  pip: name=humanize state=present virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-bower
  pip: name=django-bower state=present virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-ez-pdf
  pip: name=django-easy-pdf state=present virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install xhtml2pdf
  pip: name=xhtml2pdf version=0.0.6 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install reportlab
  pip: name=reportlab version=2.7 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Run Django 'makemigrations' command
  django_manage: command=makemigrations app_path={{ dd_install_dir }} virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Run Django 'migrate' command
  django_manage: command=migrate app_path={{ dd_install_dir }} virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Create Django superuser
  shell: echo "from django.contrib.auth.models import User; User.objects.create_superuser('{{ dd_super_user }}', '{{ dd_super_user_email }}', '{{ dd_super_user_pass }}')" | {{ venv_dir }}/bin/python {{ dd_install_dir }}/manage.py shell && touch /home/{{ dd_user }}/.supercreated
  args:
    creates: /home/{{ dd_user }}/.supercreated
    sudo: yes
    sudo_user: '{{ dd_user }}'

- name: Run Django 'bower install' command
  django_manage: command=bower install app_path={{ dd_install_dir }} virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Run Django 'collectstatic' command
  django_manage: command=collectstatic app_path={{ dd_install_dir }} virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Find any running DD instances on our gunicorn port
  shell: "ps aux | grep '[r]unserver' | grep '{{ gunicorn_port }}' | awk '{print $2}'"
  register: instances
  ignore_errors: True

- name: Kill any DD instances on our gunicorn port
  shell: "kill {{ instances.stdout }}"
  when: instances.stdout
  ignore_errors: True

- name: Start DD
  shell: 'nohup {{ venv_dir }}/bin/python {{ dd_install_dir }}/manage.py runserver 0.0.0.0:{{ gunicorn_port }} >>{{ gunicorn_log_file }} 2>&1 &'
  sudo: yes
  sudo_user: '{{ dd_user }}'
<commit_msg>fixed typo, broken pip module, attempted fix of makemigrations<commit_after>---
- name: Create DefectDojo directory
  file: path={{ dd_install_dir }} state=directory owner={{ dd_user }} group=www-data

- name: Download DefectDojo
  git: repo={{ dd_git_repo }} dest={{ dd_install_dir }} accept_hostkey=yes version=master force=yes recursive=no key_file=/home/{{ dd_user }}/.ssh/id_rsa

- name: Give ownership to dd_user
  file: path={{ dd_install_dir }} recurse=yes owner={{ dd_user }} group=www-data state=directory

- name: Check if gunicorn log file exists
  stat: path={{ gunicorn_log_file }}
  register: glf

- name: Create gunicorn log file
  file: path={{ gunicorn_log_file }} state=touch owner={{ dd_user }} group=www-data
  when: glf.stat.exists == False

- name: Generate Django secret
  shell: 'cat /dev/urandom | tr -dc "a-zA-Z0-9" | head -c 128'
  args:
    creates: '{{ dd_install_dir }}/dojo/settings.py'
  register: django_secret

- name: Populate DefectDojo settings file
  template: src=settings.j2 dest={{ dd_install_dir }}/dojo/settings.py owner={{ dd_user }} group=www-data

- name: Install virtualenv
  pip: name=virtualenv

- name: Setup virtualenv
  shell: virtualenv {{ venv_dir }} creates={{ venv_dir }}/bin/activate
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install Django
  pip: name=Django version=1.7.7 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install MySQL-Python
  pip: name=MySQL-python virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install Pillow
  pip: name=Pillow version=2.3.0 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-secure
  pip: name=django-secure version=1.0 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-tastypie
  pip: name=django-tastypie version=0.11.1 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install gunicorn
  pip: name=gunicorn version=19.1.1 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install Python-nmap
  pip: name=python-nmap version=0.3.4 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install pytz
  pip: name=pytz version=2013.9 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install requests
  pip: name=requests version=2.2.1 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install wsgiref
  pip: name=wsgiref version=0.1.2 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-tastypie-swagger
  pip: name=django-tastypie-swagger virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-filter
  pip: name=django-filter virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install supervisor
  pip: name=supervisor state=present virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install humanize
  pip: name=humanize state=present virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-bower
  pip: name=django-bower state=present virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install django-ez-pdf
  pip: name=django-easy-pdf state=present virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install xhtml2pdf
  pip: name=xhtml2pdf version=0.0.6 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Install reportlab
  pip: name=reportlab version=2.7 virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Run Django 'makemigrations' command
  django_manage: command='makemigrations dojo' app_path={{ dd_install_dir }} virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Run Django 'migrate' command
  django_manage: command=migrate app_path={{ dd_install_dir }} virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Create Django superuser
  shell: echo "from django.contrib.auth.models import User; User.objects.create_superuser('{{ dd_super_user }}', '{{ dd_super_user_email }}', '{{ dd_super_user_pass }}')" | {{ venv_dir }}/bin/python {{ dd_install_dir }}/manage.py shell && touch /home/{{ dd_user }}/.supercreated
  args:
    creates: /home/{{ dd_user }}/.supercreated
    sudo: yes
    sudo_user: '{{ dd_user }}'

- name: Run Django 'bower install' command
  django_manage: command=bower install app_path={{ dd_install_dir }} virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Run Django 'collectstatic' command
  django_manage: command=collectstatic app_path={{ dd_install_dir }} virtualenv={{ venv_dir }}
  sudo: yes
  sudo_user: '{{ dd_user }}'

- name: Find any running DD instances on our gunicorn port
  shell: "ps aux | grep '[r]unserver' | grep '{{ gunicorn_port }}' | awk '{print $2}'"
  register: instances
  ignore_errors: True

- name: Kill any DD instances on our gunicorn port
  shell: "kill {{ instances.stdout }}"
  when: instances.stdout
  ignore_errors: True

- name: Start DD
  shell: 'nohup {{ venv_dir }}/bin/python {{ dd_install_dir }}/manage.py runserver 0.0.0.0:{{ gunicorn_port }} >>{{ gunicorn_log_file }} 2>&1 &'
  sudo: yes
  sudo_user: '{{ dd_user }}'

{'fraction_non_alphanumeric': 0.148769680399736, 'fraction_numerical': 0.00971056849250495, 'mean_word_length': 4.280238924838228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 0}, 'pii_count': 3, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4250579', 'n_tokens_mistral': 4084, 'n_tokens_neox': 3862, 'n_words': 974}