2017-02-20 23:51:48 +08:00
|
|
|
---
|
|
|
|
- hosts: localhost
|
|
|
|
become: false
|
|
|
|
gather_facts: no
|
|
|
|
vars:
|
2017-02-22 21:27:30 +08:00
|
|
|
state: "present"
|
|
|
|
ssh_key_id: "6536865"
|
|
|
|
cloud_machine_type: 2gb
|
|
|
|
regions:
|
|
|
|
- nyc1
|
|
|
|
- sfo1
|
|
|
|
- nyc2
|
|
|
|
- ams2
|
|
|
|
- sgp1
|
|
|
|
- lon1
|
|
|
|
- nyc3
|
|
|
|
- ams3
|
|
|
|
- fra1
|
|
|
|
- tor1
|
|
|
|
- sfo2
|
|
|
|
- blr1
|
|
|
|
cloud_images:
|
|
|
|
- coreos-beta
|
|
|
|
- fedora-24-x64
|
|
|
|
- centos-5-x64
|
|
|
|
- centos-5-x32
|
|
|
|
- fedora-25-x64
|
|
|
|
- debian-7-x64
|
|
|
|
- debian-7-x32
|
|
|
|
- debian-8-x64
|
|
|
|
- debian-8-x32
|
|
|
|
- centos-6-x32
|
|
|
|
- centos-6-x64
|
|
|
|
- coreos-stable
|
|
|
|
- ubuntu-16-10-x32
|
|
|
|
- ubuntu-16-10-x64
|
|
|
|
- freebsd-11-0-x64-zfs
|
|
|
|
- freebsd-10-3-x64-zfs
|
|
|
|
- coreos-alpha
|
|
|
|
- ubuntu-12-04-x32
|
|
|
|
- ubuntu-12-04-x64
|
|
|
|
- ubuntu-16-04-x64
|
|
|
|
- ubuntu-16-04-x32
|
|
|
|
- ubuntu-14-04-x64
|
|
|
|
- ubuntu-14-04-x32
|
|
|
|
- centos-7-x64
|
|
|
|
- freebsd-11-0-x64
|
|
|
|
- freebsd-10-3-x64
|
|
|
|
- centos-7-3-1611-x64
|
2017-02-20 23:51:48 +08:00
|
|
|
mode: default
|
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: replace_test_id
|
|
|
|
set_fact:
|
2019-05-03 05:24:21 +08:00
|
|
|
test_name: "{{ test_id |regex_replace('\\.', '-') }}"
|
2017-02-20 23:51:48 +08:00
|
|
|
|
2018-02-12 21:28:59 +08:00
|
|
|
- name: show vars
|
2019-05-03 05:24:21 +08:00
|
|
|
debug: msg="{{ cloud_region }}, {{ cloud_image }}"
|
2018-02-12 21:28:59 +08:00
|
|
|
|
2017-02-20 23:51:48 +08:00
|
|
|
- set_fact:
|
|
|
|
instance_names: >-
|
|
|
|
{%- if mode in ['separate', 'ha'] -%}
|
2019-05-03 05:24:21 +08:00
|
|
|
["k8s-{{ test_name }}-1", "k8s-{{ test_name }}-2", "k8s-{{ test_name }}-3"]
|
2017-02-20 23:51:48 +08:00
|
|
|
{%- else -%}
|
2019-05-03 05:24:21 +08:00
|
|
|
["k8s-{{ test_name }}-1", "k8s-{{ test_name }}-2"]
|
2017-02-20 23:51:48 +08:00
|
|
|
{%- endif -%}
|
|
|
|
|
2019-05-03 05:24:21 +08:00
|
|
|
- name: Manage DO instances | {{ state }}
|
2017-02-20 23:51:48 +08:00
|
|
|
digital_ocean:
|
|
|
|
unique_name: yes
|
|
|
|
api_token: "{{ lookup('env','DO_API_TOKEN') }}"
|
|
|
|
command: "droplet"
|
|
|
|
image_id: "{{ cloud_image }}"
|
|
|
|
name: "{{ item }}"
|
|
|
|
private_networking: no
|
2019-05-03 05:24:21 +08:00
|
|
|
region_id: "{{ cloud_region }}"
|
|
|
|
size_id: "{{ cloud_machine_type }}"
|
|
|
|
ssh_key_ids: "{{ ssh_key_id }}"
|
|
|
|
state: "{{ state }}"
|
2017-02-20 23:51:48 +08:00
|
|
|
wait: yes
|
|
|
|
register: droplets
|
2019-05-03 05:24:21 +08:00
|
|
|
with_items: "{{ instance_names }}"
|
2017-02-20 23:51:48 +08:00
|
|
|
|
|
|
|
- debug:
|
2019-05-03 05:24:21 +08:00
|
|
|
msg: "{{ droplets }}, {{ inventory_path }}"
|
2018-10-11 15:45:00 +08:00
|
|
|
when: state == 'present'
|
2017-02-20 23:51:48 +08:00
|
|
|
|
|
|
|
- name: Template the inventory
|
|
|
|
template:
|
|
|
|
src: ../templates/inventory-do.j2
|
2017-02-22 21:27:30 +08:00
|
|
|
dest: "{{ inventory_path }}"
|
2018-10-11 15:45:00 +08:00
|
|
|
when: state == 'present'
|