Git Product home page Git Product logo

sparrowform's Introduction

Synopsis

Sparrowdo provision for Terraform backed instances.

asciicast

Install

$ zef install Sparrowform

Limitations

Currently only ssh accessed instances with public IPs are supported ( aws ec2 / google compute instances with public IPs ).

Terrafrom resources supported:

Ping me if you need more Terraform resourses support.

Usage

Write some Terraform scenarios and deploy some instances

$ terraform apply

Create Sparrowodo scenarios, one per instance

Scenarios should be named as $terrafrom-instance-type.$terraform-instance-ID.sparrowfile

$ nano aws_instance.example.sparrowfile
$ nano aws_instance.example2.sparrowfile
$ nano aws_instance.example3.sparrowfile
# ...

See also Sparrowdo one liners option on how to run sparrowdo tasks/modules not scenarios.

Run Sparrowdo provision

This command will run Sparrowdo scenarios for all instances for which files $terrafrom-instance-ID.sparrowfile exist:

$ sparrowform

Handling ssh connections

You may pass ssh connection parameters by specifying sparrowdo cli parameters:

$ sparrowform --ssh_user=ec2-user --ssh_private_key=/path/to/ssh.key

Using sparrowdo one liners instead of scenarios:

# install Nginx on all instances:
$ sparrowform --module_run=Nginx

# check if Nginx alive on all instances:
$ sparrowform --task_run=bash@command='"ps uax|grep nginx"'

# install packages
$ sparrowform --task_run=package-generic@list="'nano mc'"

Default Sparrowdo scenario

If you don't want bother with creating scenarios for every instance, you may choose to defined default scenario.

Create scenario named sparrowfile:

$ nano sparrowfile

bash "apt-get update";

So, these instances which do not have a related Sparrowdo scenarios files will use this default scenario.

Terraform resources access

Sparrowform exposes nice API to access Terraform internal guts inside Sparrowdo scenarios.

The function tf-resources returns Perl6 Array of all Terraform resources. Each elements consists of two elements, the first one holds resource identificator, the second one holds resource data, represented as Perl6 Hash.

Here is usage example:

$ cat sparrowfile 

# let's insert all ec2 instances DNS names into ever instance's /etc/hosts file:

use Sparrowform;

my @hosts = (
  "127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4",
  "::1         localhost localhost.localdomain localhost6 localhost6.localdomain6"
);

for tf-resources() -> $r {
  my $rd = $r[1]; # resource data
  next unless $rd<public_ip>;
  next unless $rd<public_dns>;
  next if $rd<public_ip> eq input_params('Host');
  push @hosts, $rd<public_ip> ~ ' ' ~ $rd<public_dns>;
}

file '/etc/hosts', %(
  action  => 'create',
  content => @hosts.join("\n")
);

Debugging

If something goes awry ... Enable SPF_DEBUG variable to see internal output:

$ SPF_DEBUG=1 sparrowform

Dry run

If you only want to see which instances would be deployed, run with SPG_DRYRUN enabled:

$ SPF_DRYRUN=1 sparrowform

Author

Alexey Melezhik

See also

sparrowform's People

Contributors

melezhik avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  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.