xoxys.hcloud_server/tasks/setup.yml

59 lines
2.0 KiB
YAML
Raw Normal View History

2020-05-17 18:19:07 +00:00
---
- name: Provisioning VM '{{ hcloud_server.name }}'
hcloud_server:
name: "{{ hcloud_server.name }}"
server_type: "{{ hcloud_server.type | default('cx11') }}"
ssh_keys: "{{ hcloud_server.ssh_keys | default([]) }}"
image: "{{ hcloud_server.image | default('centos-7') }}"
location: "{{ hcloud_server.location | default('nbg1') }}"
2020-05-17 21:01:48 +00:00
backups: "{{ hcloud_server.backups | default('no') }}"
2020-05-17 21:05:18 +00:00
labels: "{{ hcloud_server.labels | default({}) }}"
2020-05-17 18:43:29 +00:00
api_token: "{{ hcloud_server.api_token | default(hcloud_server_default_api_token | default(omit)) }}"
2020-05-17 18:19:07 +00:00
state: present
2020-05-17 20:37:57 +00:00
changed_when: False
2020-05-17 18:19:07 +00:00
register: __hcloud_server
async: 7200
poll: 0
delegate_to: localhost
- name: Wait for instance creation to complete
async_status:
2020-05-17 20:19:24 +00:00
jid: "{{ __hcloud_server.ansible_job_id }}"
2020-05-17 18:19:07 +00:00
register: __hcloud_job
2020-05-17 20:20:55 +00:00
until: __hcloud_job.finished
2020-05-17 18:19:07 +00:00
retries: 300
delegate_to: localhost
- name: Populate instance config
set_fact:
hcloud_instance: {
'instance': "{{ __hcloud_job.hcloud_server.name }}",
'ipv4': "{{ __hcloud_job.hcloud_server.ipv4_address }}",
'ipv6': "{{ __hcloud_job.hcloud_server.ipv6 }}",
}
2020-05-17 20:19:24 +00:00
delegate_to: localhost
2020-05-17 18:19:07 +00:00
- name: Create volumes
hcloud_volume:
name: "{{ item.name }}"
server: "{{ hcloud_server.name }}"
size: "{{ item.size | default(10) }}"
api_token: "{{ item.api_token | default(hcloud_server_default_api_token | default(omit)) }}"
2020-05-17 18:19:07 +00:00
state: "{{ item.state | default('present') }}"
loop: "{{ hcloud_server_volumes }}"
loop_control:
2020-05-17 20:41:32 +00:00
label: "{{ hcloud_server.name }}:{{ item.name }}"
2020-05-17 18:19:07 +00:00
delegate_to: localhost
- name: Create reverse DNS entries
hcloud_rdns:
server: "{{ hcloud_server.name }}"
ip_address: "{{ item.addr }}"
dns_ptr: "{{ item.ptr }}"
api_token: "{{ item.api_token | default(hcloud_server_default_api_token | default(omit)) }}"
2020-05-17 18:19:07 +00:00
state: "{{ item.state | default('present') }}"
loop: "{{ hcloud_server_rdns }}"
loop_control:
2020-05-17 20:41:32 +00:00
label: "{{ hcloud_server.name }}:{{ item.ptr }}"
2020-05-17 18:19:07 +00:00
delegate_to: localhost