From 01c882d5856fda8d23d8e19720d4736e737d75e3 Mon Sep 17 00:00:00 2001 From: Ethan Paul <24588726+enpaul@users.noreply.github.com> Date: Sat, 21 Mar 2020 13:19:32 -0400 Subject: [PATCH] Bootstrap remove venv for running ansible from God pip is just the absolute goddamn worst holy shit It took me like two hours to dig myself out of the compatibility problems trying to install docker bindings to the system python gave me. This will teach me to never install anything to the system python ever again. God I hate pip --- playbooks/meta.yml | 64 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 58 insertions(+), 6 deletions(-) diff --git a/playbooks/meta.yml b/playbooks/meta.yml index 39970c1..2154bd7 100644 --- a/playbooks/meta.yml +++ b/playbooks/meta.yml @@ -1,4 +1,54 @@ --- +- name: Bootstrap remote ansible environment + hosts: all + gather_facts: false + become: true + tags: + - always + - meta + vars: + ansible_python_interpreter: /usr/bin/python3 + tasks: + - name: Clean bootstrap virtualenv + when: omni_force_reinstall is defined + file: + path: "{{ omni_ansible_venv }}" + state: absent + + - name: Create bootstrap virtualenv + command: + cmd: "{{ ansible_python_interpreter }} -m venv {{ omni_ansible_venv }} --system-site-packages" + creates: "{{ omni_ansible_venv }}/bin/python" + + - name: Generate remote requirements file locally + become: false + delegate_to: 127.0.0.1 + command: + cmd: poetry export --format requirements.txt + changed_when: false + register: _poetry_requirements + + - name: Copy remote requirements file + blockinfile: + path: "{{ omni_ansible_venv }}/req.txt" + create: true + block: "{{ _poetry_requirements.stdout_lines | join('\n') }}" + + - name: Install remote requirements + pip: + executable: "{{ omni_ansible_venv }}/bin/pip" + requirements: "{{ omni_ansible_venv }}/req.txt" + state: present + + - name: Assign ownership of the virtualenv to ansible + file: + path: "{{ omni_ansible_venv }}" + state: directory + owner: ansible + group: ansible + recurse: true + follow: false + - name: Check meta environment hosts: all tags: @@ -11,10 +61,12 @@ that: - omni_os.name == ansible_distribution | lower - omni_os.version_major == ansible_distribution_major_version - fail_msg: "Host does not meet required OS specified" - success_msg: "Required OS validation succeeded" + fail_msg: "Remote is running OS '{{ ansible_distribution }} {{ ansible_distribution_major_version }}', expected '{{ omni_os.name }} {{ omni_os.version_major }}'" + success_msg: "Remote is running expected OS '{{ ansible_distribution }} {{ ansible_distribution_major_version }}'" - - name: Enforce python interpreter - when: ansible_distribution != "CentOS" and ansible_distribution_major_version != "7" - set_fact: - ansible_python_interpreter: /usr/bin/python3 + - name: Check required interpreter settings + assert: + that: + - ansible_python_interpreter.startswith(omni_ansible_venv) is true + fail_msg: "Interpreter '{{ ansible_python_interpreter }}' is not in the expected venv '{{ omni_ansible_venv }}'" + success_msg: "Interpreter '{{ ansible_python_interpreter }}' is in the expected venv"