Giter Club home page Giter Club logo

ansible-hetzner-cloud-volume-sshfs's Introduction

ansible-hetzner-cloud-volume-sshfs

This repository contains a bash script that creates/destroys a setup at Hetzner Cloud via the hcloud cli interface and an Ansible playbook to provision Hetzner Cloud Servers with a Hetzner Cloud Volume that is mounted on multiple servers via sshfs over the Hetzner Cloud Network. A tutorial for the Hetzner Online Community has been submitted.

Dependencies

Installation on macOS

brew install hcloud
brew install ansible

At times of writing this installs the following software versions.

  • hcloud version 1.18.0
  • ansible 2.9.10
  • hcloud-python 1.9.1

Other Operating Systems

We refer to the hcloud/cli README and Ansible documentation for installation instructions on other operating systems.

Initial configuration

For hcloud

If you haven't already, first create a project <myproject> in your Hetzner Cloud Console and generate an API token via Security > API Tokens > Generate API Token. Next, open up a terminal and execute the following.

source <(hcloud completion bash)   # if you want command completion - trust me, you do!
hcloud context create myproject
hcloud context list
hcloud context use myproject  # only if it isn't active just yet
hcloud context active  # should be myproject

Also see hcloud README/Getting Started. Note that hcloud context create stores the API token in ~/.config/hcloud/cli.toml.

For ansible

  • Create a virtualenv:

    virtualenv --python=python3 .venv 
    source .venv/bin/activate
    pip install ansible hcloud
  • We need to export the following shell variables for the Ansible hcloud plugin to automatically get the servers to provision from the hcloud cli interface.

    export HCLOUD_CONTEXT=myproject
    export HCLOUD_TOKEN=mytoken

Usage

  • Create the setup at Hetzner Cloud: ./create.sh -c
  • Run the playbook: ansible-playbook provision.yml
  • Connect to server1: ssh root@$(hcloud server ip server1) -i ~/.ssh/hcloud_sshfs_rsa -o StrictHostKeyChecking=no
  • Connect to server2: ssh root@$(hcloud server ip server2) -i ~/.ssh/hcloud_sshfs_rsa -o StrictHostKeyChecking=no
  • Destroy the setup at Hetzner Cloud: ./create.sh -d

References

Part of the Ansible roles have been gleaned from Vito Botta's ansible-bootstrap-role, specifically Update system and Install essential packages (though the latter is extensively modified).

ansible-hetzner-cloud-volume-sshfs's People

Contributors

tlrh314 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

vahobrsti

ansible-hetzner-cloud-volume-sshfs's Issues

The final test of the playbook fails, but mount succeeds after additional reboot of server2

The final test fails, but the volume is available and mounted after an additional, manual reboot on server2. Moreover, the handlers to restart sshd and networking seem to run at the end of the playbook, but they should run where specified instead.

TASK [hetzner-cloud-volume-sshfs : Create /mnt/storage/test_server1] ****************************************************************************************************************************************************
skipping: [server2]
fatal: [server1]: FAILED! => {
    "changed": false,
    "path": "/mnt/storage/test_server1",
    "state": "absent"
}

MSG:

file (/mnt/storage/test_server1) is absent, cannot continue

TASK [hetzner-cloud-volume-sshfs : Create /mnt/storage/test_server2] ****************************************************************************************************************************************************
fatal: [server2]: FAILED! => {
    "changed": false,
    "path": "/mnt/storage/test_server2",
    "state": "absent"
}

MSG:

file (/mnt/storage/test_server2) is absent, cannot continue

RUNNING HANDLER [hetzner-cloud-volume-sshfs : Restart networking] *******************************************************************************************************************************************************

RUNNING HANDLER [hetzner-cloud-volume-sshfs : Restart sshd] *************************************************************************************************************************************************************

PLAY RECAP **************************************************************************************************************************************************************************************************************
server1                    : ok=18   changed=15   unreachable=0    failed=1    skipped=9    rescued=0    ignored=0
server2                    : ok=24   changed=21   unreachable=0    failed=1    skipped=4    rescued=0    ignored=0

Add support for non-debian distro's (e.g. CentOS / Fedora)

It may be useful to implement support for non-debian distro's. The list of images supported by Hetzner Cloud is as follows.

(.venv) [09:56:44][timohalbesma@ChezTimo15]$ hcloud image list
ID         TYPE     NAME           DESCRIPTION    IMAGE SIZE   DISK SIZE   CREATED
1          system   ubuntu-16.04   Ubuntu 16.04   -            5 GB        Mon Jan 15 12:34:45 CET 2018
2          system   debian-9       Debian 9       -            5 GB        Mon Jan 15 12:34:45 CET 2018
3          system   centos-7       CentOS 7       -            5 GB        Mon Jan 15 12:34:45 CET 2018
168855     system   ubuntu-18.04   Ubuntu 18.04   -            5 GB        Wed May  2 13:02:30 CEST 2018
5924233    system   debian-10      Debian 10      -            5 GB        Mon Jul  8 08:35:48 CEST 2019
8356453    system   centos-8       CentOS 8       -            5 GB        Mon Oct  7 15:18:43 CEST 2019
15512617   system   ubuntu-20.04   Ubuntu 20.04   -            5 GB        Thu Apr 23 19:55:14 CEST 2020
15759618   system   fedora-32      Fedora 32      -            5 GB        Wed Apr 29 12:32:02 CEST 2020
  • Certainly would have to update setup_server.yml for installation /w yum instead of apt
  • Certainly would have to update setup_virtual_private_network.yml to support CentOS / Fedora following the instructions in the Cloud Networks Configuration. I don't know whether the network interface will be available on boot in time for auto-mount via sshfs.
  • Possibly would have to update setup_ssh_keys_and_config.yml
  • Probably would have to update setup_sshfs_in_fstab.yml

I'm not familiar enough /w CentOS and Fedora to implement this myself, but feel free to submit a pull request if you find this repo useful and would like to see support for CentOS/Fedora added.

Implement the ansible role to setup sshfs

Server creation via hcloud hits a timeout and it seems that the cloud init does not run through properly. It is possible to start the server via the console, but the network interface then refuses to come up. The main network interface then also appears as eth0 instead of ens10. So it seems to me that perhaps Hetzner's cloud init script fails and the resulting server has different properties than expected. As a result I am at this moment unable to complete implementation of the Ansible roles to provision the sshfs setup, so the following Ansible tasks still have to be implemented.

  • setup_virtual_private_network.yml (Step 3.1)
  • setup_ssh_keys_and_config.yml (Step 3.2)
  • setup_sshfs_in_fstab.yml (Step 3.3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.