From eed2a8a111b13fa2ef7ebd720757036eb4485506 Mon Sep 17 00:00:00 2001 From: Benjamin Bernard Date: Fri, 9 Feb 2024 10:08:20 +0100 Subject: [PATCH 1/2] enh: Add tasks to pin and install pip packages already in requirement --- tasks/deploy_netbox.yml | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/tasks/deploy_netbox.yml b/tasks/deploy_netbox.yml index 3c95501..3d0e5a5 100644 --- a/tasks/deploy_netbox.yml +++ b/tasks/deploy_netbox.yml @@ -20,13 +20,6 @@ when: - _netbox_config.SECRET_KEY is not defined -- name: Drop pip constraints file - template: - src: pip_constraints.j2 - dest: "{{ netbox_current_path }}/constraints.txt" - owner: "{{ netbox_user }}" - group: "{{ netbox_group }}" - - name: Create NetBox virtualenv pip: name: @@ -41,10 +34,35 @@ register: _netbox_virtualenv_setup until: _netbox_virtualenv_setup is succeeded +- name: Create constraints files + ansible.builtin.template: + src: pip_constraints.j2 + dest: "{{ netbox_shared_path }}/constraints.txt" + owner: "{{ netbox_user }}" + group: "{{ netbox_group }}" + +- name: Copy requirements.txt from netbox current path to shared path + ansible.builtin.copy: + src: "{{ netbox_current_path }}/requirements.txt" + dest: "{{ netbox_shared_path }}/requirements.txt" + owner: "{{ netbox_user }}" + group: "{{ netbox_group }}" + remote_src: true + changed_when: false + +- name: Edit requirements.txt in netbox shared path + ansible.builtin.replace: + path: "{{ netbox_shared_path }}/requirements.txt" + regexp: '^({{ item | regex_replace("([<>=!~].*)", "") }})[<>=!~].*' + replace: '\1' + loop: "{{ netbox_pip_constraints }}" + changed_when: false + when: "'[<>=!~]' in item" + - name: Install needed Python dependencies - pip: - requirements: "{{ netbox_current_path }}/requirements.txt" - extra_args: "-c {{ netbox_current_path }}/constraints.txt" + ansible.builtin.pip: + requirements: "{{ netbox_shared_path }}/requirements.txt" + extra_args: "-c {{ netbox_shared_path }}/constraints.txt" virtualenv: "{{ netbox_virtualenv_path }}" become: true become_user: "{{ netbox_user }}" @@ -53,7 +71,7 @@ until: _netbox_virtualenv_setup is succeeded - name: Install selected optional Python dependencies - pip: + ansible.builtin.pip: name: "{{ item }}" state: present virtualenv: "{{ netbox_virtualenv_path }}" From 9f0aed9af6e5b151e0decfdfce8e0f34192d5f09 Mon Sep 17 00:00:00 2001 From: Musee Ullah Date: Fri, 1 Mar 2024 06:04:22 +0900 Subject: [PATCH 2/2] Limit package overwrites to constraints that specify exact versions --- tasks/deploy_netbox.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tasks/deploy_netbox.yml b/tasks/deploy_netbox.yml index 3d0e5a5..cf4baa2 100644 --- a/tasks/deploy_netbox.yml +++ b/tasks/deploy_netbox.yml @@ -50,14 +50,14 @@ remote_src: true changed_when: false -- name: Edit requirements.txt in netbox shared path - ansible.builtin.replace: - path: "{{ netbox_shared_path }}/requirements.txt" - regexp: '^({{ item | regex_replace("([<>=!~].*)", "") }})[<>=!~].*' - replace: '\1' +- name: Override exact version requirements in shared path's requirements.txt if conflicting constraint is specified + ansible.builtin.replace: + path: "{{ netbox_shared_path }}/requirements.txt" + regexp: '^({{ item | regex_replace("(==.*)", "") }})==.*' + replace: '\1' loop: "{{ netbox_pip_constraints }}" changed_when: false - when: "'[<>=!~]' in item" + when: "'==' in item" - name: Install needed Python dependencies ansible.builtin.pip: