mirror of
https://github.com/trailofbits/algo.git
synced 2025-09-03 02:23:39 +02:00
Scaleway integration #623
This commit is contained in:
parent
6caeaa30d0
commit
9f7398ff77
4 changed files with 175 additions and 4 deletions
44
algo
44
algo
|
@ -347,6 +347,42 @@ algo_region=${algo_region:-1}
|
||||||
EXTRA_VARS="aws_access_key=$aws_access_key aws_secret_key=$aws_secret_key algo_server_name=$algo_server_name region=$region"
|
EXTRA_VARS="aws_access_key=$aws_access_key aws_secret_key=$aws_secret_key algo_server_name=$algo_server_name region=$region"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scaleway () {
|
||||||
|
read -p "
|
||||||
|
Enter your auth token (https://www.scaleway.com/docs/generate-an-api-token/)
|
||||||
|
$ADDITIONAL_PROMPT
|
||||||
|
[...]: " -rs scaleway_auth_token
|
||||||
|
|
||||||
|
read -p "
|
||||||
|
|
||||||
|
Enter your organization name (https://cloud.scaleway.com/#/billing)
|
||||||
|
$ADDITIONAL_PROMPT
|
||||||
|
[...]: " -rs scaleway_organization
|
||||||
|
|
||||||
|
read -p "
|
||||||
|
|
||||||
|
Name the vpn server:
|
||||||
|
[algo.local]: " -r algo_server_name
|
||||||
|
algo_server_name=${algo_server_name:-algo.local}
|
||||||
|
|
||||||
|
read -p "
|
||||||
|
|
||||||
|
What region should the server be located in?
|
||||||
|
1. par1 Paris
|
||||||
|
2. ams1 Amsterdam
|
||||||
|
Enter the number of your desired region:
|
||||||
|
[1]: " -r algo_region
|
||||||
|
algo_region=${algo_region:-1}
|
||||||
|
|
||||||
|
case "$algo_region" in
|
||||||
|
1) region="par1" ;;
|
||||||
|
2) region="ams1" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
ROLES="scaleway vpn cloud"
|
||||||
|
EXTRA_VARS="scaleway_auth_token=$scaleway_auth_token scaleway_organization=\"$scaleway_organization\" algo_server_name=$algo_server_name algo_region=$region"
|
||||||
|
}
|
||||||
|
|
||||||
gce () {
|
gce () {
|
||||||
read -p "
|
read -p "
|
||||||
Enter the local path to your credentials JSON file (https://support.google.com/cloud/answer/6158849?hl=en&ref_topic=6262490#serviceaccounts):
|
Enter the local path to your credentials JSON file (https://support.google.com/cloud/answer/6158849?hl=en&ref_topic=6262490#serviceaccounts):
|
||||||
|
@ -494,7 +530,8 @@ algo_provisioning () {
|
||||||
3. Amazon EC2
|
3. Amazon EC2
|
||||||
4. Microsoft Azure
|
4. Microsoft Azure
|
||||||
5. Google Compute Engine
|
5. Google Compute Engine
|
||||||
6. Install to existing Ubuntu 16.04 server
|
6. Scaleway
|
||||||
|
7. Install to existing Ubuntu 16.04 server
|
||||||
|
|
||||||
Enter the number of your desired provider
|
Enter the number of your desired provider
|
||||||
: "
|
: "
|
||||||
|
@ -503,11 +540,12 @@ Enter the number of your desired provider
|
||||||
|
|
||||||
case "$N" in
|
case "$N" in
|
||||||
1) digitalocean; ;;
|
1) digitalocean; ;;
|
||||||
2) lightsail; ;;
|
2) lightsail; ;;
|
||||||
3) ec2; ;;
|
3) ec2; ;;
|
||||||
4) azure; ;;
|
4) azure; ;;
|
||||||
5) gce; ;;
|
5) gce; ;;
|
||||||
6) non_cloud; ;;
|
6) scaleway; ;;
|
||||||
|
7) non_cloud; ;;
|
||||||
*) exit 1 ;;
|
*) exit 1 ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
|
|
@ -89,6 +89,10 @@ cloud_providers:
|
||||||
lightsail:
|
lightsail:
|
||||||
size: nano_1_0
|
size: nano_1_0
|
||||||
image: ubuntu_16_04
|
image: ubuntu_16_04
|
||||||
|
scaleway:
|
||||||
|
size: VC1S
|
||||||
|
image: Ubuntu Xenial
|
||||||
|
arch: x86_64
|
||||||
local:
|
local:
|
||||||
|
|
||||||
fail_hint:
|
fail_hint:
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
- { role: cloud-gce, tags: ['gce'] }
|
- { role: cloud-gce, tags: ['gce'] }
|
||||||
- { role: cloud-azure, tags: ['azure'] }
|
- { role: cloud-azure, tags: ['azure'] }
|
||||||
- { role: cloud-lightsail, tags: ['lightsail'] }
|
- { role: cloud-lightsail, tags: ['lightsail'] }
|
||||||
|
- { role: cloud-scaleway, tags: ['scaleway'] }
|
||||||
- { role: local, tags: ['local'] }
|
- { role: local, tags: ['local'] }
|
||||||
|
|
||||||
post_tasks:
|
post_tasks:
|
||||||
|
@ -53,7 +54,7 @@
|
||||||
- block:
|
- block:
|
||||||
- name: Common pre-tasks
|
- name: Common pre-tasks
|
||||||
include_tasks: playbooks/common.yml
|
include_tasks: playbooks/common.yml
|
||||||
tags: [ 'digitalocean', 'ec2', 'gce', 'azure', 'lightsail', 'local', 'pre' ]
|
tags: [ 'digitalocean', 'ec2', 'gce', 'azure', 'lightsail', 'scaleway', 'local', 'pre' ]
|
||||||
rescue:
|
rescue:
|
||||||
- debug: var=fail_hint
|
- debug: var=fail_hint
|
||||||
tags: always
|
tags: always
|
||||||
|
|
128
roles/cloud-scaleway/tasks/main.yml
Normal file
128
roles/cloud-scaleway/tasks/main.yml
Normal file
|
@ -0,0 +1,128 @@
|
||||||
|
- block:
|
||||||
|
- name: Check if server exists
|
||||||
|
uri:
|
||||||
|
url: "https://cp-{{ algo_region }}.scaleway.com/servers"
|
||||||
|
method: GET
|
||||||
|
headers:
|
||||||
|
Content-Type: 'application/json'
|
||||||
|
X-Auth-Token: "{{ scaleway_auth_token }}"
|
||||||
|
status_code: 200
|
||||||
|
register: scaleway_servers
|
||||||
|
|
||||||
|
- name: Set server id as a fact
|
||||||
|
set_fact:
|
||||||
|
server_id: "{{ item.id }}"
|
||||||
|
no_log: true
|
||||||
|
when: algo_server_name == item.name
|
||||||
|
with_items: "{{ scaleway_servers.json.servers }}"
|
||||||
|
|
||||||
|
- name: Create a server if it doesn't exist
|
||||||
|
block:
|
||||||
|
- name: Get the organization id
|
||||||
|
uri:
|
||||||
|
url: https://account.cloud.online.net/organizations
|
||||||
|
method: GET
|
||||||
|
headers:
|
||||||
|
Content-Type: 'application/json'
|
||||||
|
X-Auth-Token: "{{ scaleway_auth_token }}"
|
||||||
|
status_code: 200
|
||||||
|
register: scaleway_organizations
|
||||||
|
|
||||||
|
- name: Set organization id as a fact
|
||||||
|
set_fact:
|
||||||
|
organization_id: "{{ item.id }}"
|
||||||
|
no_log: true
|
||||||
|
when: scaleway_organization == item.name
|
||||||
|
with_items: "{{ scaleway_organizations.json.organizations }}"
|
||||||
|
|
||||||
|
- name: Get images
|
||||||
|
uri:
|
||||||
|
url: "https://cp-{{ algo_region }}.scaleway.com/images"
|
||||||
|
method: GET
|
||||||
|
headers:
|
||||||
|
Content-Type: 'application/json'
|
||||||
|
X-Auth-Token: "{{ scaleway_auth_token }}"
|
||||||
|
status_code: 200
|
||||||
|
register: scaleway_images
|
||||||
|
|
||||||
|
- name: Set image id as a fact
|
||||||
|
set_fact:
|
||||||
|
image_id: "{{ item.id }}"
|
||||||
|
no_log: true
|
||||||
|
when:
|
||||||
|
- cloud_providers.scaleway.image in item.name
|
||||||
|
- cloud_providers.scaleway.arch == item.arch
|
||||||
|
with_items: "{{ scaleway_images.json.images }}"
|
||||||
|
|
||||||
|
- name: Create a server
|
||||||
|
uri:
|
||||||
|
url: "https://cp-{{ algo_region }}.scaleway.com/servers/"
|
||||||
|
method: POST
|
||||||
|
headers:
|
||||||
|
Content-Type: 'application/json'
|
||||||
|
X-Auth-Token: "{{ scaleway_auth_token }}"
|
||||||
|
body:
|
||||||
|
organization: "{{ organization_id }}"
|
||||||
|
name: "{{ algo_server_name }}"
|
||||||
|
image: "{{ image_id }}"
|
||||||
|
commercial_type: "{{cloud_providers.scaleway.size }}"
|
||||||
|
tags:
|
||||||
|
- Environment:Algo
|
||||||
|
- AUTHORIZED_KEY={{ lookup('file', SSH_keys.public)|regex_replace(' ', '_') }}
|
||||||
|
enable_ipv6: true
|
||||||
|
status_code: 201
|
||||||
|
body_format: json
|
||||||
|
register: algo_instance
|
||||||
|
|
||||||
|
- name: Set server id as a fact
|
||||||
|
set_fact:
|
||||||
|
server_id: "{{ algo_instance.json.server.id }}"
|
||||||
|
when: server_id is not defined
|
||||||
|
|
||||||
|
- name: Power on the server
|
||||||
|
uri:
|
||||||
|
url: https://cp-{{ algo_region }}.scaleway.com/servers/{{ server_id }}/action
|
||||||
|
method: POST
|
||||||
|
headers:
|
||||||
|
Content-Type: application/json
|
||||||
|
X-Auth-Token: "{{ scaleway_auth_token }}"
|
||||||
|
body:
|
||||||
|
action: poweron
|
||||||
|
status_code: 202
|
||||||
|
body_format: json
|
||||||
|
ignore_errors: true
|
||||||
|
no_log: true
|
||||||
|
|
||||||
|
- name: Wait for the server to become running
|
||||||
|
uri:
|
||||||
|
url: "https://cp-{{ algo_region }}.scaleway.com/servers/{{ server_id }}"
|
||||||
|
method: GET
|
||||||
|
headers:
|
||||||
|
Content-Type: 'application/json'
|
||||||
|
X-Auth-Token: "{{ scaleway_auth_token }}"
|
||||||
|
status_code: 200
|
||||||
|
until:
|
||||||
|
- algo_instance.json.server.state is defined
|
||||||
|
- algo_instance.json.server.state == "running"
|
||||||
|
retries: 20
|
||||||
|
delay: 30
|
||||||
|
register: algo_instance
|
||||||
|
|
||||||
|
- set_fact:
|
||||||
|
cloud_instance_ip: "{{ algo_instance['json']['server']['public_ip']['address'] }}"
|
||||||
|
|
||||||
|
- name: Add new instance to host group
|
||||||
|
add_host:
|
||||||
|
hostname: "{{ cloud_instance_ip }}"
|
||||||
|
groupname: vpn-host
|
||||||
|
ansible_ssh_user: root
|
||||||
|
ansible_python_interpreter: "/usr/bin/python2.7"
|
||||||
|
ansible_ssh_private_key_file: "{{ SSH_keys.private }}"
|
||||||
|
cloud_provider: scaleway
|
||||||
|
ipv6_support: yes
|
||||||
|
|
||||||
|
rescue:
|
||||||
|
- debug: var=fail_hint
|
||||||
|
tags: always
|
||||||
|
- fail:
|
||||||
|
tags: always
|
Loading…
Add table
Reference in a new issue