Ansible Installation
Ansible is an automation tool that provisions and configures infrastructure using procedural "playbooks" written in YAML. With the openstack.cloud collection, Ansible can deploy VMs, manage networks, and orchestrate multi-step deployments directly against the OpenStack API.
This chapter describes how to install Ansible and configure it for the OpenStack platform.
Prerequisites
- Basic knowledge of the Linux operating system (shell)
- Access to a running Linux VM or workstation (Ubuntu in our example) with an open port (Egress 443) to the OpenStack API
- Application Credentials (
clouds.yaml) — see Application Credentials
The steps to be performed are:
- Installation of Ansible
- Installation of the OpenStack collection
- A test run
Note
Ansible reads the same clouds.yaml file as the OpenStack CLI. Make sure it is placed at ~/.config/openstack/clouds.yaml before you start.
Steps:
0) Install Ansible
We recommend installing Ansible inside a Python virtual environment to avoid version conflicts with system packages.
sudo apt update
sudo apt install -y python3-venv
python3 -m venv ~/ansible-venv
source ~/ansible-venv/bin/activate
pip install -U pip
pip install -U ansible "openstacksdk<0.102.0"
Verify the installation:
ansible --version
Tip
The openstacksdk package is required by the openstack.cloud collection. Pin it to <0.102.0 to match the OSC compatibility — see OSC Installation.
1) Install the OpenStack collection
ansible-galaxy collection install openstack.cloud
This installs the modules os_server, os_network, os_volume, os_image_info, and others used to manage OpenStack resources.
2) Configure the cloud environment
Ansible uses the OS_CLOUD environment variable to select the cloud entry from your clouds.yaml:
export OS_CLOUD=openstack
Add this line to your ~/.bashrc to make it persistent.
3) Test connectivity
Run an ad-hoc command to verify that Ansible can reach the OpenStack API:
ansible localhost -m openstack.cloud.os_image_info
If everything is configured correctly, Ansible connects to the OpenStack API and lists the available images.
Note
The old module name os_image_info and the new FQCN openstack.cloud.os_image_info are both valid. We recommend using the FQCN in playbooks for clarity.
Congratulations, your Ansible setup is operational!
For full deployment examples (VMs, volumes), see: Infrastructure as Code
For more information on the OpenStack collection, refer to: Ansible OpenStack Collection