1 Home
Markus Bergholz edited this page 9 months ago

Deploy an Instance and set a DNS record

---
- hosts: localhost
  connection: local
  gather_facts: no

  tasks:
    - name: Create a basic server
      hcloud_server:
        api_token: "{{ HCLOUD_TOKEN }}"
        name: my-server
        server_type: cx11
        image: ubuntu-18.04
        state: present
      register: INSTANCE

    - name: add record for my-server
      markuman.hetzner_dns.record:
        api_token: "{{ DNS_TOKEN }}"
        zone_name: osuv.de
        name: my-server
        value: "{{ INSTANCE.hcloud_server.ipv4_address }}"
        type: A
        ttl: 300

output

[m@nuc tests]$ ansible-playbook instance_test.yml 
[WARNING]: No inventory was parsed, only implicit localhost is available
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

PLAY [localhost] ******************************************************************************************************************************************************************************************************************************************************

TASK [Create a basic server] ******************************************************************************************************************************************************************************************************************************************
changed: [localhost]

TASK [add record for my-server] ***************************************************************************************************************************************************************************************************************************************
changed: [localhost]

PLAY RECAP ************************************************************************************************************************************************************************************************************************************************************
localhost                  : ok=2    changed=2    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0   

[m@nuc tests]$ host my-server.osuv.de
my-server.osuv.de has address 168.119.55.134
[m@nuc tests]$