From ecf0527f97c395fdfc8d9f0a63360610c80daff6 Mon Sep 17 00:00:00 2001 From: Mark Goddard Date: Wed, 13 Dec 2017 12:13:47 +0000 Subject: [PATCH] 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. --- ansible/roles/ipa-images/tasks/main.yml | 18 ++++++++---------- .../ironic-inspector-rules/tasks/main.yml | 16 ++++++++-------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/ansible/roles/ipa-images/tasks/main.yml b/ansible/roles/ipa-images/tasks/main.yml index e2b58e24a..1d4aae95a 100644 --- a/ansible/roles/ipa-images/tasks/main.yml +++ b/ansible/roles/ipa-images/tasks/main.yml @@ -29,11 +29,11 @@ - "{{ ipa_images_ramdisk_name }}" register: ipa_images_checksum -# Note that setting this via a play or task variable seems to not -# evaluate the Jinja variable reference, so we use set_fact. -- name: Update the Ansible python interpreter fact to point to the virtualenv - set_fact: - ansible_python_interpreter: "{{ ipa_images_venv }}/bin/python" +- name: Activate the virtualenv + include_role: + name: activate-virtualenv + vars: + activate_virtualenv_path: "{{ ipa_images_venv }}" # 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). @@ -92,8 +92,6 @@ - name: "{{ ipa_images_ramdisk_name }}" format: ari -# This variable is unset before we set it, and it does not appear to be -# possible to unset a variable in Ansible. -- name: Set a fact to reset the Ansible python interpreter - set_fact: - ansible_python_interpreter: /usr/bin/python +- name: Deactivate the virtualenv + include_role: + name: deactivate-virtualenv diff --git a/ansible/roles/ironic-inspector-rules/tasks/main.yml b/ansible/roles/ironic-inspector-rules/tasks/main.yml index 38cd51bee..2ede1e114 100644 --- a/ansible/roles/ironic-inspector-rules/tasks/main.yml +++ b/ansible/roles/ironic-inspector-rules/tasks/main.yml @@ -8,9 +8,11 @@ with_items: - name: python-ironic-inspector-client -- name: Set a fact to ensure Ansible uses the python interpreter in the virtualenv - set_fact: - ansible_python_interpreter: "{{ ironic_inspector_venv }}/bin/python" +- name: Activate the virtualenv + include_role: + name: activate-virtualenv + vars: + activate_virtualenv_path: "{{ ironic_inspector_venv }}" - name: Ensure introspection rules exist os_ironic_inspector_rule: @@ -24,8 +26,6 @@ inspector_url: "{{ ironic_inspector_url }}" with_items: "{{ ironic_inspector_rules }}" -# This variable is unset before we set it, and it does not appear to be -# possible to unset a variable in Ansible. -- name: Set a fact to reset the Ansible python interpreter - set_fact: - ansible_python_interpreter: /usr/bin/python +- name: Deactivate the virtualenv + include_role: + name: deactivate-virtualenv