hcloud-server-exists

Description

Create a server with the specified name/id exists in your Hetzner hcloud account, if it doesn't exist yet.

If a server exists, nothing is done, even if the 'image' and 'server_type' are different to the deployed server.

Variables

Name Type Default Description

api_token

string --

The hcloud API token. Required

server_name

string --

The name of the cloud server to manage (for now, don't use '_', '-', or other special characters in the server name -- will be fixed later). Required

extra_wait_time

integer 0

Extra wait time after ssh is ready.

image

string ubuntu-18.04

The OS image of the server.

register_target

string _register_hcloud_server

The name of the variable to register the result of this frecklet.

server_type

string cx11

The type of server to create.

ssh_keys

list --

List of SSH key names that correspond to the SSH keys configured for your Hetzner Cloud account access.

wait_for_ssh

boolean True

Whether to wait for ssh to become available

Code

doc:
  short_help: Create a server with the specified name/id exists in your Hetzner hcloud
    account.
  help: |
    Create a server with the specified name/id exists in your Hetzner hcloud account, if it doesn't exist yet.

    If a server exists, nothing is done, even if the 'image' and 'server_type' are different to the deployed server.
args:
  api_token:
    doc:
      short_help: The hcloud API token.
    type: string
    required: true
    secret: true
  server_name:
    doc:
      short_help: The name of the cloud server to manage (for now, don't use '_',
        '-', or other special characters in the server name -- will be fixed later).
    type: string
    required: true
  register_target:
    doc:
      short_help: The name of the variable to register the result of this frecklet.
    type: string
    required: false
    default: _register_hcloud_server
    cli:
      metavar: VAR_NAME
  server_type:
    doc:
      short_help: The type of server to create.
    type: string
    allowed:
    - cx11
    - cx21
    - cx31
    - cx41
    - cx51
    - cx11-ceph
    - cx21-ceph
    - cx31-ceph
    - cx41-ceph
    - cx51-ceph
    - ccx11
    - ccx21
    - ccx31
    - ccx41
    - ccx51
    default: cx11
  image:
    doc:
      short_help: The OS image of the server.
    type: string
    required: false
    default: ubuntu-18.04
  wait_for_ssh:
    doc:
      short_help: Whether to wait for ssh to become available
    type: boolean
    required: false
    default: true
  extra_wait_time:
    doc:
      short_help: Extra wait time after ssh is ready.
    type: integer
    required: false
    default: 0
  ssh_keys:
    doc:
      short_help: List of SSH key names that correspond to the SSH keys configured
        for your Hetzner Cloud account access.
    type: list
    schema:
      type: string
    required: false
    empty: true
    cli:
      param_decls:
      - --ssh-key
frecklets:
- frecklet:
    name: hcloud_server
    type: ansible-module
    register:
      target: '{{:: register_target ::}}'
      value: '{{ __result__.hcloud_server }}'
    properties:
      elevated: false
      internet: true
      idempotent: true
    resources:
      python-package:
      - hcloud
  task:
    become: false
  vars:
    api_token: '{{:: api_token ::}}'
    name: '{{:: server_name ::}}'
    server_type: '{{:: server_type ::}}'
    image: '{{:: image ::}}'
    ssh_keys: '{{:: ssh_keys ::}}'
    state: present
- wait-for-ssh:
    frecklet::skip: '{{:: wait_for_ssh | negate ::}}'
    host: '{{ {{:: register_target ::}}.hcloud_server.ipv4_address }}'
    extra_wait_time: '{{:: extra_wait_time ::}}'
frecklecute --community hcloud-server-exists --help

Usage: frecklecute hcloud-server-exists [OPTIONS]

  Create a server with the specified name/id exists in your Hetzner hcloud
  account, if it doesn't exist yet.

  If a server exists, nothing is done, even if the 'image' and 'server_type'
  are different to the deployed server.

Options:
  --api-token API_TOKEN           The hcloud API token.  [required]
  --server-name SERVER_NAME       The name of the cloud server to manage (for
                                  now, don't use '_', '-', or other special
                                  characters in the server name -- will be
                                  fixed later).  [required]
  --extra-wait-time EXTRA_WAIT_TIME
                                  Extra wait time after ssh is ready.
  --image IMAGE                   The OS image of the server.
  --register-target VAR_NAME      The name of the variable to register the
                                  result of this frecklet.
  --server-type SERVER_TYPE       The type of server to create.
  --ssh-key SSH_KEYS              List of SSH key names that correspond to the
                                  SSH keys configured for your Hetzner Cloud
                                  account access.
  --wait-for-ssh / --no-wait-for-ssh
                                  Whether to wait for ssh to become available
  --help                          Show this message and exit.
# -*- coding: utf-8 -*-


#
# module path: pycklets.hcloud_server_exists.HcloudServerExists
#


from dataclasses import dataclass
from pyckles import AutoPycklet
from typing import *    # noqa

@dataclass
class HcloudServerExists(AutoPycklet):
    """Create a server with the specified name/id exists in your Hetzner hcloud account, if it doesn't exist yet.

     If a server exists, nothing is done, even if the 'image' and 'server_type' are different to the deployed server.

       Args:
         api_token: The hcloud API token.
         extra_wait_time: Extra wait time after ssh is ready.
         image: The OS image of the server.
         register_target: The name of the variable to register the result of this frecklet.
         server_name: The name of the cloud server to manage (for now, don't use '_', '-', or other special characters in the server name -- will be fixed later).
         server_type: The type of server to create.
         ssh_keys: List of SSH key names that correspond to the SSH keys configured for your Hetzner Cloud account access.
         wait_for_ssh: Whether to wait for ssh to become available

    """

    FRECKLET_ID = "hcloud-server-exists"

    api_token: str = None
    extra_wait_time: int = None
    image: str = None
    register_target: str = None
    server_name: str = None
    server_type: str = None
    ssh_keys: List = None
    wait_for_ssh: bool = None


    def __post_init__(self):
        super(HcloudServerExists, self).__init__(var_names=["api_token", "extra_wait_time", "image", "register_target", "server_name", "server_type", "ssh_keys", "wait_for_ssh"])


frecklet_class = HcloudServerExists
# -*- coding: utf-8 -*-


#
# module path: pycklets.hcloud_server_exists.HcloudServerExists
#


from pyckles import AutoPycklet

class HcloudServerExists(AutoPycklet):
    """Create a server with the specified name/id exists in your Hetzner hcloud account, if it doesn't exist yet.

     If a server exists, nothing is done, even if the 'image' and 'server_type' are different to the deployed server.

       Args:
         api_token: The hcloud API token.
         extra_wait_time: Extra wait time after ssh is ready.
         image: The OS image of the server.
         register_target: The name of the variable to register the result of this frecklet.
         server_name: The name of the cloud server to manage (for now, don't use '_', '-', or other special characters in the server name -- will be fixed later).
         server_type: The type of server to create.
         ssh_keys: List of SSH key names that correspond to the SSH keys configured for your Hetzner Cloud account access.
         wait_for_ssh: Whether to wait for ssh to become available

    """

    FRECKLET_ID = "hcloud-server-exists"

    def __init__(self, api_token=None, extra_wait_time=None, image="ubuntu-18.04", register_target="_register_hcloud_server", server_name=None, server_type="cx11", ssh_keys=None, wait_for_ssh=True):

        super(HcloudServerExists, self).__init__(var_names=["api_token", "extra_wait_time", "image", "register_target", "server_name", "server_type", "ssh_keys", "wait_for_ssh"])
        self._api_token = api_token
        self._extra_wait_time = extra_wait_time
        self._image = image
        self._register_target = register_target
        self._server_name = server_name
        self._server_type = server_type
        self._ssh_keys = ssh_keys
        self._wait_for_ssh = wait_for_ssh

    @property
    def api_token(self):
        return self._api_token

    @api_token.setter
    def api_token(self, api_token):
        self._api_token = api_token

    @property
    def extra_wait_time(self):
        return self._extra_wait_time

    @extra_wait_time.setter
    def extra_wait_time(self, extra_wait_time):
        self._extra_wait_time = extra_wait_time

    @property
    def image(self):
        return self._image

    @image.setter
    def image(self, image):
        self._image = image

    @property
    def register_target(self):
        return self._register_target

    @register_target.setter
    def register_target(self, register_target):
        self._register_target = register_target

    @property
    def server_name(self):
        return self._server_name

    @server_name.setter
    def server_name(self, server_name):
        self._server_name = server_name

    @property
    def server_type(self):
        return self._server_type

    @server_type.setter
    def server_type(self, server_type):
        self._server_type = server_type

    @property
    def ssh_keys(self):
        return self._ssh_keys

    @ssh_keys.setter
    def ssh_keys(self, ssh_keys):
        self._ssh_keys = ssh_keys

    @property
    def wait_for_ssh(self):
        return self._wait_for_ssh

    @wait_for_ssh.setter
    def wait_for_ssh(self, wait_for_ssh):
        self._wait_for_ssh = wait_for_ssh



frecklet_class = HcloudServerExists