mirror of
https://github.com/trailofbits/algo.git
synced 2025-08-02 02:43:01 +02:00
DigitalOcean: move to the latest modules
This commit is contained in:
parent
866149a147
commit
251d105d6d
4 changed files with 33 additions and 116 deletions
|
@ -1,2 +0,0 @@
|
|||
---
|
||||
digitalocean_venv: "{{ playbook_dir }}/configs/.venvs/digitalocean"
|
|
@ -1,105 +1,30 @@
|
|||
---
|
||||
- name: Build python virtual environment
|
||||
import_tasks: venv.yml
|
||||
- name: Include prompts
|
||||
import_tasks: prompts.yml
|
||||
|
||||
- block:
|
||||
- name: Include prompts
|
||||
import_tasks: prompts.yml
|
||||
- name: "Upload the SSH key"
|
||||
digital_ocean_sshkey:
|
||||
oauth_token: "{{ algo_do_token }}"
|
||||
name: "{{ SSH_keys.comment }}"
|
||||
ssh_pub_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
|
||||
register: do_ssh_key
|
||||
|
||||
- name: Set additional facts
|
||||
set_fact:
|
||||
algo_do_region: >-
|
||||
{% if region is defined %}{{ region }}
|
||||
{%- elif _algo_region.user_input %}{{ do_regions[_algo_region.user_input | int -1 ]['slug'] }}
|
||||
{%- else %}{{ do_regions[default_region | int - 1]['slug'] }}{% endif %}
|
||||
public_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}"
|
||||
- name: "Creating a droplet..."
|
||||
digital_ocean_droplet:
|
||||
state: present
|
||||
name: "{{ algo_server_name }}"
|
||||
oauth_token: "{{ algo_do_token }}"
|
||||
size: "{{ cloud_providers.digitalocean.size }}"
|
||||
region: "{{ algo_do_region }}"
|
||||
image: "{{ cloud_providers.digitalocean.image }}"
|
||||
wait_timeout: 300
|
||||
unique_name: true
|
||||
ipv6: true
|
||||
ssh_keys: "{{ do_ssh_key.data.ssh_key.id }}"
|
||||
tags:
|
||||
- Environment:Algo
|
||||
register: digital_ocean_droplet
|
||||
|
||||
- block:
|
||||
- name: "Delete the existing Algo SSH keys"
|
||||
digital_ocean:
|
||||
state: absent
|
||||
command: ssh
|
||||
api_token: "{{ algo_do_token }}"
|
||||
name: "{{ SSH_keys.comment }}"
|
||||
register: ssh_keys
|
||||
until: not ssh_keys.changed
|
||||
retries: 10
|
||||
delay: 1
|
||||
|
||||
rescue:
|
||||
- name: Collect the fail error
|
||||
digital_ocean:
|
||||
state: absent
|
||||
command: ssh
|
||||
api_token: "{{ algo_do_token }}"
|
||||
name: "{{ SSH_keys.comment }}"
|
||||
register: ssh_keys
|
||||
ignore_errors: yes
|
||||
|
||||
- debug: var=ssh_keys
|
||||
|
||||
- fail:
|
||||
msg: "Please, ensure that your API token is not read-only."
|
||||
|
||||
- name: "Upload the SSH key"
|
||||
digital_ocean:
|
||||
state: present
|
||||
command: ssh
|
||||
ssh_pub_key: "{{ public_key }}"
|
||||
api_token: "{{ algo_do_token }}"
|
||||
name: "{{ SSH_keys.comment }}"
|
||||
register: do_ssh_key
|
||||
|
||||
- name: "Creating a droplet..."
|
||||
digital_ocean:
|
||||
state: present
|
||||
command: droplet
|
||||
name: "{{ algo_server_name }}"
|
||||
region_id: "{{ algo_do_region }}"
|
||||
size_id: "{{ cloud_providers.digitalocean.size }}"
|
||||
image_id: "{{ cloud_providers.digitalocean.image }}"
|
||||
ssh_key_ids: "{{ do_ssh_key.ssh_key.id }}"
|
||||
unique_name: yes
|
||||
api_token: "{{ algo_do_token }}"
|
||||
ipv6: yes
|
||||
register: do
|
||||
|
||||
- set_fact:
|
||||
cloud_instance_ip: "{{ do.droplet.ip_address }}"
|
||||
ansible_ssh_user: root
|
||||
|
||||
- name: Tag the droplet
|
||||
digital_ocean_tag:
|
||||
name: "Environment:Algo"
|
||||
resource_id: "{{ do.droplet.id }}"
|
||||
api_token: "{{ algo_do_token }}"
|
||||
state: present
|
||||
|
||||
- block:
|
||||
- name: "Delete the new Algo SSH key"
|
||||
digital_ocean:
|
||||
state: absent
|
||||
command: ssh
|
||||
api_token: "{{ algo_do_token }}"
|
||||
name: "{{ SSH_keys.comment }}"
|
||||
register: ssh_keys
|
||||
until: not ssh_keys.changed
|
||||
retries: 10
|
||||
delay: 1
|
||||
|
||||
rescue:
|
||||
- name: Collect the fail error
|
||||
digital_ocean:
|
||||
state: absent
|
||||
command: ssh
|
||||
api_token: "{{ algo_do_token }}"
|
||||
name: "{{ SSH_keys.comment }}"
|
||||
register: ssh_keys
|
||||
ignore_errors: yes
|
||||
|
||||
- debug: var=ssh_keys
|
||||
|
||||
- fail:
|
||||
msg: "Please, ensure that your API token is not read-only."
|
||||
environment:
|
||||
PYTHONPATH: "{{ digitalocean_venv }}/lib/python2.7/site-packages/"
|
||||
- set_fact:
|
||||
cloud_instance_ip: "{{ digital_ocean_droplet.data.ip_address }}"
|
||||
ansible_ssh_user: root
|
||||
|
|
|
@ -44,3 +44,10 @@
|
|||
[{{ default_region }}]
|
||||
register: _algo_region
|
||||
when: region is undefined
|
||||
|
||||
- name: Set additional facts
|
||||
set_fact:
|
||||
algo_do_region: >-
|
||||
{% if region is defined %}{{ region }}
|
||||
{%- elif _algo_region.user_input %}{{ do_regions[_algo_region.user_input | int -1 ]['slug'] }}
|
||||
{%- else %}{{ do_regions[default_region | int - 1]['slug'] }}{% endif %}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
---
|
||||
- name: Clean up the environment
|
||||
file:
|
||||
dest: "{{ digitalocean_venv }}"
|
||||
state: absent
|
||||
when: clean_environment
|
||||
|
||||
- name: Install requirements
|
||||
pip:
|
||||
name: dopy
|
||||
version: 0.3.5
|
||||
virtualenv: "{{ digitalocean_venv }}"
|
||||
virtualenv_python: python2.7
|
Loading…
Add table
Reference in a new issue