Skip to content

Instantly share code, notes, and snippets.

@rcarrata
Created July 16, 2020 14:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcarrata/2fecfa7e46157fcd1734282dfbb75704 to your computer and use it in GitHub Desktop.
Save rcarrata/2fecfa7e46157fcd1734282dfbb75704 to your computer and use it in GitHub Desktop.
Playbook for solve the issue in Tower of pip install openshift / kubernetes
#!/usr/bin/env ansible-playbook
# Installs the company specific virtual environments for Python properly
# into the Tower environment following the Ansible Tower environment notes:
# URL: https://docs.ansible.com/ansible-tower/3.3.4/html/upgrade-migration-guide/virtualenv.html
#
# NOTE: Requires the EPEL repository to install the python2-pip package.
#
# Usage:
# $ sudo ./setup_venvs.yml -i inventory.sand_swn01.ini
#
---
- hosts:
- tower
- playground
gather_facts: false
vars:
venvs:
# Setup the Kubernetes virtual environment
- dirname: Kubernetes
modules:
- k8s
- openshift
- requests
prereqs:
- gcc
tasks:
- name: "Ensure pip is installed"
# NOTE: This is from the EPEL repository.
yum:
name: python2-pip
state: latest
- name: "Ensure pip has latest tools"
# Notes taken from the Ansible container page:
# https://docs.ansible.com/ansible-container/installation.html
pip:
name:
- setuptools
extra_args: --upgrade
- name: "Install packages OUTSIDE Tower virtual environments"
# Necessary to make 'openshift' for the 'k8s' module.
pip:
name:
- openshift
extra_args: --ignore-installed
- name: "Install Python virtual environment packages"
yum:
name:
- python-virtualenv
state: latest
- name: "Install pip module required packages"
yum:
name: "{{ item.prereqs }}"
state: latest
loop: "{{ venvs }}"
when: item.prereqs is defined
- name: "Clean out old venv directories"
file:
path: "/var/lib/awx/venv/{{ item.dirname }}"
state: absent
become: true
loop: "{{ venvs }}"
- name: "Create the venv skeleton directory"
file:
path: "/var/lib/awx/venv/{{ item.dirname }}"
state: directory
become: true
loop: "{{ venvs }}"
- name: "Install base Tower packages"
pip:
name:
- python-memcached
- psutil
umask: "0022"
state: latest
virtualenv: "/var/lib/awx/venv/{{ item.dirname }}"
virtualenv_site_packages: yes
extra_args: --ignore-installed
loop: "{{ venvs }}"
- name: "Install requested packages in virtual env"
pip:
name: "{{ item.modules }}"
umask: "0022"
state: latest
virtualenv: "/var/lib/awx/venv/{{ item.dirname }}"
virtualenv_site_packages: yes
extra_args: --ignore-installed
loop: "{{ venvs }}"
@rcarrata
Copy link
Author

Run from the Tower as root user. Dirty but works... as always :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment