Created
October 5, 2011 04:20
-
-
Save sawanoboly/1263623 to your computer and use it in GitHub Desktop.
Raketask: copy sshdconfigs from host to all lxc Containers. (igunore guest status.)
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
## lxc-tool for natty | |
## copy sshdconfigs from host to all guests. (ignore the guest status) | |
## author [email protected] | |
## Usage: rake copyssh | |
require 'pp' | |
LXC_DIR = "/var/lib/lxc/" | |
rake_env = ENV['RAKE_ENV'] || "dafault" | |
# sshd consts | |
SSHD_CONF = "/etc/ssh/sshd_config" | |
SSHD_AUTH = "/root/.ssh/authorized_keys" | |
## ls LXC_DIR, and remove /^./ Directories(files). | |
def getCTlist() | |
tmp_list = Dir::entries(LXC_DIR) | |
ct_list = [] | |
tmp_list.each do |ct| | |
if ct !~ /^\./ then | |
ct_list << ct | |
end | |
end | |
return ct_list | |
end | |
desc 'copy sshdconfigs from host to all guests. (ignore the guest status)' | |
task :copyssh do | |
ct_list = getCTlist | |
ct_list.each do |ct| | |
tmp_base = LXC_DIR + ct + "/rootfs/root/.ssh" | |
if true != File.exist?(tmp_base) | |
Dir.mkdir(tmp_base,0700) | |
end | |
puts "Setting up #{ct}..." | |
tmp_dist = LXC_DIR + ct + "/rootfs" + SSHD_CONF | |
# p tmp_dist | |
FileUtils.copy(SSHD_CONF, tmp_dist, {:preserve => true}) | |
puts " #{ct}: OverWritten #{tmp_dist}" | |
tmp_dist = LXC_DIR + ct + "/rootfs" + SSHD_AUTH | |
# p tmp_dist | |
FileUtils.copy(SSHD_AUTH, tmp_dist, {:preserve => true}) | |
puts " #{ct}: OverWritten #{tmp_dist}" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment