add linode as one of cloud providers

This commit is contained in:
Larry Huang 2019-09-01 17:24:38 +08:00 committed by Jack Ivanov
parent b1d1491a66
commit cae6a0ea4a
5 changed files with 80 additions and 0 deletions

View file

@ -198,6 +198,9 @@ cloud_providers:
vultr:
os: Ubuntu 20.04 x64
size: 1024 MB RAM,25 GB SSD,1.00 TB BW
linode:
type: g6-nanode-1
image: linode/ubuntu19.04
local:
fail_hint:

View file

@ -21,6 +21,7 @@
- { name: Scaleway, alias: scaleway}
- { name: OpenStack (DreamCompute optimised), alias: openstack }
- { name: CloudStack (Exoscale optimised), alias: cloudstack }
- { name: Linode, alias: linode }
- { name: "Install to existing Ubuntu 18.04 or 20.04 server (for more advanced users)", alias: local }
vars_files:
- config.cfg

View file

@ -0,0 +1,2 @@
---
linode_venv: "{{ playbook_dir }}/configs/.venvs/linode"

View file

@ -0,0 +1,19 @@
---
- name: Include prompts
import_tasks: prompts.yml
- name: "Creating an instance..."
linode_v4:
access_token: "{{ algo_linode_token }}"
label: "{{ algo_server_name }}"
state: present
region: "{{ algo_linode_region }}"
image: "{{ cloud_providers.linode.image }}"
type: "{{ cloud_providers.linode.type }}"
authorized_keys: "{{ public_key }}"
root_pass: "{{ algo_linode_password }}"
register: _linode
- set_fact:
cloud_instance_ip: "{{ _linode.instance.ipv4[0] }}"
ansible_ssh_user: root

View file

@ -0,0 +1,55 @@
---
- pause:
prompt: |
Enter your ACCESS token. (https://developers.linode.com/api/v4/#access-and-authentication):
echo: false
register: _linode_token
when:
- linode_token is undefined
- lookup('env','LINODE_API_TOKEN')|length <= 0
- name: Set the token as a fact
set_fact:
algo_linode_token: "{{ linode_token | default(_linode_token.user_input|default(None)) | default(lookup('env','linode_API_TOKEN'), true) }}"
- name: Get regions
uri:
url: https://api.linode.com/v4/regions
method: GET
status_code: 200
register: _linode_regions
- name: Set facts about the regions
set_fact:
linode_regions: "{{ _linode_regions.json.data | sort(attribute='id') }}"
- name: Set default region
set_fact:
default_region: 1
- pause:
prompt: |
What region should the server be located in?
{% for r in linode_regions %}
{{ loop.index }}. {{ r['country'] }}
{% endfor %}
Enter the number of your desired region
[{{ default_region }}]
register: _algo_region
when: region is undefined
- pause:
prompt: |
Enter root password of this instance.
echo: false
register: _linode_root_password
- name: Set additional facts
set_fact:
algo_linode_region: >-
{% if region is defined %}{{ region }}
{%- elif _algo_region.user_input %}{{ linode_regions[_algo_region.user_input | int -1 ]['id'] }}
{%- else %}{{ linode_regions[default_region | int - 1]['id'] }}{% endif %}
algo_linode_password: "{{_linode_root_password.user_input}}"
public_key: "{{ lookup('file', '{{ SSH_keys.public }}') }}"