--- - hosts: servers vars_files: - vars.yml - secrets.yml gather_facts: true become: yes tasks: - name: Copy Apache-Pre config template: src: ../../ansible_templates/apache_site-pre.conf.j2 dest: /etc/apache2/sites-available/{{ project_name }}.conf - name: Clone/pull project repo git: repo: "{{ project_repo }}" dest: "{{ project_root }}/src/{{ project_name }}" accept_hostkey: yes become: yes become_user: "{{ user_username }}" notify: - restart apache - name: Install python packages pip: requirements: "{{ project_root }}/src/{{ project_name }}/requirements/production.txt" virtualenv: "{{ project_root }}/env" virtualenv_site_packages: yes become: yes become_user: "{{ user_username }}" notify: - restart apache - name: Copy secrets template: src: ../../ansible_templates/secrets.json.j2 dest: "{{ project_root }}/src/{{ project_name }}/{{ project_name }}/settings/secrets.json" notify: - restart apache - name: Django migrate django_manage: command: migrate app_path: "{{ project_root }}/src/{{ project_name }}" pythonpath: "{{ python_path }}" settings: "{{ django_settings }}" virtualenv: "{{ project_root }}/env/" become: yes become_user: "{{ user_username }}" - name: Django collectstatic django_manage: command: collectstatic app_path: "{{ project_root }}/src/{{ project_name }}" pythonpath: "{{ python_path }}" settings: "{{ django_settings }}" virtualenv: "{{ project_root }}/env/" become: yes become_user: "{{ user_username }}" - name: Copy apache config template: src: ../../ansible_templates/apache_site.conf.j2 dest: /etc/apache2/sites-available/{{ project_name }}.conf notify: - restart apache - name: Make sure Apache server is running and enabled to survive reboot service: name=apache2 state=started enabled=yes daemon_reload=yes - name: Make sure that Redis is running and is enabled to survive reboot service: name=redis-server state=started enabled=yes handlers: - name: restart apache service: name=apache2 state=restarted