Ansible install python module

Eugeneer’s Media Cloud World

Блог творческого ИТ-практика — возьми свою мысль и придай ей ускорение идеи! В фокусе: сети, безопасность, виртуализация, web, мультимедиа.

Главная

А А Saturday, 12 December 2020

Установка сторонних модулей в Ansible.

Установка сторонних модулей с открытым исходным кодом или специализированных модулей выполняется достаточно просто. Рассмотрим эту установку на примере модулей NTC.

Для этого нужно выполнить следующие действия:

1. Выбрать путь в файловой системе Linux, то есть локацию для хранения всех сторонних модулей.

2. Открыть файл конфигурации Ansible (ansible.cfg) и добавить в путь поиска модулей новый каталог, в котором выполнялось клонирование.

Если место расположения файла ansible.cfg неизвестно, то необходимо выполнить команду ansible —version в своей системе. Вывод может выглядеть приблизительно так:

ntc@ntc:~/projects$ ansible —version

config file = /etc/ansible/ansible.cfg

configured module search path = [u’/etc/ntc/ansible/’]

python version = 2.7.6 (default, Jul 21 2020, 16:45:13) [GCC 4.8.2]

Вы также увидите строку library =. В этой строке нужно добавить каталог, в котором сохранены все клонированные репозитории (например, library = /etc/ntc/ansible/). При правильном обновлении файла конфигурации при следующем выполнении команды ansible —version вы увидите все внесенные изменения.

3. Перейти в локацию для сторонних модулей по выбранному пути и выполнить команду git clone в репозитории каждого модуля, который предполагается использовать:

git clone https://github.com/networktocode/ntc-ansible —recursive

git clone https://github.com/networktocode/ntc-ansible

git submodule update —init –recursive

4. Если сохраняется необходимость установки каких-либо пакетов от которых зависят модули, то эта процедура должна быть документирована на сайте каждого соответствующего проекта GitHub. При этом, возможно, потребуется установка нескольких пакетов с помощью утилиты pip. Если вы используете Python virtualenv или в вашей системе установлено несколько версий Python, то потребуется определение значения переменной ansible_python_interpreter в среде Ansible.

5. Также может потребоваться установка зависимостей.

Дополнительно вам может понадобиться lxml:

sudo apt-get install zlib1g-dev libxml2-dev libxslt-dev python-dev

Источник

ansible.builtin.pip module – Manages Python library dependencies

This module is part of ansible-core and included in all Ansible installations. In most cases, you can use the short module name pip even without specifying the collections: keyword. However, we recommend you use the FQCN for easy linking to the module documentation and to avoid conflicting with other collections that may have the same module name.

Synopsis

  • Manage Python library dependencies. To use this module, one of the following keys is required: name or requirements .

Requirements

The below requirements are needed on the host that executes this module.

Parameters

cd into this directory before running the command

The explicit executable or pathname for the pip executable, if different from the Ansible Python interpreter. For example pip3.3 , if there are both Python 2.7 and 3.3 installations in the system and you want to run pip for the Python 3.3 installation.

Mutually exclusive with virtualenv (added in 2.1).

Does not affect the Ansible Python interpreter.

The setuptools package must be installed for both the Ansible Python interpreter and for the version of Python specified by this option.

Extra arguments passed to pip.

The name of a Python library to install or the url(bzr+,hg+,git+,svn+) of the remote package.

This can be a list (since 2.2) and contain version specifiers (since 2.7).

requirements

The path to a pip requirements file, which should be local to the remote system. File can be specified as a relative path if using the chdir option.

The ‘forcereinstall’ option is only available in Ansible 2.1 and above.

The system umask to apply before installing the pip package. This is useful, for example, when installing on systems that have a very restrictive umask by default (e.g., “0077”) and you want to pip install packages which are to be used by all users. Note that this requires you to specify desired umask mode as an octal string, (e.g., “0022”).

The version number to install of the Python library specified in the name parameter.

An optional path to a virtualenv directory to install into. It cannot be specified together with the ‘executable’ parameter (added in 2.1). If the virtualenv does not exist, it will be created before installing packages. The optional virtualenv_site_packages, virtualenv_command, and virtualenv_python options affect the creation of the virtualenv.

virtualenv_command

The command or a pathname to the command to create the virtual environment with. For example pyvenv , virtualenv , virtualenv2 , ~/bin/virtualenv , /usr/local/bin/virtualenv .

virtualenv_python

The Python executable used for creating the virtual environment. For example python3.5 , python2.7 . When not specified, the Python version used to run the ansible module is used. This parameter should not be used when virtualenv_command is using pyvenv or the -m venv module.

virtualenv_site_packages

Whether the virtual environment will inherit packages from the global site-packages directory. Note that if this setting is changed on an already existing virtual environment it will not have any effect, the environment must be deleted and newly created.

Attributes

Can run in check_mode and return changed status prediction without modifying target

Will return details on what has changed (or possibly needs changing in check_mode), when in diff mode

Target OS/families that can be operated against

Notes

  • The virtualenv (http://www.virtualenv.org/) must be installed on the remote host if the virtualenv parameter is specified and the virtualenv needs to be created.
  • Although it executes using the Ansible Python interpreter, the pip module shells out to run the actual pip command, so it can use any pip version you specify with executable. By default, it uses the pip version for the Ansible Python interpreter. For example, pip3 on python 3, and pip2 or pip on python 2.
  • The interpreter used by Ansible (see ansible_python_interpreter ) requires the setuptools package, regardless of the version of pip set with the executable option.

Examples

- name: Install bottle python package ansible.builtin.pip: name: bottle - name: Install bottle python package on version 0.11 ansible.builtin.pip: name: bottle==0.11 - name: Install bottle python package with version specifiers ansible.builtin.pip: name: bottle>0.10, - name: Install multi python packages with version specifiers ansible.builtin.pip: name: - django>1.11.0, - bottle>0.10, - name: Install python package using a proxy ansible.builtin.pip: name: six environment: http_proxy: 'http://127.0.0.1:8080' https_proxy: 'https://127.0.0.1:8080' # You do not have to supply '-e' option in extra_args - name: Install MyApp using one of the remote protocols (bzr+,hg+,git+,svn+) ansible.builtin.pip: name: svn+http://myrepo/svn/MyApp#egg=MyApp - name: Install MyApp using one of the remote protocols (bzr+,hg+,git+) ansible.builtin.pip: name: git+http://myrepo/app/MyApp - name: Install MyApp from local tarball ansible.builtin.pip: name: file:///path/to/MyApp.tar.gz - name: Install bottle into the specified (virtualenv), inheriting none of the globally installed modules ansible.builtin.pip: name: bottle virtualenv: /my_app/venv - name: Install bottle into the specified (virtualenv), inheriting globally installed modules ansible.builtin.pip: name: bottle virtualenv: /my_app/venv virtualenv_site_packages: yes - name: Install bottle into the specified (virtualenv), using Python 2.7 ansible.builtin.pip: name: bottle virtualenv: /my_app/venv virtualenv_command: virtualenv-2.7 - name: Install bottle within a user home directory ansible.builtin.pip: name: bottle extra_args: --user - name: Install specified python requirements ansible.builtin.pip: requirements: /my_app/requirements.txt - name: Install specified python requirements in indicated (virtualenv) ansible.builtin.pip: requirements: /my_app/requirements.txt virtualenv: /my_app/venv - name: Install specified python requirements and custom Index URL ansible.builtin.pip: requirements: /my_app/requirements.txt extra_args: -i https://example.com/pypi/simple - name: Install specified python requirements offline from a local directory with downloaded packages ansible.builtin.pip: requirements: /my_app/requirements.txt extra_args: "--no-index --find-links=file:///my_downloaded_packages_dir" - name: Install bottle for Python 3.3 specifically, using the 'pip3.3' executable ansible.builtin.pip: name: bottle executable: pip3.3 - name: Install bottle, forcing reinstallation if it's already installed ansible.builtin.pip: name: bottle state: forcereinstall - name: Install bottle while ensuring the umask is 0022 (to ensure other users can use it) ansible.builtin.pip: name: bottle umask: "0022" become: True 

Return Values

Common return values are documented here , the following are the fields unique to this module:

Источник

Читайте также:  Php check url available
Оцените статью