Code Monkey home page Code Monkey logo

brovision's Introduction

Master-less Server Provisioning with Bash

Start provisioning your servers and images without the steep learning curve.

Start

Start by defining a node to be provisioned.

mkdir -p nodes/myservers/
echo -e "SSH_HOST=192.168.1.x
SSH_PORT=22
SSH_USER=pi
declare -a TASKS=('ping')
" > nodes/myservers/raspberry_pi.sh

Test out the server connection with the ping task

./brovision.sh raspberry_pi

Variables

Variables defined in your node file are pre-pended to any task being sent to the node. In this way you can use source to arrange your settings and password files.

SSH_HOST=192.168.1.x
SSH_PORT=22
SSH_USER=pi

D=$(dirname "${BASH_SOURCE[0]}")
source $D/roles/mysql.sh
source $D/roles/nginx.sh

It is advisable to write all your tasks and source files to use the prefix BRO_ for all variable names. Trying to automatically determine the variables defined in a bash script is problamatic. Only transfering variables prefixed with BRO_ could prove a more reliable method in the future.

Node specific tasks

Sometimes you have a script that is not applicable to any other host. Maybe it has passwords in it. Maybe it is for a specific architecture that you cannot make generic. In these cases, you can put the file into a "tasks/" folder in your node groups.

brovision.sh
├── tasks
│   └── os
│       └── set-hostname.sh
├── nodes
│   ├── MYSERVERS #separate git repo
│   │    ├── my-rpi.sh
│   │    └── tasks/
│   │       └── install-repozytorium.sh

In the above case, install-repozytorium is really only applicable to raspberry-pi devices. Trying to make a generic repo adding task is not very rewarding. We can call this task directly in the my-rpi.sh node file:

#nodes/MYSERVERS/my-rpi.sh

declare -a TASKS=()
TASKS+=('os/set-hostname.sh') # <-- generic tasks/os/set-hostname.sh
TASKS+=('install-repozytorium.sh') # <-- first tries nodes/MYSERVERS/tasks/

Notice that we include the file extension ".sh". The brovision.sh file will examine any "tasks/" folder under the directory which holds the specified node file. If it cannot find a file there, it seeks to look under tasks//.sh.

Basically:

  • refer to just the file with .sh extension for custom task files
  • but, refer to directory or directory/task.sh for generic tasks.

brovision's People

Contributors

markkimsal avatar

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.