[ English | Indonesia | русский | español | Deutsch | English (United Kingdom) ]

Extending OpenStack-Ansible with additional Ansible content

Einschließlich OpenStack-Ansible in Ihrem Projekt

Die Einbindung des openstack-ansible-Repository in ein anderes Projekt kann auf verschiedene Arten erfolgen:

  • Ein Git-Submodul zeigte auf ein freigegebenes Tag.

  • Ein Skript zum automatischen Ausführen eines Git-Checkouts von OpenStack-Ansible.

Wenn Sie OpenStack-Ansible in einem Projekt verwenden, sollten Sie eine parallele Verzeichnisstruktur verwenden, wie im Abschnitt `` ansible.cfg``-Dateien gezeigt.

Beachten Sie auch, dass das Kopieren von Dateien in Verzeichnisse wie `` env.d`` oder `` conf.d`` über eine Art Skript innerhalb des Erweiterungsprojekts erfolgen sollte.

Einschließlich OpenStack-Ansible mit Ihrer Ansible-Struktur

Sie können Ihre eigene Playbook-, Variablen- und Rollenstruktur erstellen, während Sie weiterhin die OpenStack-Ansible-Rollen und -Bibliotheken enthalten, indem Sie Umgebungsvariablen festlegen oder /usr/local/bin/openstack-ansible.rc anpassen.

Die relevanten Umgebungsvariablen für OpenStack-Ansible sind wie folgt:

ANSIBLE_LIBRARY

Diese Variable sollte auf /etc/ansible/plugins/library zeigen. Auf diese Weise können Rollen und Playbooks auf die enthaltenen Ansible-Module von OpenStack-Ansible zugreifen.

ANSIBLE_ROLES_PATH

Diese Variable sollte standardmäßig auf /etc/ansible/roles zeigen. Dadurch kann Ansible alle OpenStack-Ansible-Rollen, auf die sich die Erweiterungsrollen beziehen, ordnungsgemäß nachschlagen.

ANSIBLE_INVENTORY

Diese Variable sollte auf openstack-ansible/inventory/dynamic_inventory.py zeigen. Mit dieser Einstellung haben Erweiterungen Zugriff auf dasselbe dynamische Inventar, das OpenStack-Ansible verwendet.

Die Pfade zum obersten Verzeichnis openstack-ansible können in dieser Datei relativ sein.

Betrachten Sie diese Verzeichnisstruktur:

my_project
|
|- custom_stuff
|  |
|  |- playbooks
|- openstack-ansible
|  |
|  |- playbooks

Die Umgebungsvariablen würden ../openstack-ansible/playbooks/<directory> benutzen.

Hinzufügen neuer oder übergeordneter Rollen in Ihrer OpenStack-Ansible-Installation

Standardmäßig verwendet OpenStack-Ansible die ansible-role-requirements Datei, um die Rollen zu holen, die für den Installationsprozess benötigt werden.

Die Rollen werden in den Standard ANSIBLE_ROLES_PATH geholt, der standardmäßig /etc/ansible/roles ist.

ANSIBLE_ROLE_FILE ist eine Umgebungsvariable, die auf den Speicherort einer YAML-Datei verweist, die ansible-galaxy konsumieren kann, wobei angegeben wird, welche Rollen heruntergeladen und installiert werden sollen. Der Standardwert dafür ist ansible-role-anforderungen.yml.

To completely override the ansible-role-requirement file you can define the environment variable ANSIBLE_ROLE_FILE before running the bootstrap-ansible.sh script. With this approach it is now the responsibility of the deployer to maintain appropriate versions pins of the ansible roles if an upgrade is required.

If you want to extend or just partially override content of the ansible-role-requirements.yml file you can create a new config file which path defaults to /etc/openstack_deploy/user-role-requirements.yml. This path can be overriden with another environment variable USER_ROLE_FILE which is expected to be relative to OSA_CONFIG_DIR (/etc/openstack_deploy) folder.

This file is in the same format as ansible-role-requirements.yml and can be used to add new roles or selectively override existing ones. New roles listed in user-role-requirements.yml will be merged with those in ansible-role-requirements.yml, and roles with matching name key will override those in ansible-role-requirements.yml. In case when src key is not defined bootstrap script will skip cloning such roles.

It is easy for a deployer to keep this file under their own version control and out of the openstack-ansible tree.

Adding new or overriding collections in your OpenStack-Ansible installation

Alike to roles, collections for installation are stored in ansible-collection-requirements file. Path to this file can be overriden through ANSIBLE_COLLECTION_FILE environmental variable.

The Victoria release of openstack-ansible adds an optional new config file which defaults to /etc/openstack_deploy/user-collection-requirements.yml.

It should be in the native format of the ansible-galaxy requirements file and can be used to add new collections to the deploy host or override versions or source for collections defined in ansible-collection-requirements.

user-collection-requirements will be merged with ansible-collection-requirements using collection name as a key. In case source is not defined in user-collection-requirements, collection installation will be skipped. This way you can skip installation of unwanted collections.

You can override location of the user-collection-requirements.yml by setting USER_COLLECTION_FILE environment variable before running the bootstrap-ansible.sh script. Though it is expected to be relative to OSA_CONFIG_DIR (/etc/openstack_deploy) folder.

Calling extra playbooks during the deployment

If you install some additional deployment functionality as either a collection or a git repository on the deploy host, it is possible to automatically include extra playbooks at certain points during the deployment.

The points where a hook exists to call an external playbook are as follows:

  • pre_setup_hosts_hook

  • post_setup_hosts_hook

  • pre_setup_infrastructure_hook

  • post_setup_infrastructure_hook

  • pre_setup_openstack_hook

  • post_setup_openstack_hook

The hook variables should be configured in a suitable user_variables file. An example calling a playbook from a collection (installed using user-collection-requirements.yml) :

pre_setup_hosts_hook: custom.collection.playbook

Installing extra playbooks using collections, and referencing the playbook with its FQCN is the most robust approach to including additional user defined playbooks.

Installing extra Python packages inside Ansible virtualenv

Some Ansible collections may require presence of specific Python libraries inside execution environment. In order to accomplish that deployer can create /etc/openstack_deploy/user-ansible-venv-requirements.txt file with a list of Python libraries that should be installed inside virtual environment along with Ansible during bootstrap-ansible.sh execution.

You can override the default path to user-ansible-venv-requirements.txt file with USER_ANSIBLE_REQUIREMENTS_FILE environment variable before running the bootstrap-ansible.sh script.

Defining environment variables for deployment

Throughout the documentation we talk a lot about different environment variables that control behaviour of OpenStack-Ansible and Ansible iteself.

Starting with the Zed release a user.rc file can be placed in OSA_CONFIG_DIR (/etc/openstack_deploy) folder and contain any environment variable definitions that might be needed to change the default behaviour or any arbitrary Ansible configuration parameter. These environment variables are general purpose and are not limited to those understood by Ansible.

The path to this file can be changed by setting the OSA_USER_RC variable, but the OSA_CONFIG_DIR and OSA_USER_RC variables cannot re-defined or controlled through the user.rc file.