Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

cherryservers/cherry-ansible-module

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 

Repository files navigation

Cherry Servers ansible module

WARNING

Beware, this module has been obsoleted by Cherry Servers Ansible collection .

Introduction

Cherry Servers is an international Bare Metal Cloud provider and supports the following Ansible modules:

  • cherryservers_sshkey: manages public SSH keys on Client Portal. You may assign these keys to your chosen servers upon deployment.
  • cherryservers_ips: manages floating IPs at Client Portal. You may order additional IPs, route them to existing servers, etc.
  • cherryservers_server: manages servers at Cherry Servers. You may Deploy and Terminate servers, manage theyr power, etc.

Installation

In order to use above mentioned modules you need to download files from bitbucket , put them into folder named library and move it to your ansible playbooks directory, for instance:

└── cherry_servers_playbooks
    ├── library
    │   ├── cherryservers_ips.py
    │   ├── cherryservers_server.py
    │   └── cherryservers_sshkey.py
    ├── servers_deploy.yml
    └── servers_terminate.yml

Requirements

The Cherry Servers module connects to Cherry Servers Public API via cherry-python package. You need to install it with pip:

$ pip install cherry-python

In order to use Ansible module you will need to export Cherry Servers API token. You can generate and get it from your Client Portal. The easiest way is to export variable like this:

$ export CHERRY_AUTH_TOKEN="2b00042f7481c7b056c4b410d28f33cf"

Most of the time you will need several UUIDs or specific names to work with those modules:

  • project_id - you will need to specify it to work with all modules. You can find that ID by looging to Cherry Servers Client Portal.
  • plan_id - you will need to specify it to work with cherryservers_server module.
  • image - you will need to specify it to work with cherryservers_server module.
  • region - you will need to specify it to work with cherryservers_server and cherryservers_ips module.

Manage SSH keys

  • cherryservers_sshkey module
Parameter Choices/Defaults Comments
auth_token Required: true Authenticating API token provided by Cherry Servers. You can supply it via CHERRY_AUTH_TOKEN environement variable.
label Label of SSH key.
id ID of SSH key.
fingerprint Fingerprint of SSH key.
key_file Path to SSH key file.
key RAW key
state Choices: present, absent Define desired state of SSH key

Add new SSH key from raw input to Client Portal:

# ssh_add_keys.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Add SSH key
    cherryservers_sshkey:
      label: "trylika"
      key: "ssh-rsa key-data comment"
      state: present

Add new SSH key from selected file to Client Portal:

# ssh_add_keys.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Manage SSH keys
    cherryservers_sshkey:
      label: "keturiolika"
      key_file: key_file.pub
      state: present

Remove existing SSH key by label:

# ssh_remove_keys.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Removes SSH keys
    cherryservers_sshkey:
      label:
        - 'testas'
        - 'trylika'
      state: absent

Remove existing SSH key by ID:

# ssh_remove_keys.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Removes SSH keys
    cherryservers_sshkey:
      key_id:
        - '127'
        - '125'
      state: absent

Remove existing SSH key by fingerprint:

# ssh_remove_keys.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Removes SSH keys
    cherryservers_sshkey:
      fingerprint:
        - 'cf:dc:ee:96:00:cb:c6:e2:fd:49:5c:64:0a:85:e9:47'
        - '88:b9:88:43:b3:24:53:55:85:88:61:cc:a0:7d:cb:f0'
      state: absent

Remove existing SSH key by file:

# ssh_remove_keys.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Removes SSH keys
    cherryservers_sshkey:
      key_file:
        - key_file_jonas.pub
        - key_file_kestas.pub
        - key_file_mantas.pub
        - key_file_marius.pub
      state: absent

After you have created a playbook, you can run it like this:

ansible-playbook ssh_add_keys.yml

Manage Servers

  • cherryservers_server module
Parameter Choices/Defaults Comments
auth_token Required: true Authenticating API token provided by Cherry Servers. You can supply it via CHERRY_AUTH_TOKEN environement variable.
project_id Required: true ID of project of the servers.
hostname Define hostname of server. You may specify %02d or %03d depending how many servers you need - dozens or hundreds. By specifying %02d with count 3, you will get hostnames numerated from 01 to 03, in case of %03d it will generate range from 001 to 003.
image Image to be installed on the server, e.g. Ubuntu 16.04 64bit.
ip_address List of floating IP addresses to be added to new server.
ip_address_id List of floating IP addresses UIDs to be added to a new server.
plan_id Plan for server creation.
ssh_key_id SSH key`s ID for adding SSH key to server.
ssh_label SSH key`s label for adding SSH key to server.
server_ids List of servers' IDs on which to operate.
region Region of the server.
spot_market default: 0 Request server as a spot server.
count default: 1 Amount of servers to be created.
count_offset default: 1 From which number to start the count.
wait_timeout default: 1800 How long to wait for server to reach active state.
state Choices: absent, active, rebooted, present, stopped, running Define desired state of the server. If set to present, the module will return back immediately after API call returns. If set to active, the module will wait for wait_timeout for server to be in active state.

Deploy server with selected SSH keys on it

# server_deploy.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Deploy CherryServers Server
    cherryservers_server:
      hostname:
        - server%02d.example.com
      plan_id: '161'
      project_id: '79813'
      image: 'Ubuntu 16.04 64bit'
      region: 'EU-East-1'
      state: present
      count: 1
      count_offset: 4
      ssh_label:
        - john
        - marius

Terminate servers

# server_terminate.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Remove CherryServers server
    cherryservers_server:
      project_id: '79813'
      hostname:
        - 'server03.example.com'
        - 'server04.example.com'
        - 'server06.example.com'
      state: absent

Deploy servers and wait for them to be active

# server_deploy.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Deploy CherryServers Server
    cherryservers_server:
      hostname:
        - server%02d.example.com
      plan_id: '161'
      project_id: '79813'
      image: 'Ubuntu 16.04 64bit'
      region: 'EU-East-1'
      state: active
      count: 2
      count_offset: 1

After you have created a playbook, just run it like this:

ansible-playbook server_deploy.yml

Manage Floating IPs

  • cherryservers_ips module
Parameter Choices/Defaults Comments
auth_token Required: true Authenticating API token provided by Cherry Servers. You can supply it via CHERRY_AUTH_TOKEN environement variable.
project_id Required: true ID of project of the servers.
ptr_record Your preferable reverse
ia_record Easy memorizable hostname
routed_to_ip IP address of the server to route Floating IP to.
routed_to_hostname Hostname of the server to route Floating IP to.
routed_to_server_id Server ID of the server to route Floating IP to.
ip_address_id Floating IP address ID to update or remove.
ip_address Floating IP address to be updated or removed.
region Region of the Floating IP address.
cout default: 1 Count of Floating IP addresses to be added.
state Choices: present, absent, update Define desired state of the IPs.

Add one Floating IP routed to server`s IP address

# ip_add.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Manage IP addresses
    cherryservers_ips:
    project_id : '79813'
    region : 'EU-East-1'
    ptr_record : 'your-preferable-reverse.example.com'
    a_record : 'easy-memorizable-hostname.cloud.cherryservers.com'
    routed_to_ip: 'xxx.xxx.xxx.xxx'
    state: present

Add several Floating IPs routed to server`s hostname

# ip_add.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Manage IP addresses
    cherryservers_ips:
    project_id : '79813'
    region : 'EU-East-1'
    ptr_record : 'your-preferable-reverse.example.com'
    a_record : 'easy-memorizable-hostname.cloud.cherryservers.com'
    routed_to_hostname: 'server04.example.com'
    state: present

Modify Floating IP route to different server`s hostname

# ip_update.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Manage IP addresses
    cherryservers_ips:
    project_id: '79813'
    ip_address_id: '2593fd9b-a0a1-10ce-13ce-2f7d7ad99eca'
    ptr_record: 'your-preferable-reverse.example.com'
    routed_to_hostname: easy-memorizable-hostname
    a_record: 'arturas1'
    state: update

Remove specific Floating IP address

# ip_terminate.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Manage IP addresses
    cherryservers_ips:
    project_id: '79813'
    ip_address: 
      - 'xxx.xxx.xxx.xxx'
    state: absent

After you have created a playbook, just run it like this:

ansible-playbook ip_add.yml

Manage Storage Volume

  • cherryservers_storage module
Parameter Choices/Defaults Comments
auth_token Required: true Authenticating API token provided by Cherry Servers. You can supply it via CHERRY_AUTH_TOKEN environement variable.
project_id Required: true ID of project of the volume.
storage_volume_id Storage volume ID to update or remove.
attach_to_id ID of the server to attach volume to.
attach_to_hostname Hostname of the server to attach volume to.
size Volume size to create or update.
description Volume description.
region Region of the Floating IP address.
state Choices: present, absent, update Define desired state of the volume.

Request new storage volume

# storage_create.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Request new storage volume
    cherryservers_storage:
    project_id : '79813'
    region : 'EU-Nord-1'
    size: 256
    description: 'my-new-storage-volume'
    state: present

Attach storage to server

# storage_attach.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Attach volume to server
    cherryservers_storage:
    project_id: '79813'
    storage_volume_id: 388268
    state: update

Detach storage from a server

# storage_detach.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Detach volume from a server
    cherryservers_storage:
    project_id: '79813'
    state: update

Upgrade storage volume size and/or description

# storage_upgrade.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Detach volume from server
    cherryservers_storage:
    project_id: '79813'
    storage_volume_id: 388268
    size:512
    description: 'my-upgraded-storage-volume'
    state: update

Delete storage volume

# storage_delete.yml

- name: Cherry Servers API module
  connection: local
  hosts: localhost
  tasks:
  - name: Delete storage volume
    cherryservers_storage:
    project_id: '79813'
    storage_volume_id: 388268
    state: absent

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages