This Ansible role, AhmadRafiee.openstack-bootstrap, automates the deployment of an OpenStack environment, provisioning resources such as flavors, networks, subnets, routers, keypairs, images, and compute instances. It provides a streamlined way to bootstrap an OpenStack cloud infrastructure using best practices.
The AhmadRafiee.openstack-bootstrap role simplifies OpenStack setup by automating the creation of:
- Custom compute flavors (e.g., Tiny, Small, Medium, Large).
- Public and private networks with subnets.
- A router with external gateway and interfaces.
- SSH keypairs for secure access.
- Disk images (e.g., Cirros, Ubuntu 24.04, Debian 12).
- Compute instances with cloud-init configurations.
This role is available on Ansible Galaxy and is ideal for initializing OpenStack environments for development, testing, or production.
Before using this role, ensure the following are installed and configured:
- Ansible: Version 2.9 or higher.
pip install --upgrade ansible
- openstack.cloud Collection: Required for OpenStack interactions. Install it using:
Alternatively, use the provided
ansible-galaxy collection install openstack.cloud
requirements.yml:ansible-galaxy install -r requirements.yml
- Python Dependencies: Install the
openstacksdkpackage:pip install openstacksdk
- OpenStack Environment: Access to an OpenStack cloud with valid admin credentials (e.g.,
auth_url,username,password). - SSH Public Keys: Required for keypair provisioning.
- Image Download Access: URLs for images (e.g., Ubuntu, Cirros) must be accessible.
Install the role from Ansible Galaxy:
ansible-galaxy role install AhmadRafiee.openstack-bootstrapInstall dependencies using the provided requirements.yml:
ansible-galaxy install -r requirements.ymlThe requirements.yml file includes:
collections:
- name: openstack.cloud
source: https://galaxy.ansible.com
version: ">=2.0.0"The role is organized into modular tasks:
├── defaults/
│ └── main/main.yml # Default variables (flavors, networks, etc.)
├── tasks/
│ ├── main.yml # Main playbook importing all tasks
│ ├── create-flavor.yml # Creates custom flavors
│ ├── create-network.yml # Creates networks and subnets
│ ├── create-router.yml # Creates router and interfaces
│ ├── create-keypair.yml # Adds SSH keypairs
│ ├── create-image.yml # Downloads and uploads images
│ ├── create-instance.yml # Creates compute instances
│ └── delete-instance.yml # Deletes instances
├── meta/
│ └── main.yml # Role metadata
├── requirements.yml # Dependency definitions
└── README.md # Documentation
Defines compute flavors (e.g., Tiny: 1GB RAM, 1 vCPU, 10GB disk) configurable via the flavors variable.
Provisions:
- Public Network: External flat network (
192.168.202.0/24) with DHCP. - Private Network: Internal network (
10.20.30.0/24) with DHCP. - Zun Network: Non-DHCP network (
20.30.40.0/24) for specific use cases.
Creates a router connected to the public network with interfaces to private subnets.
Uploads SSH public keys to OpenStack for secure instance access.
Downloads and uploads images (e.g., Cirros, Ubuntu 24.04, Debian 12) to OpenStack with qcow2 format and public visibility.
Deploys instances with:
- Boot-from-volume support.
- Cloud-init for configuring hostname, users, packages (e.g., nginx), and services.
- Custom security groups and networks.
-
Set Up Authentication: Configure OpenStack credentials in a
clouds.yamlfile or as playbook variables:openstack_auth: auth_url: "https://your-openstack-auth-url:5000/v3" username: "admin" password: "your-password" project_name: "admin" user_domain_name: "Default" project_domain_name: "Default"
-
Create a Playbook: Example playbook (
playbook.yml):- name: Bootstrap OpenStack with AhmadRafiee.openstack-bootstrap hosts: localhost connection: local vars: openstack_auth: auth_url: "https://your-openstack-auth-url:5000/v3" username: "admin" password: "your-password" project_name: "admin" user_domain_name: "Default" project_domain_name: "Default" image_path: "/tmp/openstack-images" ssh_keys: - name: "test-key" public_key: "ssh-rsa AAAAB3NzaC1yc2E... your-public-key" router: name: "test-router" external_network: "Public" roles: - AhmadRafiee.openstack-bootstrap
-
Run the Playbook:
ansible-playbook playbook.yml -v
Use tags to run specific tasks (e.g.,
--tags create_instance). -
Delete Resources (if needed):
ansible-playbook playbook.yml --tags delete_instance -v
Key variables defined in defaults/main/main.yml:
flavors: List of flavor specs (name, ram, vcpus, disk, is_public).networks: Network configurations (name, external, subnet_name, cidr, gateway_ip, etc.).router: Router name and external network.ssh_keys: List of SSH keypairs (name, public_key).image_path: Directory for downloaded images.images_to_upload: Image details (name, url, container_format, disk_format).instance: Instance details (image_name, flavor_name, network_name, etc.).
See defaults/main/main.yml for full variable definitions.
Run specific tasks using tags:
preparing_openstack: Creates flavors, networks, router, keypairs, and images.create_flavor,create_network,create_router,create_keypair,create_image: Individual setup tasks.create_instance: Creates an instance.delete_instance: Deletes an instance.
Example:
ansible-playbook playbook.yml --tags create_instanceSubscribe to our channels, leave a comment, and drop a like to support our content. Your engagement helps us create more valuable DevOps and cloud content! 🙌