├── .ansible-lint ├── .github ├── FUNDING.yml └── workflows │ ├── ci.yml │ ├── release.yml │ └── stale.yml ├── .gitignore ├── .yamllint ├── LICENSE ├── README.md ├── defaults └── main.yml ├── meta └── main.yml ├── molecule └── default │ ├── converge.yml │ └── molecule.yml └── tasks └── main.yml /.ansible-lint: -------------------------------------------------------------------------------- 1 | skip_list: 2 | - 'yaml' 3 | - 'role-name' 4 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | --- 3 | github: geerlingguy 4 | patreon: geerlingguy 5 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: CI 3 | 'on': 4 | pull_request: 5 | push: 6 | branches: 7 | - master 8 | schedule: 9 | - cron: "0 4 * * 5" 10 | 11 | defaults: 12 | run: 13 | working-directory: 'geerlingguy.pip' 14 | 15 | jobs: 16 | 17 | lint: 18 | name: Lint 19 | runs-on: ubuntu-latest 20 | steps: 21 | - name: Check out the codebase. 22 | uses: actions/checkout@v3 23 | with: 24 | path: 'geerlingguy.pip' 25 | 26 | - name: Set up Python 3. 27 | uses: actions/setup-python@v4 28 | with: 29 | python-version: '3.x' 30 | 31 | - name: Install test dependencies. 32 | run: pip3 install yamllint 33 | 34 | - name: Lint code. 35 | run: | 36 | yamllint . 37 | 38 | molecule: 39 | name: Molecule 40 | runs-on: ubuntu-latest 41 | strategy: 42 | matrix: 43 | distro: 44 | - rockylinux9 45 | - fedora39 46 | - ubuntu2204 47 | - ubuntu2004 48 | - debian12 49 | - debian11 50 | 51 | steps: 52 | - name: Check out the codebase. 53 | uses: actions/checkout@v3 54 | with: 55 | path: 'geerlingguy.pip' 56 | 57 | - name: Set up Python 3. 58 | uses: actions/setup-python@v4 59 | with: 60 | python-version: '3.x' 61 | 62 | - name: Install test dependencies. 63 | run: pip3 install ansible molecule molecule-plugins[docker] docker 64 | 65 | - name: Run Molecule tests. 66 | run: molecule test 67 | env: 68 | PY_COLORS: '1' 69 | ANSIBLE_FORCE_COLOR: '1' 70 | MOLECULE_DISTRO: ${{ matrix.distro }} 71 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # This workflow requires a GALAXY_API_KEY secret present in the GitHub 3 | # repository or organization. 4 | # 5 | # See: https://github.com/marketplace/actions/publish-ansible-role-to-galaxy 6 | # See: https://github.com/ansible/galaxy/issues/46 7 | 8 | name: Release 9 | 'on': 10 | push: 11 | tags: 12 | - '*' 13 | 14 | defaults: 15 | run: 16 | working-directory: 'geerlingguy.pip' 17 | 18 | jobs: 19 | 20 | release: 21 | name: Release 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Check out the codebase. 25 | uses: actions/checkout@v4 26 | with: 27 | path: 'geerlingguy.pip' 28 | 29 | - name: Set up Python 3. 30 | uses: actions/setup-python@v5 31 | with: 32 | python-version: '3.x' 33 | 34 | - name: Install Ansible. 35 | run: pip3 install ansible-core 36 | 37 | - name: Trigger a new import on Galaxy. 38 | run: >- 39 | ansible-galaxy role import --api-key ${{ secrets.GALAXY_API_KEY }} 40 | $(echo ${{ github.repository }} | cut -d/ -f1) $(echo ${{ github.repository }} | cut -d/ -f2) 41 | -------------------------------------------------------------------------------- /.github/workflows/stale.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Close inactive issues 3 | 'on': 4 | schedule: 5 | - cron: "55 21 * * 5" # semi-random time 6 | 7 | jobs: 8 | close-issues: 9 | runs-on: ubuntu-latest 10 | permissions: 11 | issues: write 12 | pull-requests: write 13 | steps: 14 | - uses: actions/stale@v8 15 | with: 16 | days-before-stale: 120 17 | days-before-close: 60 18 | exempt-issue-labels: bug,pinned,security,planned 19 | exempt-pr-labels: bug,pinned,security,planned 20 | stale-issue-label: "stale" 21 | stale-pr-label: "stale" 22 | stale-issue-message: | 23 | This issue has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 24 | 25 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 26 | close-issue-message: | 27 | This issue has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 28 | stale-pr-message: | 29 | This pr has been marked 'stale' due to lack of recent activity. If there is no further activity, the issue will be closed in another 30 days. Thank you for your contribution! 30 | 31 | Please read [this blog post](https://www.jeffgeerling.com/blog/2020/enabling-stale-issue-bot-on-my-github-repositories) to see the reasons why I mark issues as stale. 32 | close-pr-message: | 33 | This pr has been closed due to inactivity. If you feel this is in error, please reopen the issue or file a new issue with the relevant details. 34 | repo-token: ${{ secrets.GITHUB_TOKEN }} 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.retry 2 | */__pycache__ 3 | *.pyc 4 | .cache 5 | 6 | -------------------------------------------------------------------------------- /.yamllint: -------------------------------------------------------------------------------- 1 | --- 2 | extends: default 3 | 4 | rules: 5 | line-length: 6 | max: 120 7 | level: warning 8 | 9 | ignore: | 10 | .github/workflows/stale.yml 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 Jeff Geerling 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Ansible Role: Pip (for Python) 2 | 3 | [![CI](https://github.com/geerlingguy/ansible-role-pip/actions/workflows/ci.yml/badge.svg)](https://github.com/geerlingguy/ansible-role-pip/actions/workflows/ci.yml) 4 | 5 | An Ansible Role that installs [Pip](https://pip.pypa.io) on Linux. 6 | 7 | ## Requirements 8 | 9 | On RedHat/CentOS, you may need to have EPEL installed before running this role. You can use the `geerlingguy.repo-epel` role if you need a simple way to ensure it's installed. 10 | 11 | ## Role Variables 12 | 13 | Available variables are listed below, along with default values (see `defaults/main.yml`): 14 | 15 | pip_package: python3-pip 16 | 17 | The name of the package to install to get `pip` on the system. For older systems that don't have Python 3 available, you can set this to `python-pip`. 18 | 19 | pip_executable: pip3 20 | 21 | The role will try to autodetect the pip executable based on the `pip_package` (e.g. `pip` for Python 2 and `pip3` for Python 3). You can also override this explicitly, e.g. `pip_executable: pip3.6`. 22 | 23 | pip_install_packages: [] 24 | 25 | A list of packages to install with pip. Examples below: 26 | 27 | pip_install_packages: 28 | # Specify names and versions. 29 | - name: docker 30 | version: "1.2.3" 31 | - name: awscli 32 | version: "1.11.91" 33 | 34 | # Or specify bare packages to get the latest release. 35 | - docker 36 | - awscli 37 | 38 | # Or uninstall a package. 39 | - name: docker 40 | state: absent 41 | 42 | # Or update a package to the latest version. 43 | - name: docker 44 | state: latest 45 | 46 | # Or force a reinstall. 47 | - name: docker 48 | state: forcereinstall 49 | 50 | # Or install a package in a particular virtualenv. 51 | - name: docker 52 | virtualenv: /my_app/venv 53 | 54 | # Or pass through any extra arguments. 55 | - name: my_special_package_from_my_special_repo 56 | extra_args: --extra-index-url https://my-domain/pypi/pypi-master/simple 57 | 58 | ## Dependencies 59 | 60 | None. 61 | 62 | ## Example Playbook 63 | 64 | - hosts: all 65 | 66 | vars: 67 | pip_install_packages: 68 | - name: docker 69 | - name: awscli 70 | 71 | roles: 72 | - geerlingguy.pip 73 | 74 | ## License 75 | 76 | MIT / BSD 77 | 78 | ## Author Information 79 | 80 | This role was created in 2017 by [Jeff Geerling](https://www.jeffgeerling.com/), author of [Ansible for DevOps](https://www.ansiblefordevops.com/). 81 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # For Python 3, use python3-pip. 3 | pip_package: python3-pip 4 | pip_executable: "{{ 'pip3' if pip_package.startswith('python3') else 'pip' }}" 5 | 6 | pip_install_packages: [] 7 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | dependencies: [] 3 | 4 | galaxy_info: 5 | role_name: pip 6 | author: geerlingguy 7 | description: Pip (Python package manager) for Linux. 8 | issue_tracker_url: https://github.com/geerlingguy/ansible-role-pip/issues 9 | company: "Midwestern Mac, LLC" 10 | license: "MIT" 11 | min_ansible_version: 2.10 12 | platforms: 13 | - name: Fedora 14 | versions: 15 | - all 16 | - name: Debian 17 | versions: 18 | - all 19 | - name: Ubuntu 20 | versions: 21 | - all 22 | galaxy_tags: 23 | - system 24 | - server 25 | - packaging 26 | - python 27 | - pip 28 | - tools 29 | -------------------------------------------------------------------------------- /molecule/default/converge.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Converge 3 | hosts: all 4 | #become: true 5 | 6 | vars: 7 | pip_install_packages: 8 | # Test installing a specific version of a package. 9 | - name: ipaddress 10 | version: "1.0.18" 11 | # Test installing a package by name. 12 | - colorama 13 | 14 | pre_tasks: 15 | - name: Update apt cache. 16 | apt: update_cache=true cache_valid_time=600 17 | when: ansible_os_family == 'Debian' 18 | 19 | - name: Set package name for older OSes. 20 | set_fact: 21 | pip_package: python-pip 22 | when: > 23 | (ansible_os_family == 'RedHat') and (ansible_distribution_major_version | int < 8) 24 | or (ansible_distribution == 'Debian') and (ansible_distribution_major_version | int < 10) 25 | or (ansible_distribution == 'Ubuntu') and (ansible_distribution_major_version | int < 18) 26 | 27 | roles: 28 | - role: geerlingguy.pip 29 | -------------------------------------------------------------------------------- /molecule/default/molecule.yml: -------------------------------------------------------------------------------- 1 | --- 2 | role_name_check: 1 3 | dependency: 4 | name: galaxy 5 | options: 6 | ignore-errors: true 7 | driver: 8 | name: docker 9 | platforms: 10 | - name: instance 11 | image: "geerlingguy/docker-${MOLECULE_DISTRO:-rockylinux9}-ansible:latest" 12 | command: ${MOLECULE_DOCKER_COMMAND:-""} 13 | volumes: 14 | - /sys/fs/cgroup:/sys/fs/cgroup:rw 15 | cgroupns_mode: host 16 | privileged: true 17 | pre_build_image: true 18 | provisioner: 19 | name: ansible 20 | playbooks: 21 | converge: ${MOLECULE_PLAYBOOK:-converge.yml} 22 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Ensure Pip is installed. 3 | package: 4 | name: "{{ pip_package }}" 5 | state: present 6 | 7 | - name: Remove EXTERNALLY-MANAGED 8 | ansible.builtin.file: 9 | path: /usr/lib/python3.{{ ansible_python.version.minor }}/EXTERNALLY-MANAGED 10 | state: absent 11 | 12 | - name: Ensure pip_install_packages are installed. 13 | pip: 14 | name: "{{ item.name | default(item) }}" 15 | version: "{{ item.version | default(omit) }}" 16 | virtualenv: "{{ item.virtualenv | default(omit) }}" 17 | state: "{{ item.state | default(omit) }}" 18 | extra_args: "{{ item.extra_args | default(omit) }}" 19 | executable: "{{ item.virtualenv | default(false) | ternary(omit, pip_executable) }}" 20 | loop: "{{ pip_install_packages }}" 21 | --------------------------------------------------------------------------------