mirror of
https://github.com/ansible/awx.git
synced 2026-03-11 06:29:31 -02:30
Merge pull request #4263 from fantashley/easy-custom-venvs
Add dynamic custom venv setup Reviewed-by: Shane McDonald <me@shanemcd.com> https://github.com/shanemcd
This commit is contained in:
@@ -98,48 +98,42 @@ Once the AWX API is available, update the `CUSTOM_VENV_PATHS` setting as describ
|
|||||||
|
|
||||||
Kubernetes Custom Virtualenvs
|
Kubernetes Custom Virtualenvs
|
||||||
=============================
|
=============================
|
||||||
|
You can add custom virtual environments without modifying images by including
|
||||||
|
the following variables in your `install.yml` playbook run. Your variables file
|
||||||
|
must have a variable called `custom_venvs` with a list of your custom
|
||||||
|
virtualenvs containing the name, python interpreter, ansible version, and a list
|
||||||
|
of modules that should be installed in each one:
|
||||||
|
|
||||||
You can create custom virtualenvs without updating the awx images by using initContainers and a shared emptydir within Kubernetes. To start create an emptydir volume in the volumes stanza.
|
```yaml
|
||||||
|
# venv_vars.yaml
|
||||||
|
---
|
||||||
|
custom_venvs:
|
||||||
|
- name: dns_team
|
||||||
|
python: python3 # Defaults to python2
|
||||||
|
python_ansible_version: 2.8.1
|
||||||
|
python_modules:
|
||||||
|
- dnspython
|
||||||
|
- infoblox-client
|
||||||
|
- name: windows_team
|
||||||
|
python: python2
|
||||||
|
python_ansible_version: 2.8.0
|
||||||
|
python_modules:
|
||||||
|
- winrm
|
||||||
|
- name: vmware_team
|
||||||
|
python_ansible_version: 2.7.10
|
||||||
|
python_modules:
|
||||||
|
- pyvmomi
|
||||||
|
```
|
||||||
|
|
||||||
volumes:
|
The virtualenvs will be created in `/opt/custom-venvs` by default, but you can
|
||||||
- emptyDir: {}
|
override that location by setting the variable `custom_venvs_path`.
|
||||||
name: custom-venv
|
|
||||||
|
|
||||||
Now create an initContainer stanza. You can subsititute your own custom images for this example we are using centos:7 as the base to build upon. The command stanza is where you will add the python modules you require in your virtualenv.
|
You can use the variables file like so:
|
||||||
|
|
||||||
initContainers:
|
$ ansible-playbook install.yml --extra-vars "@venv_vars.yaml"
|
||||||
- image: 'centos:7'
|
|
||||||
name: init-custom-venv
|
|
||||||
command:
|
|
||||||
- sh
|
|
||||||
- '-c'
|
|
||||||
- >-
|
|
||||||
yum install -y ansible python-pip curl python-setuptools epel-release openssl openssl-devel gcc python-devel &&
|
|
||||||
curl 'https://bootstrap.pypa.io/get-pip.py' | python &&
|
|
||||||
pip install virtualenv &&
|
|
||||||
mkdir -p /opt/my-envs &&
|
|
||||||
virtualenv /opt/my-envs/custom-venv &&
|
|
||||||
source /opt/my-envs/custom-venv/bin/activate &&
|
|
||||||
/opt/my-envs/custom-venv/bin/pip install psutil &&
|
|
||||||
/opt/my-envs/custom-venv/bin/pip install -U "ansible == X.Y.Z" &&
|
|
||||||
/opt/my-envs/custom-venv/bin/pip install -U custom-python-module
|
|
||||||
volumeMounts:
|
|
||||||
- mountPath: /opt/my-envs/custom-venv
|
|
||||||
name: custom-venv
|
|
||||||
|
|
||||||
Finally in the awx-celery and awx-web containers stanza add the shared volume as a mount.
|
Once the AWX API is available, you will need to update the `CUSTOM_VENV_PATHS`
|
||||||
|
setting as described in `Preparing a New Custom Virtualenv`.
|
||||||
volumeMounts:
|
|
||||||
- mountPath: /opt/my-envs/custom-venv
|
|
||||||
name: custom-venv
|
|
||||||
- mountPath: /etc/tower
|
|
||||||
name: awx-application-config
|
|
||||||
readOnly: true
|
|
||||||
- mountPath: /etc/tower/conf.d
|
|
||||||
name: awx-confd
|
|
||||||
readOnly: true
|
|
||||||
|
|
||||||
Once the AWX API is available, update the `CUSTOM_VENV_PATHS` setting as described in `Preparing a New Custom Virtualenv`.
|
|
||||||
|
|
||||||
Assigning Custom Virtualenvs
|
Assigning Custom Virtualenvs
|
||||||
============================
|
============================
|
||||||
|
|||||||
@@ -46,3 +46,6 @@ kubernetes_deployment_replica_size: 1
|
|||||||
postgress_activate_wait: 60
|
postgress_activate_wait: 60
|
||||||
|
|
||||||
insights_url_base: "https://example.org"
|
insights_url_base: "https://example.org"
|
||||||
|
|
||||||
|
custom_venvs_path: "/opt/custom-venvs"
|
||||||
|
custom_venvs_python: "python2"
|
||||||
|
|||||||
@@ -134,6 +134,35 @@ spec:
|
|||||||
spec:
|
spec:
|
||||||
serviceAccountName: awx
|
serviceAccountName: awx
|
||||||
terminationGracePeriodSeconds: 10
|
terminationGracePeriodSeconds: 10
|
||||||
|
{% if custom_venvs is defined %}
|
||||||
|
initContainers:
|
||||||
|
- image: 'centos:7'
|
||||||
|
name: init-custom-venvs
|
||||||
|
command:
|
||||||
|
- sh
|
||||||
|
- '-c'
|
||||||
|
- >-
|
||||||
|
yum install -y ansible curl python-setuptools epel-release \
|
||||||
|
openssl openssl-devel gcc python-devel &&
|
||||||
|
yum install -y python-virtualenv python36 python36-devel &&
|
||||||
|
mkdir -p {{ custom_venvs_path }} &&
|
||||||
|
{% for custom_venv in custom_venvs %}
|
||||||
|
virtualenv -p {{ custom_venv.python | default(custom_venvs_python) }} \
|
||||||
|
{{ custom_venvs_path }}/{{ custom_venv.name }} &&
|
||||||
|
source {{ custom_venvs_path }}/{{ custom_venv.name }}/bin/activate &&
|
||||||
|
{{ custom_venvs_path }}/{{ custom_venv.name }}/bin/pip install -U psutil \
|
||||||
|
"ansible=={{ custom_venv.python_ansible_version }}" &&
|
||||||
|
{% if custom_venv.python_modules is defined %}
|
||||||
|
{{ custom_venvs_path }}/{{ custom_venv.name }}/bin/pip install -U \
|
||||||
|
{% for module in custom_venv.python_modules %}{{ module }} {% endfor %} &&
|
||||||
|
{% endif %}
|
||||||
|
deactivate &&
|
||||||
|
{% endfor %}
|
||||||
|
:
|
||||||
|
volumeMounts:
|
||||||
|
- name: custom-venvs
|
||||||
|
mountPath: {{ custom_venvs_path }}
|
||||||
|
{% endif %}
|
||||||
containers:
|
containers:
|
||||||
- name: {{ kubernetes_deployment_name }}-web
|
- name: {{ kubernetes_deployment_name }}-web
|
||||||
image: "{{ kubernetes_web_image }}:{{ kubernetes_web_version }}"
|
image: "{{ kubernetes_web_image }}:{{ kubernetes_web_version }}"
|
||||||
@@ -150,6 +179,10 @@ spec:
|
|||||||
- name: {{ kubernetes_deployment_name }}-project-data-dir
|
- name: {{ kubernetes_deployment_name }}-project-data-dir
|
||||||
mountPath: "/var/lib/awx/projects"
|
mountPath: "/var/lib/awx/projects"
|
||||||
readOnly: false
|
readOnly: false
|
||||||
|
{% endif %}
|
||||||
|
{% if custom_venvs is defined %}
|
||||||
|
- name: custom-venvs
|
||||||
|
mountPath: {{ custom_venvs_path }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
- name: {{ kubernetes_deployment_name }}-application-config
|
- name: {{ kubernetes_deployment_name }}-application-config
|
||||||
mountPath: "/etc/tower/settings.py"
|
mountPath: "/etc/tower/settings.py"
|
||||||
@@ -190,6 +223,10 @@ spec:
|
|||||||
- name: {{ kubernetes_deployment_name }}-ca-trust-dir
|
- name: {{ kubernetes_deployment_name }}-ca-trust-dir
|
||||||
mountPath: "/etc/pki/ca-trust/source/anchors/"
|
mountPath: "/etc/pki/ca-trust/source/anchors/"
|
||||||
readOnly: true
|
readOnly: true
|
||||||
|
{% endif %}
|
||||||
|
{% if custom_venvs is defined %}
|
||||||
|
- name: custom-venvs
|
||||||
|
mountPath: {{ custom_venvs_path }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
- name: {{ kubernetes_deployment_name }}-application-config
|
- name: {{ kubernetes_deployment_name }}-application-config
|
||||||
mountPath: "/etc/tower/settings.py"
|
mountPath: "/etc/tower/settings.py"
|
||||||
@@ -300,6 +337,10 @@ spec:
|
|||||||
hostPath:
|
hostPath:
|
||||||
path: "{{ project_data_dir }}"
|
path: "{{ project_data_dir }}"
|
||||||
type: Directory
|
type: Directory
|
||||||
|
{% endif %}
|
||||||
|
{% if custom_venvs is defined %}
|
||||||
|
- name: custom-venvs
|
||||||
|
emptyDir: {}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
- name: {{ kubernetes_deployment_name }}-application-config
|
- name: {{ kubernetes_deployment_name }}-application-config
|
||||||
configMap:
|
configMap:
|
||||||
|
|||||||
Reference in New Issue
Block a user