cloudscale_ch.cloud.server (2.3.1) — module

Manages servers on the cloudscale.ch IaaS service

| "added in version" 1.0.0 of cloudscale_ch.cloud"

Authors: Gaudenz Steinlin (@gaudenz), René Moser (@resmo), Denis Krienbühl (@href)

Install collection

Install with ansible-galaxy collection install cloudscale_ch.cloud:==2.3.1


Add to requirements.yml

  collections:
    - name: cloudscale_ch.cloud
      version: 2.3.1

Description

Create, update, start, stop and delete servers on the cloudscale.ch IaaS service.

Usage examples

  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Create and start a server with an existing server group (shiny-group)
- name: Start cloudscale.ch server
  cloudscale_ch.cloud.server:
    name: my-shiny-cloudscale-server
    image: debian-10
    flavor: flex-4-4
    ssh_keys:
      - ssh-rsa XXXXXXXXXX...XXXX ansible@cloudscale
    server_groups: shiny-group
    zone: lpg1
    use_private_network: true
    bulk_volume_size_gb: 100
    api_token: xxxxxx
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Start another server in anti-affinity (server group shiny-group)
- name: Start second cloudscale.ch server
  cloudscale_ch.cloud.server:
    name: my-other-shiny-server
    image: ubuntu-16.04
    flavor: flex-8-2
    ssh_keys:
      - ssh-rsa XXXXXXXXXX...XXXX ansible@cloudscale
    server_groups: shiny-group
    zone: lpg1
    api_token: xxxxxx
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Force to update the flavor of a running server
- name: Start cloudscale.ch server
  cloudscale_ch.cloud.server:
    name: my-shiny-cloudscale-server
    image: debian-10
    flavor: flex-8-2
    force: true
    ssh_keys:
      - ssh-rsa XXXXXXXXXX...XXXX ansible@cloudscale
    use_private_network: true
    bulk_volume_size_gb: 100
    api_token: xxxxxx
  register: server1
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Stop the first server
- name: Stop my first server
  cloudscale_ch.cloud.server:
    uuid: '{{ server1.uuid }}'
    state: stopped
    api_token: xxxxxx
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Delete my second server
- name: Delete my second server
  cloudscale_ch.cloud.server:
    name: my-other-shiny-server
    state: absent
    api_token: xxxxxx
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Start a server and wait for the SSH host keys to be generated
- name: Start server and wait for SSH host keys
  cloudscale_ch.cloud.server:
    name: my-cloudscale-server-with-ssh-key
    image: debian-10
    flavor: flex-4-2
    ssh_keys:
      - ssh-rsa XXXXXXXXXX...XXXX ansible@cloudscale
    api_token: xxxxxx
  register: server
  until: server is not failed
  retries: 5
  delay: 2
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Start a server with two network interfaces:
#
#    A public interface with IPv4/IPv6
#    A private interface on a specific private network with an IPv4 address

- name: Start a server with a public and private network interface
  cloudscale_ch.cloud.server:
    name: my-cloudscale-server-with-two-network-interfaces
    image: debian-10
    flavor: flex-4-2
    ssh_keys:
      - ssh-rsa XXXXXXXXXX...XXXX ansible@cloudscale
    api_token: xxxxxx
    interfaces:
      - network: 'public'
      - addresses:
        - subnet: UUID_of_private_subnet
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Start a server with a specific IPv4 address from subnet range
- name: Start a server with a specific IPv4 address from subnet range
  cloudscale_ch.cloud.server:
    name: my-cloudscale-server-with-specific-address
    image: debian-10
    flavor: flex-4-2
    ssh_keys:
      - ssh-rsa XXXXXXXXXX...XXXX ansible@cloudscale
    api_token: xxxxxx
    interfaces:
      - addresses:
        - subnet: UUID_of_private_subnet
          address: 'A.B.C.D'
  • Success
    Steampunk Spotter scan finished with no errors, warnings or hints.
# Start a server with two network interfaces:
#
#    A public interface with IPv4/IPv6
#    A private interface on a specific private network with no IPv4 address

- name: Start a server with a private network interface and no IP address
  cloudscale_ch.cloud.server:
    name: my-cloudscale-server-with-specific-address
    image: debian-10
    flavor: flex-4-2
    ssh_keys:
      - ssh-rsa XXXXXXXXXX...XXXX ansible@cloudscale
    api_token: xxxxxx
    interfaces:
      - network: 'public'
      - network: UUID_of_private_network
        addresses: []

Inputs

    
name:
    description:
    - Name of the Server.
    - Either I(name) or I(uuid) are required.
    type: str

tags:
    description:
    - Tags assosiated with the servers. Set this to C({}) to clear any tags.
    type: dict

uuid:
    description:
    - UUID of the server.
    - Either I(name) or I(uuid) are required.
    type: str

zone:
    description:
    - Zone in which the server resides (e.g. C(lpg1) or C(rma1)).
    type: str

force:
    default: false
    description:
    - Allow to stop the running server for updating if necessary.
    type: bool

image:
    description:
    - Image used to create the server.
    type: str

state:
    choices:
    - running
    - stopped
    - absent
    default: running
    description:
    - State of the server.
    type: str

flavor:
    description:
    - Flavor of the server.
    type: str

api_url:
    default: https://api.cloudscale.ch/v1
    description:
    - cloudscale.ch API URL.
    - This can also be passed in the C(CLOUDSCALE_API_URL) environment variable.
    type: str
    version_added: 1.3.0
    version_added_collection: cloudscale_ch.cloud

password:
    description:
    - Password for the server.
    type: str

ssh_keys:
    description:
    - List of SSH public keys.
    - Use the full content of your .pub file here.
    elements: str
    type: list

use_ipv6:
    default: true
    description:
    - Enable IPv6 on the public network interface.
    type: bool

api_token:
    description:
    - cloudscale.ch API token.
    - This can also be passed in the C(CLOUDSCALE_API_TOKEN) environment variable.
    required: true
    type: str

user_data:
    description:
    - Cloud-init configuration (cloud-config) data to use for the server.
    type: str

interfaces:
    description:
    - List of network interface objects specifying the interfaces to be attached to the
      server. See U(https://www.cloudscale.ch/en/api/v1/#interfaces-attribute-specification)
      for more details.
    elements: dict
    suboptions:
      addresses:
        description:
        - Attach a private network interface and configure a subnet and/or an IP address.
        elements: dict
        suboptions:
          address:
            description:
            - The static IP address of the interface. Use '[]' to avoid assigning an IP
              address via DHCP.
            type: str
          subnet:
            description:
            - UUID of the subnet from which an address will be assigned.
            type: str
        type: list
      network:
        description:
        - Create a network interface on the network identified by UUID. Use 'public' instead
          of an UUID to attach a public network interface. Can be omitted if a subnet
          is provided under addresses.
        type: str
    type: list
    version_added: 1.4.0
    version_added_collection: cloudscale_ch.cloud

api_timeout:
    default: 45
    description:
    - Timeout in seconds for calls to the cloudscale.ch API.
    - This can also be passed in the C(CLOUDSCALE_API_TIMEOUT) environment variable.
    type: int

server_groups:
    description:
    - List of UUID or names of server groups.
    elements: str
    type: list

volume_size_gb:
    default: 10
    description:
    - Size of the root volume in GB.
    type: int

use_public_network:
    description:
    - Attach a public network interface to the server.
    type: bool

bulk_volume_size_gb:
    description:
    - Size of the bulk storage volume in GB.
    - No bulk storage volume if not set.
    type: int

use_private_network:
    description:
    - Attach a private network interface to the server.
    type: bool

Outputs

flavor:
  description: The flavor that has been used for this server
  returned: success when not state == absent
  sample:
    memory_gb: 4
    name: Flex-4-2
    slug: flex-4-2
    vcpu_count: 2
  type: dict
href:
  description: API URL to get details about this server
  returned: success when not state == absent
  sample: https://api.cloudscale.ch/v1/servers/cfde831a-4e87-4a75-960f-89b0148aa2cc
  type: str
image:
  description: The image used for booting this server
  returned: success when not state == absent
  sample:
    default_username: ubuntu
    name: Ubuntu 18.04 LTS
    operating_system: Ubuntu
    slug: ubuntu-18.04
  type: dict
interfaces:
  description: List of network ports attached to the server
  returned: success when not state == absent
  sample:
  - addresses:
    - '...'
    type: public
  type: list
name:
  description: The display name of the server
  returned: success
  sample: its-a-me-mario.cloudscale.ch
  type: str
server_groups:
  description: List of server groups
  returned: success when not state == absent
  sample:
  - href: https://api.cloudscale.ch/v1/server-groups/...
    name: db-group
    uuid: '...'
  type: list
ssh_fingerprints:
  description: A list of SSH host key fingerprints. Will be null until the host keys
    could be retrieved from the server.
  returned: success when not state == absent
  sample:
  - ecdsa-sha2-nistp256 SHA256:XXXX
  - '...'
  type: list
ssh_host_keys:
  description: A list of SSH host keys. Will be null until the host keys could be
    retrieved from the server.
  returned: success when not state == absent
  sample:
  - ecdsa-sha2-nistp256 XXXXX
  - '...'
  type: list
state:
  description: The current status of the server
  returned: success
  sample: running
  type: str
tags:
  description: Tags assosiated with the server.
  returned: success
  sample:
    project: my project
  type: dict
uuid:
  description: The unique identifier for this server
  returned: success
  sample: cfde831a-4e87-4a75-960f-89b0148aa2cc
  type: str
volumes:
  description: List of volumes attached to the server
  returned: success when not state == absent
  sample:
  - device: /dev/vda
    size_gb: '50'
    type: ssd
  type: list
zone:
  description: The zone used for booting this server
  returned: success when not state == absent
  sample:
    slug: lpg1
  type: dict