Skip to content

Instantly share code, notes, and snippets.

@mago0
Created June 25, 2012 18:03
Show Gist options
  • Save mago0/2990245 to your computer and use it in GitHub Desktop.
Save mago0/2990245 to your computer and use it in GitHub Desktop.
package chef;
use Rex -base;
# Knife Conf Location
my $env = environment || 'dev';
set knife_conf => "vagrant/private/$env-knife.rb";
set user => $ENV{'USER'};
set environment => $env;
set chef_roles => [
qw/ base standalone backend database admin_frontend frontend mq reporting workers /
];
set chef_envs => [
qw/ development staging production /
];
#-------------------------------------------------------------------------------
# Local commands
#-------------------------------------------------------------------------------
desc 'Upload cookbooks and roles';
task 'push', sub {
my $roles = get 'chef_roles' || die 'Chef Roles not set!';
my $envs = get 'chef_envs' || die 'Chef Envs not set!';
my $knife_conf = get 'knife_conf';
my $environment = get 'environment';
die "$knife_conf doesn't exist." unless is_file($knife_conf);
say "Running 'knife cookbook upload -V --all -o chef/site-cookbooks:chef/cookbooks' -c $knife_conf";
run "knife cookbook upload -V --all -o chef/site-cookbooks:chef/cookbooks -c $knife_conf";
for my $role ( @$roles ) {
say "Running 'knife role from file chef/roles/${role}.rb' -c $knife_conf";
run "knife role from file chef/roles/${role}.rb -c $knife_conf";
}
for my $env ( @$envs ) {
say "Running 'knife environment from file chef/environments/${env}.rb' -c $knife_conf";
run "knife environment from file chef/environments/${env}.rb -c $knife_conf";
}
};
desc 'Delete vagrant client from chef server';
task 'rmclient', sub {
my $knife_conf = "vagrant/private/prod-knife.rb";
my $user = get 'user';
die "$knife_conf doesn't exist." unless is_file($knife_conf);
say "Running 'knife client delete vagrant-$user ' -c $knife_conf";
#run "knife client delete vagrant-$user -c $knife_conf";
};
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment