|
| 1 | +--- |
| 2 | +# Deploys a Django app to Plesk |
| 3 | + |
| 4 | +- name: Set Python executable |
| 5 | + set_fact: python="`which python{{ conf.python_version | default('3.5') }}`" |
| 6 | + |
| 7 | +- name: Make virtualenv |
| 8 | + shell: "source ~/.bash_profile && mkvirtualenv {{ project }} --python={{ python }} --no-site-packages" |
| 9 | + args: |
| 10 | + executable: /bin/bash |
| 11 | + creates: "{{ virtualenv_dir }}/{{ project }}" |
| 12 | + register: mkvirtualenv |
| 13 | + failed_when: 'mkvirtualenv.changed and "New python executable" not in mkvirtualenv.stdout' |
| 14 | + |
| 15 | +- name: Configure Apache |
| 16 | + template: src="vhost.conf.j2" dest="/var/www/vhosts/{{ conf.domain_name }}/conf/vhost.conf" backup=yes |
| 17 | + become: true |
| 18 | + when: conf.domain_name is defined |
| 19 | + notify: |
| 20 | + - Reconfigure Plesk domain |
| 21 | + - Restart Apache |
| 22 | + |
| 23 | +- name: Configure New Relic |
| 24 | + template: src="newrelic.ini.j2" dest="{{ virtualenv_dir }}/{{ project }}.newrelic.ini" backup=yes |
| 25 | + when: newrelic is defined |
| 26 | + |
| 27 | +- name: Open ownership |
| 28 | + file: name="{{ conf.host_path }}" owner="{{ ansible_user_id }}" mode=0775 state=directory recurse=yes |
| 29 | + become: true |
| 30 | + |
| 31 | +- name: Sync files |
| 32 | + synchronize: |
| 33 | + src: "{{ conf.dev_path }}/" |
| 34 | + dest: "{{ conf.host_path }}" |
| 35 | + delete: yes |
| 36 | + rsync_opts: |
| 37 | + - "--exclude=.*" |
| 38 | + |
| 39 | +- name: Upgrade pip |
| 40 | + pip: |
| 41 | + name: "{{ item }}" |
| 42 | + state: latest |
| 43 | + virtualenv: "{{ virtualenv_dir }}/{{ project }}" |
| 44 | + executable: "{{ virtualenv_dir }}/{{ project }}/bin/pip" |
| 45 | + with_items: |
| 46 | + - pip |
| 47 | + - setuptools |
| 48 | + |
| 49 | +- name: Install pip requirements |
| 50 | + pip: |
| 51 | + requirements: "{{ conf.host_path }}/requirements.txt" |
| 52 | + virtualenv: "{{ virtualenv_dir }}/{{ project }}" |
| 53 | + executable: "{{ virtualenv_dir }}/{{ project }}/bin/pip" |
| 54 | + |
| 55 | +- name: Set Django admin executable |
| 56 | + set_fact: manage="{{ virtualenv_dir }}/{{ project }}/bin/python {{ conf.host_path }}/manage.py" |
| 57 | + |
| 58 | +- name: Set Django admin settings |
| 59 | + set_fact: settings="--settings={{ conf.name | default(project) }}.{{ django_settings }}" |
| 60 | + |
| 61 | +- name: Migrate |
| 62 | + shell: "{{ manage }} migrate {{ settings }}" |
| 63 | + register: migrate_result |
| 64 | + changed_when: '"No migrations to apply." not in migrate_result.stdout' |
| 65 | + |
| 66 | +- name: Load data |
| 67 | + shell: "{{ manage }} loaddata {{ item }} {{ settings }}" |
| 68 | + when: loaddata is defined and loaddata == 'true' |
| 69 | + with_items: conf.data |
| 70 | + register: loaddata_results |
| 71 | + failed_when: '"Installed" not in loaddata_results.stdout' |
| 72 | + |
| 73 | +- name: Collect static |
| 74 | + shell: "{{ manage }} collectstatic --noinput {{ settings }}" |
| 75 | + |
| 76 | +- name: Compile messages |
| 77 | + shell: "{{ manage }} compilemessages {{ settings }}" |
| 78 | + when: conf.compile_msgs is defined and conf.compile_msgs |
| 79 | + |
| 80 | +- name: Clear cache |
| 81 | + shell: "{{ manage }} cache_clear {{ settings }}" |
| 82 | + when: conf.memcached is defined and conf.memcached |
| 83 | + |
| 84 | +- name: Close ownership to Plesk account group |
| 85 | + file: |
| 86 | + name: "{{ conf.host_path }}" |
| 87 | + owner: "{{ conf.host_user }}" |
| 88 | + group: "{{ plesk_account_group }}" |
| 89 | + mode: 0775 |
| 90 | + state: directory |
| 91 | + recurse: yes |
| 92 | + become: true |
| 93 | + |
| 94 | +- name: Close ownership to Plesk server group |
| 95 | + file: |
| 96 | + name: "{{ conf.host_path }}" |
| 97 | + owner: "{{ conf.host_user }}" |
| 98 | + group: "{{ plesk_server_group }}" |
| 99 | + state: directory |
| 100 | + become: true |
0 commit comments