Minimal code to start deploy machines on the OVH Public Cloud (OpenStack) with Terraform and Ansible.
Instructions for use directly on your system. For use with docker see below.
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
$ 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
Install terraform plugins
$ terraform init
$ terraform apply
$ ansible-playbook site.yml
$ terraform destroy
$ cp .env.example .env
Edit .env
with sensitive values and load them in the shell
$ vim .env
$ 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
Only nixpkgs and pip required.
$ python -m venv .venv
$ pip install -r requirements.txt
$ 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.