Add DigitalOcean playbook to create VM

pull/2317/head
Antoine Legrand 2017-02-20 16:51:48 +01:00 committed by Antoine Legrand
parent c0aad0a6d5
commit 442d211ee3
2 changed files with 96 additions and 0 deletions

View File

@ -0,0 +1,48 @@
---
- 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}}"

View File

@ -0,0 +1,48 @@
{% 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