<style>
.reveal {
font-size: 22px;
}
</style>
# Openstack Ansible collections
slides: https://hackmd.io/@sshnaidm/collection-presentation
---
## Ansible and collections
- Before 2.10 version Ansible contains all cloud modules in main distribution
- `pip install ansible`
```graphviz
digraph hierarchy {
nodesep=1.0 // increases the separation between nodes
node [color=Red,fontname=Courier,shape=box] //All nodes will this shape and colour
edge [color=Blue, style=dashed] //All the lines look like this
"Ansible 2.9"->{"Ansible core" openstack aws gcp other_modules}
}
```
---
- After 2.10 Ansible repo will contain core code only, all other community modules moved to their separate repositories and called **collections**.
```graphviz
digraph hierarchy {
nodesep=1.0
node [color=Green,fontname=Courier,shape=box]
edge [color=Blue, style=dashed]
"Ansible 2.10"->{"ansible-base" "Ansible Community Distribution"}
"ansible-base"->{"Ansible core"}
"Ansible Community Distribution"->{openstack aws other }
}
```
- Now it's possible to install either Ansible "core" or Ansible "core" + all community modules
- `pip install ansible-base` vs `pip install ansible`
- Openstack collection in particular moved to Openstack Gerrit under Opendev umbrella: https://opendev.org/openstack/ansible-collections-openstack/
- It's developed now as any other Openstack project
- *But is not "official" part of Openstack because it's licensed as GPLv3+ (as all Ansible), while Openstack is licensed by Apache2.*
---
### Releasing collections with Ansible
- Ansible and collection releases are not adjusted, each collection has itw own release schedule.
```mermaid
gantt
title Releasing flow
section Ansible
Release 2.10.1 :a1, 2020-01-01, 20d
Release 2.10.2 :a2, after a1 , 20d
Release 2.10.3 :after a2 , 20d
section Openstack Collection
Version 1.0.3 :b1, 2020-01-02 , 12d
Version 1.0.4 :b2, after b1 , 9d
Version 1.0.5 :b3, after b2, 19d
Version 1.0.6 :b4, after b3, 10d
Version 1.0.7 :b5, after b4, 9d
Version 1.0.8 :b6, after b5, 10d
```
- Final collection version on the moment of Ansible release will be included in current Ansible Community Distribution (*ACD*) release.
- *for example in Ansible 2.10.2 on the diagram will be Openstack collection version 1.0.4 which was final in 2020-01-20, when 2.10.2 was released*
- *and 2.10.3 will include 1.0.5 as final at the moment of release*
- For using latest collection (or any specific version) there is possibility to install collection directly.
- *Collection installed separately takes precedence on that which is included in current install Ansible.*
- For example if Ansilbe has Openstack collection version `1.0.3` included we still can install collection version `1.0.1` and this one will be used.
- **Openstack collection - is a separate and independent product, a specific version of which is included in Ansible distribution from `2.10` version.**
---
## Install collection
---
### Install dependencies
- Openstack collection has [Openstack SDK](https://opendev.org/openstack/openstacksdk/) as its dependency.
- For using collection one need to install `pip install openstacksdk`
- **For using Openstack collection `openstacksdk` package must be installed on the machine where Ansible is actually executing**.
- For example if it's admins laptop when Ansible playbook runs, it should be installed on the laptop.
- If Ansible playbooks are executing on AWX/Tower or build machine, `openstacksdk` has to be installed there.
- There is no any need to install `openstacksdk` on actual Openstack nodes.
- For correct usage `openstacksdk` should be accessible to same python interpreter Ansible uses.
- For example if Ansible is installed in Python virtual environment, `openstacksdk` has to be installed there as well.
---
### SDK Versioning
- It's always recommended to use latest OpenstackSDK.
- OpenstackSDK version doesn't have to match Openstack version at all.
- OpenstackSDK are tools library for operating Openstack, it's not a part of Openstack itself, that's why latest SDK should support all versions of Openstack.
- OpenstackSDK Python packages can be install with `pip` - preferred installation way.
- OpenstackSDK RPM can be install from RDO `dnf install python3-openstacksdk` or `dnf install python2-openstacksdk`.
- Python version 3 is highly recommended for using SDK and collections. SDK from version `0.39.0` is supported for Python 3 only.
- Old version of SDK and collection itself still may support Python version 2, although it's strongly not recommended.
---
### Install Openstack collection
Collection can be installed in various ways:
- Install collection from [Ansible Galaxy](https://galaxy.ansible.com/openstack/cloud) where all collections releases present - **most preferred and recommended way**.
- Either download it as a tarball, or install with command `ansible-galaxy collection install openstack.cloud`
- Collection install with `ansible-galaxy` works from Ansible version 2.9.
- Collection itself may work with Ansible 2.8 as well, it has collection features as a "preview". Not recommended.
- Collection can be cloned from [Opendev repository](https://opendev.org/openstack/ansible-collections-openstack) from master branch or tagged release.
- Collection can be installed as RPM `dnf install ansible-collections-openstack` with enabled RDO repositories (currently from Ussuri and above, will be included in Train as well).
- Colelction can be install with `pip`. Clone the repository above and run `pip install .`
- Collections usually autodetected from folder `~/.ansible/collections/ansible_collections/`
- When installing with `pip` or `RPM` the collection will be installed in `/usr/share/ansible/collections/ansible_collections`.
- To use them from there need to update [collection path](https://docs.ansible.com/ansible/latest/reference_appendices/config.html#collections-paths):
```bash
export ANSIBLE_COLLECTIONS_PATHS=/usr/share/ansible/collections:$ANSIBLE_COLLECTIONS_PATHS
```
- There is possibility Openstack collection will be available in [Automation Hub](https://cloud.redhat.com/ansible/automation-hub/) with other Red Hat certified collections.
---
### Usage
scripts for installations
- Usage examples and additional info can be found in [collection README](https://opendev.org/openstack/ansible-collections-openstack/src/branch/master/README.md)
- List of supported modules from Openstack collection (not all supported atm)
---
### Wrap up
Q&A?
---
### Thank you!
{"metaMigratedAt":"2023-06-15T11:40:48.610Z","metaMigratedFrom":"YAML","title":"Ansible Openstack collection tutorial","breaks":true,"description":"How to install and use Ansible Openstack collections.","contributors":"[{\"id\":\"3d0a6adb-ac9b-40f9-9764-93772fb3f6df\",\"add\":7740,\"del\":3078}]"}