diff --git a/roles/wsgi_website/tasks/main.yml b/roles/wsgi_website/tasks/main.yml index 9de83d175682f4473b0714f8c19d3af789ec6ccf..8c341baa4533886154abf68e23be0f49084626ed 100644 --- a/roles/wsgi_website/tasks/main.yml +++ b/roles/wsgi_website/tasks/main.yml @@ -101,11 +101,24 @@ changed_when: false register: virtualenv_python_version -- name: Remove virtual environment if Python version does not match +- name: Retrieve virtual environment prompt + command: + argv: + - "bash" + - "-c" + - "source '{{ home }}/virtualenv/bin/activate'; printenv PS1" + failed_when: false + changed_when: false + register: current_virtualenv_prompt + +- name: Remove virtual environment in case of mismatches file: path: "{{ home }}/virtualenv" state: absent - when: "virtualenv_python_version.rc != 0 or virtualenv_python_version.stdout.strip() != python_interpreter_version.stdout.strip()" + when: | + virtualenv_python_version.rc != 0 or + virtualenv_python_version.stdout.strip() != python_interpreter_version.stdout.strip() or + current_virtualenv_prompt.stdout != "(" + fqdn + ") " notify: - Restart WSGI services @@ -118,7 +131,7 @@ mode: 02750 - name: Create Python virtual environment - command: '/usr/bin/virtualenv --python "{{ python_interpreter }}" --prompt "({{ fqdn }})" "{{ home }}/virtualenv"' + command: '/usr/bin/virtualenv --python "{{ python_interpreter }}" --prompt "{{ virtualenv_prompt }}" "{{ home }}/virtualenv"' args: creates: "{{ home }}/virtualenv/bin/{{ python_interpreter | basename }}" become: true