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
This commit is contained in:
parent
306eda9c3c
commit
01c882d585
@ -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"
|
||||
|
Reference in New Issue
Block a user