From 162915b8e5098ce8c371191063a57a0cc7e94c9c Mon Sep 17 00:00:00 2001 From: Enzo Arroyo Date: Sun, 17 Jul 2022 22:43:32 +0200 Subject: [PATCH] =?UTF-8?q?Se=20ajusta=20la=20tarea=20de=20instalaci=C3=B3?= =?UTF-8?q?n=20de=20paquetes=20al=20'venv',=20en=20ves=20de=20recorrer=20e?= =?UTF-8?q?l=20diccionario=20con=20el=20m=C3=A9todo=20'with=5Fitems'=20y?= =?UTF-8?q?=20llamar=20el=20valor=20directamente,=20usamos=20el=20metodo?= =?UTF-8?q?=20'with=5Fdict',=20ya=20que=20el=20el=20valor=20a=20leer=20es?= =?UTF-8?q?=20un=20diccionario=20y=20no=20una=20lista?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +-- CHANGELOG.md | 3 ++ README.md | 88 +++++++++++++++++++++++++++++--------------------- tasks/main.yml | 20 ++++++------ tests/main.yml | 2 +- 5 files changed, 68 insertions(+), 50 deletions(-) diff --git a/.gitignore b/.gitignore index dc96934..5a5f20e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ # Ficheros creados por Vagrant .vagrant/ - -# Fichero de pruebas +# Direcotrio temporal tests/roles/ +# AnsibleVault +.vaultpass diff --git a/CHANGELOG.md b/CHANGELOG.md index 9bb13a3..dc704e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 0.2.0 +* Se ajusta la tarea de instalación de paquetes al `venv`, en ves de recorrer el diccionario con el método `with_items` y llamar el valor directamente, usamos el metodo `with_dict`, ya que el el valor a leer es un diccionario y no una lista. + # 0.1.1 * Actualizamos `Jenkinsfile` para adaptarnos a la nueva versión del vars `ansibleActions`[jenkins-shared-libraries] diff --git a/README.md b/README.md index 4ee0725..d010541 100644 --- a/README.md +++ b/README.md @@ -1,39 +1,53 @@ -# Role PIP -Este rol tiene como finalidad configurar el crear y mantener jaulas de **python 3**. - -## Dependencias -Este rol no tiene dependencias de otros roles - -## Funcionamiento -El funcionamiento como tal es simple, lo reflejamos en la siguiente tabla: - -| | Primer nivel | Segundo nivel | -|--|--|--| -| Jaulas | X | - | -| Paquetes | - | X | - -## Particularidades -Este rol está pensado para el uso de python3 y no es compatible con versiones de *python* inferiores a 3. - -## Variables -Debajo una pequeña tabla que podría definir brevemente las características de cada variable: - -| | Mandatoria | Opcional | Tipo | -|--|--|--|--| -| environments | X | - | Diccionario | - -Un ejemplo de como se crearia el diccionario: - - environments: - ansible: - - "ansible==2.8.5" - - "yamllint" - - "docker" - ansible29: - - "ansible==2.9.27" - - "flask" - cualquiera: - -## Leyenda +Role PIP +=================== + +Description +------------- +The purpose of this role is configure python jails over **python 3** and **pip** packages. + +Requirements +------------- +It has no special requirements + +How to use +------------- + - import_role: + name: "pip" + vars: + environments: + [jail_name]: + - [package_name] + - [package_name] + - [package_name==0.1] + [jail_name]: + - [package_name] + - [package_name] + - [package_name==2] + [jail_name]: [] +ROOT Vars +------------- + +* Variable name: `environments` +* Default value: empty {}. +* Accepted values: Dictionary [key => value]. +* Description: Variable intended to contain `keys` for the purposes of each `python virtualenv` and `values` as package list. + +CHILD Vars for: `environments` +------------- + +* Variable name: `jail_name` +* Default value: `NULL`. +* Accepted values: STRING +* Description: The python jail name that you want to create. + +---------- + +* Variable name: `package_name` +* Default value: `NULL`. +* Accepted values: STRING +* Description: The package name that you want to install, this content is a list so if you want to declare as empty can use `[]`. You can specify the package version like this: `package==version`, by example **yamllint==0.1** + +Legend +------------- * NKS => No key sensitive * KS => Key sensitive diff --git a/tasks/main.yml b/tasks/main.yml index 2f59adf..3de444a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -12,12 +12,12 @@ when: (requiredpackages is defined and requiredpackages | length > 0) - name: pip | Check ansible virtual environment exists stat: - path: "{{ ve_default_path }}{{ item }}/bin/activate" + path: "{{ ve_default_path }}{{ item.key }}/bin/activate" register: 'virtualenv_status' - with_items: "{{ environments }}" + with_dict: "{{ environments }}" - name: pip | Ansible virtual environment directory creation file: - path: "{{ ve_default_path }}{{ item.item }}/" + path: "{{ ve_default_path }}{{ item.item.key }}/" state: "directory" mode: "0755" recurse: "yes" @@ -25,7 +25,7 @@ when: (not item.stat.exists) - name: pip | Setting ACL for environment directory acl: - path: "{{ ve_default_path }}{{ item.item }}/" + path: "{{ ve_default_path }}{{ item.item.key }}/" entity: "{{ 'wheel' if ansible_os_family == 'RedHat' else 'sudo' }}" etype: "group" permissions: "rwx" @@ -34,7 +34,7 @@ when: (not item.stat.exists) - name: pip | Setting default ACL for environment directory acl: - path: "{{ ve_default_path }}{{ item.item }}/" + path: "{{ ve_default_path }}{{ item.item.key }}/" entity: "{{ 'wheel' if ansible_os_family == 'RedHat' else 'sudo' }}" etype: "group" permissions: "rwx" @@ -45,13 +45,13 @@ - name: pip | Python virtualenv creation shell: cmd: | - python3 -m virtualenv -p python3 "{{ ve_default_path }}{{ item.item }}"/ + python3 -m virtualenv -p python3 "{{ ve_default_path }}{{ item.item.key }}"/ with_items: "{{ virtualenv_status.results }}" when: (not item.stat.exists) - name: pip | Virtualenv packages installation pip: - name: "{{ environments[item] }}" - virtualenv: "{{ ve_default_path }}{{ item }}/" - with_items: "{{ environments }}" - when: (environments[item]) + name: "{{ item.value }}" + virtualenv: "{{ ve_default_path }}{{ item.key }}/" + with_dict: "{{ environments }}" + when: (item.value) ... diff --git a/tests/main.yml b/tests/main.yml index 22cf22b..5187a49 100644 --- a/tests/main.yml +++ b/tests/main.yml @@ -20,5 +20,5 @@ ansible29: - "ansible==2.9.27" - "flask" - cualquiera: + cualquiera: [] ... -- GitLab