Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Specific Versions of Packages from pip freeze in venv #13

Open
jandiorio opened this issue May 31, 2022 · 1 comment
Open

Allow Specific Versions of Packages from pip freeze in venv #13

jandiorio opened this issue May 31, 2022 · 1 comment

Comments

@jandiorio
Copy link

The current solution compares the package names in the venv to the base image only resulting in the derived image losing the version specified in the venv.

The assumption is that most packages with specific versions required are packages in addition to what's installed by the base Ansible requirements in support of other modules, roles, and collections.

  1. Gather pip freeze from the base image and each venv
  2. Split the output on == in each line and build a new dictionary
  3. Loop over venv keys (package name)
  4. If venv package name is not in base package keys() add to new var (packages_to_install)

Essentially, perform the comparison at a name level, but install a specific version if the package doesn't exist in the base already.

Sample Solution Code

    
    - name: VENV PACKAGES AND VERSIONS SPLIT
      ansible.builtin.set_fact:
        venv_package_details: "{{ venv_package_details | default({}) | combine({item.split('==')[0]: item.split('==')[1]}) }}"
      loop: "{{ venv_packages }}"

    - name: BASE PACKAGES AND VERSIONS SPLIT
      ansible.builtin.set_fact:
        base_package_details: "{{ base_package_details | default({}) | combine({item.split('==')[0]: item.split('==')[1]}) }}"
      loop: "{{ base_packages }}"

    - name: CREATE NEW WITH VERSION
      ansible.builtin.set_fact:
        packages_to_install: "{{ packages_to_install | default([]) + [item.key + '==' + item.value] }}"
      loop: "{{ venv_package_details | dict2items }}"
      when:
        - item.key not in base_package_details.keys()
        - not item.key is search('ansible')

...working on integrating similar code into the existing role and PR...

@sean-m-sullivan
Copy link
Contributor

I've made some changes to the role, but this would still be useful, Even a partial solution WIP and we can likely figure out a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants