-
Notifications
You must be signed in to change notification settings - Fork 1
/
create-linode.yaml
82 lines (75 loc) · 2.7 KB
/
create-linode.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
# Creates a new Linode.
- name: Create Linode
hosts: localhost
gather_facts: false
connection: local
vars:
my_username: kenyon
swap_size: 2048
region: us-west
image: linode/debian11
linode_type: g6-nanode-1
retry_count: 10
delay_seconds: 5
vars_prompt:
- name: linode_label
prompt: New Linode label
private: false
tasks:
- name: Create Linode {{ linode_label }}
ansible.builtin.command: >-
linode-cli --json --no-defaults linodes create
--label {{ linode_label }}
--type {{ linode_type }}
--region {{ region }}
register: linode_create
changed_when: true
- name: Set facts of new Linode
ansible.builtin.set_fact:
linode_disk: "{{ (linode_create.stdout | from_json | first).specs.disk }}"
linode_id: "{{ (linode_create.stdout | from_json | first).id }}"
linode_ipv6: "{{ (linode_create.stdout | from_json | first).ipv6 }}"
- name: Create system disk for {{ linode_label }}
ansible.builtin.command: >-
linode-cli --json --no-defaults linodes disk-create {{ linode_id }}
--label system
--size {{ linode_disk | int - swap_size }}
--image {{ image }}
--authorized_users {{ my_username }}
--root_pass {{ lookup("password", "/dev/null") | quote }}
register: system_disk
retries: "{{ retry_count }}"
delay: "{{ delay_seconds }}"
until: system_disk is not failed
changed_when: true
- name: Create swap disk for {{ linode_label }}
ansible.builtin.command: >-
linode-cli --json --no-defaults linodes disk-create {{ linode_id }}
--label swap
--size {{ swap_size }}
--filesystem swap
register: swap_disk
retries: "{{ retry_count }}"
delay: "{{ delay_seconds }}"
until: swap_disk is not failed
changed_when: true
- name: Create configuration profile for {{ linode_label }}
ansible.builtin.command: >-
linode-cli --json --no-defaults linodes config-create {{ linode_id }}
--label config
--devices.sda.disk_id {{ (system_disk.stdout | from_json | first).id }}
--devices.sdb.disk_id {{ (swap_disk.stdout | from_json | first).id }}
--helpers.updatedb_disabled false
--helpers.network false
register: config_profile
retries: "{{ retry_count }}"
delay: "{{ delay_seconds }}"
until: config_profile is not failed
changed_when: true
- name: Boot {{ linode_label }}
ansible.builtin.command: linode-cli linodes boot {{ linode_id }}
changed_when: true
- name: Show IPv6 address
ansible.builtin.debug:
msg: "{{ linode_label }} address: {{ linode_ipv6 }}"