Skip to content
Snippets Groups Projects
Commit 442d211e authored by Antoine Legrand's avatar Antoine Legrand Committed by Antoine Legrand
Browse files

Add DigitalOcean playbook to create VM

parent c0aad0a6
No related branches found
No related tags found
No related merge requests found
---
- hosts: localhost
become: false
gather_facts: no
vars:
cloud_machine_type: g1-small
mode: default
tasks:
- name: replace_test_id
set_fact:
test_name: "{{test_id |regex_replace('\\.', '-')}}"
- set_fact:
instance_names: >-
{%- if mode in ['separate', 'ha'] -%}
["k8s-{{test_name}}-1", "k8s-{{test_name}}-2", "k8s-{{test_name}}-3"]
{%- else -%}
["k8s-{{test_name}}-1", "k8s-{{test_name}}-2"]
{%- endif -%}
- name: Create DO instances
digital_ocean:
unique_name: yes
api_token: "{{ lookup('env','DO_API_TOKEN') }}"
command: "droplet"
image_id: "{{ cloud_image }}"
name: "{{ item }}"
private_networking: no
region_id: "{{cloud_region}}"
size_id: 2gb
ssh_key_ids: "6536865"
state: present
wait: yes
register: droplets
with_items: "{{instance_names}}"
- debug:
msg: "{{droplets}}, {{inventory_path}}"
- name: Template the inventory
template:
src: ../templates/inventory-do.j2
dest: "{{ inventory_path }}/inventory-do.cfg"
- name: Wait for SSH to come up
wait_for: host={{item.droplet.ip_address}} port=22 delay=10 timeout=180 state=started
with_items: "{{droplets.results}}"
{% for instance in droplets.results %}
node{{loop.index}} ansible_ssh_host={{instance.droplet.ip_address}}
{% endfor %}
{% if mode is defined and mode == "separate" %}
[kube-master]
node1
[kube-node]
node2
[etcd]
node3
[vault]
node3
{% elif mode is defined and mode == "ha" %}
[kube-master]
node1
node2
[kube-node]
node3
[etcd]
node2
node3
[vault]
node2
node3
{% else %}
[kube-master]
node1
[kube-node]
node2
[etcd]
node1
[vault]
node1
{% endif %}
[k8s-cluster:children]
kube-node
kube-master
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment