-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bao Nguyen
committed
Oct 8, 2014
1 parent
f14c59e
commit 5e326f2
Showing
11 changed files
with
272 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# Encoding: utf-8 | ||
# Cookbook Name:: rancid-git | ||
# Provider:: router | ||
# Author:: Bao Nguyen | ||
# License:: Apache 2.0 | ||
# | ||
# Copyright 2014, Bao Nguyen | ||
|
||
use_inline_resources | ||
|
||
action :remove do | ||
db_file = "#{node[:rancid][:install_dir]}/var/#{@name}/router.db" | ||
Chef::Log.info "Removing router db #{new_resource.name.to_s}: to #{db_file}" | ||
|
||
if ::File.exists?(db_file) | ||
Chef::Log.info "Removing router db #{new_resource.name.to_s}: to #{db_file}" | ||
file db_file do | ||
action :delete | ||
end | ||
new_resource.updated_by_last_action(true) | ||
end | ||
end | ||
|
||
action :create do | ||
var = "#{node[:rancid][:install_dir]}/var" | ||
group = "#{var}/#{new_resource.name}" | ||
db_file = "#{group}/router.db" | ||
|
||
directory var do | ||
owner node[:rancid][:user] | ||
group node[:rancid][:group] | ||
mode "0755" | ||
action :create | ||
end | ||
|
||
directory group do | ||
owner node[:rancid][:user] | ||
group node[:rancid][:group] | ||
mode "0755" | ||
action :create | ||
end | ||
|
||
template db_file do | ||
source "routers.db.erb" | ||
owner node[:rancid][:user] | ||
group node[:rancid][:group] | ||
mode "0644" | ||
variables( | ||
devices: new_resource.devices | ||
) | ||
end | ||
Chef::Log.info "Building router db #{new_resource.name.to_s}: to #{db_file}" | ||
new_resource.updated_by_last_action(true) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
include_recipe "cron" | ||
# install the cron job to run diff but doesn't do anything until it's setup with | ||
# the routers/switch to query and groups etc. | ||
cron_d "hourly-rancid-diff" do | ||
hour 1 | ||
command "#{node[:rancid][:install_dir]}/bin/rancid-run" | ||
user node[:rancid][:user] | ||
end | ||
|
||
cron_d "daily-clean-up" do | ||
hour 23 | ||
command "/usr/bin/find #{node[:rancid][:install_dir]}/var/rancid/logs -type f -mtime +2 -exec rm {} \;" | ||
user node[:rancid][:user] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
|
||
# packages needed by rancid to build and run | ||
packages = {} | ||
packages.merge!({ | ||
'expect' => '', | ||
'git' => '', | ||
'build-essential' => '', | ||
'autoconf' => '', | ||
}) | ||
|
||
packages.each do |pkg_name, pkg_version| | ||
package pkg_name do | ||
action :install | ||
version pkg_version unless pkg_version.empty? | ||
end | ||
end | ||
|
||
# Rancid is going to run as a user, which query router configs | ||
# we creating the user/group here | ||
|
||
group node[:rancid][:group] do | ||
gid node[:rancid][:gid] | ||
end | ||
|
||
user node[:rancid][:user] do | ||
supports :manage_home => true | ||
comment "RANCID User" | ||
uid node[:rancid][:uid] | ||
gid node[:rancid][:group] | ||
home node[:rancid][:prefix_dir] | ||
shell "/bin/bash" | ||
end | ||
|
||
# we sync with the upstream rancid-git revision 3.8.1 | ||
if node.chef_environment == "dev" | ||
branch_name = "master" | ||
else | ||
branch_name = node[:rancid][:version] | ||
end | ||
|
||
unless node[:rancid][:installed] | ||
git "#{node[:rancid][:install_dir]}/rancid-git" do | ||
not_if do | ||
File.exist?("#{node[:rancid][:install_dir]}/.cloginrc") | ||
end | ||
# we use http so we can delay dealing with ssh_known_host manangement | ||
repository node[:rancid][:url] | ||
revision branch_name | ||
action :sync | ||
user node[:rancid][:user] | ||
group node[:rancid][:group] | ||
end | ||
|
||
# build and install rancid from source here | ||
bash "build_install_rancid" do | ||
not_if do | ||
File.exist?("#{node[:rancid][:install_dir]}/etc/rancid.conf") | ||
end | ||
user node[:rancid][:user] | ||
group node[:rancid][:group] | ||
cwd "#{node[:rancid][:install_dir]}/rancid-git" | ||
code <<-EOF | ||
autoreconf | ||
./configure --prefix=#{node[:rancid][:prefix_dir]} --localstatedir=#{node[:rancid][:install_dir]}/var/rancid && make install | ||
EOF | ||
end | ||
node.set[:rancid][:installed] = true | ||
end | ||
|
||
# make the etc/rancid.conf file | ||
template "#{node[:rancid][:install_dir]}/etc/rancid.conf" do | ||
source "rancid.conf.erb" | ||
mode "0644" | ||
variables( | ||
:admin_email => node[:rancid][:admin_email], | ||
:install_dir => node[:rancid][:install_dir] | ||
) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Author:: Bao Nguyen <[email protected]> | ||
# Cookbook:: rancid-git | ||
# Resource:: router | ||
# | ||
# Copyright 2014, Ooyala | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# List of all actions supported by the provider | ||
actions :create, :remove | ||
|
||
# Make create the default action | ||
default_action :create | ||
|
||
# Require attributes | ||
attribute :name, kind_of: String, name_attribute: true | ||
attribute :devices, kind_of: Array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# sjc1 cluster | ||
add user *-sjc1* rancid | ||
add password *-sjc1* {D3s3rtr1pRRR} {Kbf7Lsmqq9yv} | ||
add identity *-sjc1* /home/rancid/.ssh/rancid | ||
add method *-sjc1* ssh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# This file is generated by Chef | ||
# rancid 2.3.1 | ||
|
||
TERM=network;export TERM | ||
LC_COLLATE="POSIX"; export LC_COLLATE | ||
umask 027 | ||
TMPDIR=/tmp; export TMPDIR | ||
BASEDIR=<%= node['rancid']['install_dir']%>/var/rancid; export BASEDIR | ||
PATH=<%= node['rancid']['install_dir']%>/bin:/usr/bin:/usr/sbin:/bin:.:/usr/local/bin:/usr/bin; export PATH | ||
CVSROOT=$BASEDIR/CVS; export CVSROOT | ||
LOGDIR=$BASEDIR/logs; export LOGDIR | ||
RCSSYS=git; export RCSSYS | ||
#ACLSORT=YES; export ACLSORT | ||
#NOPIPE=YES; export NOPIPE | ||
FILTER_PWDS=YES; export FILTER_PWDS | ||
NOCOMMSTR=YES; export NOCOMMSTR | ||
#MAX_ROUNDS=4; export MAX_ROUNDS | ||
OLDTIME=4; export OLDTIME | ||
#LOCKTIME=4; export LOCKTIME | ||
PAR_COUNT=5; export PAR_COUNT | ||
|
||
|
||
# list of rancid groups | ||
#LIST_OF_GROUPS="sf sjc1 sj sv2 lon mtv nyc gdl syd" | ||
|
||
#<% node['rancid']['groups'].each do |g| -%> | ||
# <%= g %> | ||
#<% end -%> | ||
|
||
LIST_OF_GROUPS="<%= node['rancid']['configs']['groups'].reduce("") {|acc,v| acc.concat("#{v} ")} %>" | ||
|
||
########### | ||
## Ooyala specific to bypass the rancid-${group} mapping, due to no access to remote smtp-out2.sv2 server | ||
## MAIL configurations | ||
#[email protected]; export mailrcpt | ||
#[email protected]; export adminmailrcpt | ||
#MAILDOMAIN="@ooyala.com"; export MAILDOMAIN | ||
|
||
HTMLMAILS=NO; export HTMLMAILS | ||
MAILHEADERS="Precedence: bulk"; export MAILHEADERS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<% @devices.each do |i| -%> | ||
<%= i[:name] %>:<%= i[:model] %>:<%= i[:status] %> | ||
<% end -%> |
Oops, something went wrong.