Use (de)activate-virtualenv role to activate virtualenvs

These roles ensure that the previous value of ansible_python_interpreter is
restored when the virtualenv is deactivated.
This commit is contained in:
Mark Goddard 2017-12-13 12:13:47 +00:00
parent 3620be7c08
commit ecf0527f97
2 changed files with 16 additions and 18 deletions

View File

@ -29,11 +29,11 @@
- "{{ ipa_images_ramdisk_name }}" - "{{ ipa_images_ramdisk_name }}"
register: ipa_images_checksum register: ipa_images_checksum
# Note that setting this via a play or task variable seems to not - name: Activate the virtualenv
# evaluate the Jinja variable reference, so we use set_fact. include_role:
- name: Update the Ansible python interpreter fact to point to the virtualenv name: activate-virtualenv
set_fact: vars:
ansible_python_interpreter: "{{ ipa_images_venv }}/bin/python" activate_virtualenv_path: "{{ ipa_images_venv }}"
# To support updating the IPA image, we check the MD5 sum of the cached image # To support updating the IPA image, we check the MD5 sum of the cached image
# files, and compare with the images in Glance (if there are any). # files, and compare with the images in Glance (if there are any).
@ -92,8 +92,6 @@
- name: "{{ ipa_images_ramdisk_name }}" - name: "{{ ipa_images_ramdisk_name }}"
format: ari format: ari
# This variable is unset before we set it, and it does not appear to be - name: Deactivate the virtualenv
# possible to unset a variable in Ansible. include_role:
- name: Set a fact to reset the Ansible python interpreter name: deactivate-virtualenv
set_fact:
ansible_python_interpreter: /usr/bin/python

View File

@ -8,9 +8,11 @@
with_items: with_items:
- name: python-ironic-inspector-client - name: python-ironic-inspector-client
- name: Set a fact to ensure Ansible uses the python interpreter in the virtualenv - name: Activate the virtualenv
set_fact: include_role:
ansible_python_interpreter: "{{ ironic_inspector_venv }}/bin/python" name: activate-virtualenv
vars:
activate_virtualenv_path: "{{ ironic_inspector_venv }}"
- name: Ensure introspection rules exist - name: Ensure introspection rules exist
os_ironic_inspector_rule: os_ironic_inspector_rule:
@ -24,8 +26,6 @@
inspector_url: "{{ ironic_inspector_url }}" inspector_url: "{{ ironic_inspector_url }}"
with_items: "{{ ironic_inspector_rules }}" with_items: "{{ ironic_inspector_rules }}"
# This variable is unset before we set it, and it does not appear to be - name: Deactivate the virtualenv
# possible to unset a variable in Ansible. include_role:
- name: Set a fact to reset the Ansible python interpreter name: deactivate-virtualenv
set_fact:
ansible_python_interpreter: /usr/bin/python