xoxys.hcloud_server/tasks/setup.yml
Robert Kaussow cc424171f7
All checks were successful
continuous-integration/drone/push Build is passing
feat: add task to attach host to local networks
2021-03-28 13:02:30 +02:00

73 lines
2.6 KiB
YAML

---
- 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(hcloud_server_default_ssh_keys) }}"
image: "{{ hcloud_server.image | default(hcloud_server_default_image) }}"
location: "{{ hcloud_server.location | default(hcloud_server_default_location) }}"
backups: "{{ hcloud_server.backups | default(hcloud_server_default_backup) }}"
delete_protection: "{{ hcloud_server.protection | default(hcloud_server_default_protection) }}"
rebuild_protection: "{{ hcloud_server.protection | default(hcloud_server_default_protection) }}"
labels: "{{ hcloud_server.labels | default({}) }}"
api_token: "{{ hcloud_server.api_token | default(hcloud_server_default_api_token | default(omit)) }}"
state: present
changed_when: False
register: __hcloud_server
async: 7200
poll: 0
delegate_to: localhost
- name: Wait for instance creation to complete
async_status:
jid: "{{ __hcloud_server.ansible_job_id }}"
register: __hcloud_job
until: __hcloud_job.finished
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 }}",
}
delegate_to: localhost
- name: Attach server to local networks
hcloud_server_network:
network: "{{ item.name }}"
server: "{{ hcloud_server.name }}"
ip: "{{ item.ip }}"
state: "{{ item.state | default('present') }}"
loop: "{{ hcloud_server_networks }}"
loop_control:
label: "{{ hcloud_server.name }}:{{ item.name }}"
delegate_to: localhost
- name: Create volumes
hcloud_volume:
name: "{{ item.name }}"
server: "{{ hcloud_server.name }}"
size: "{{ item.size | default(10) }}"
api_token: "{{ hcloud_server.api_token | default(hcloud_server_default_api_token | default(omit)) }}"
state: "{{ item.state | default('present') }}"
loop: "{{ hcloud_server_volumes }}"
loop_control:
label: "{{ hcloud_server.name }}:{{ item.name }}"
delegate_to: localhost
- name: Create reverse DNS entries
hcloud_rdns:
server: "{{ hcloud_server.name }}"
ip_address: "{{ item.addr }}"
dns_ptr: "{{ item.ptr }}"
api_token: "{{ hcloud_server.api_token | default(hcloud_server_default_api_token | default(omit)) }}"
state: "{{ item.state | default('present') }}"
loop: "{{ hcloud_server_rdns }}"
loop_control:
label: "{{ hcloud_server.name }}:{{ item.ptr }}"
delegate_to: localhost