Skip to content

langouste/openstack-starter

Repository files navigation

Minimal code to start deploy machines on the OVH Public Cloud (OpenStack) with Terraform and Ansible.

Usage without docker

Instructions for use directly on your system. For use with docker see below.

1. Install requirements

Install terraform :

  • Download binary v0.14.9
  • Unzipping it and moving it to a directory included in your system's PATH.

Install ansible :

If you want to use OpenStack CLI, install python requirements (optional):

$ pip install -r requirements.txt

2. Set OpenStack configuration and keypair

$ cp .env.example .env

Edit .env with sensitive values and load them in the shell

$ vim .env
$ source openrc.sh

Geerate a RSA keypair

$ ssh-keygen -t rsa -b 4096 -f ~/.ssh/ovhcloud

3. Apply Terraform and Ansible config

Install terraform plugins

$ terraform init
$ terraform apply
$ ansible-playbook site.yml

4. Destroy the test server

$ terraform destroy

Usage with docker

1. Set OpenStack configuration and keypair

$ cp .env.example .env

Edit .env with sensitive values and load them in the shell

$ vim .env

2. Use tools on docker via make

$ make shell
(...)
bash-5.1# ./create-server.sh
bash-5.1# source openrc.sh
bash-5.1# openstack server list
+--------------------------------------+-------------+--------+----------------------------------------------+-------+--------+
| ID                                   | Name        | Status | Networks                                     | Image | Flavor |
+--------------------------------------+-------------+--------+----------------------------------------------+-------+--------+
| e624c727-13ab-4cce-b797-3cb56d50591c | ubuntu-test | ACTIVE | Ext-Net=2001:41d0:801:1000::2138, 54.37.5.51 |       | s1-2   |
+--------------------------------------+-------------+--------+----------------------------------------------+-------+--------+

bash-5.1# wget -q -O - 54.37.5.51; echo
Hello world !
bash-5.1# terraform destroy
bash-5.1# exit
$ make clean

If you edit some files re-copy then in the container

$ make
Copy this files in the container : .env openrc.sh main.tf .terraform.lock.hcl ansible.cfg site.yml

Usage with nixpkgs

Only nixpkgs and pip required.

1. Install python requirements in a virtual env (optional)

$ python -m venv .venv
$ pip install -r requirements.txt

2. Get a working environment

$ nix-shell

This command :

  • Install system dependencies (terraform, ansible)
  • Load environment variables on openrc.sh
  • Activate the virtual python environment .venv

Next you can use terraform and ansible commands to perform actions described below.

About

Deploy a test machine with Terraform and Ansible

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published