Skip to content

Instantly share code, notes, and snippets.

View ohadlevy's full-sized avatar

Ohad Levy ohadlevy

  • Red Hat
  • Israel
View GitHub Profile
require 'foreman'
hosts = gethosts({"fact"=>{"domain"=>"lan", "puppetversion"=>"0.25.4"}})
if hosts.nil?
puts "no hosts found"
else
puts hosts.join(" ")
end
require 'csv'
module Puppet::Parser::Functions
# we parse the precedence here because the best place to specify
# it would be in site.pp but site.pp is only evaluated at startup
# so $fqdn etc would have no meaning there, this way it gets evaluated
# each run and has access to the right variables for that run
newfunction(:lookup, :type => :rvalue) do |args|
def var_to_fact str
while str =~ /%\{(.+?)\}/
#!/bin/sh
# This procedure must be followed after a puppetmaster has been created but before
# any clients have been created by that puppetmaster. It should be performed on
# the puppeteer in the directory where the openssl.cnf file is located.
#
# It requires the puppeteers id_rsa.pub to be in the authorized_keys template
# It requires that the puppetmaster service has been started at least once on
# new server
# It requires that the puppetmaster and httpd services have been stopped on the
# new server
# $Id: openssl.cnf,v 1.3 2007/06/03 18:15:11 jmates Exp $
#
HOME = .
RANDFILE = $ENV::HOME/.rnd
[ ca ]
default_ca = CA_default
[ CA_default ]
dir = /var/lib/puppet/ssl
#!/usr/bin/ruby
require "rubygems"
require 'net/http'
require "mechanize"
agent = Mechanize.new
url = "http://localhost:3000"
new_host_url = "#{url}/hosts/new"
# Run this script via the runner app, e.g.
# ~foreman/scripts/runner -e production "thisscript"
dir = "/var/lib/puppet/reports"
User.current = User.find_by_login "admin"
Dir["#{dir}/*/*.yaml"].each do |yaml|
begin
print "importing #{yaml} "
puts Report.import File.read(yaml)
diff --git a/extras/query/foreman.rb b/extras/query/foreman.rb
index dca1e25..703c0d0 100644
--- a/extras/query/foreman.rb
+++ b/extras/query/foreman.rb
@@ -1,13 +1,22 @@
require 'yaml'
-require 'net/http'
+require 'net/https'
+class NilClass; def closed?; true; end; end
@ohadlevy
ohadlevy / gist:674623
Created November 12, 2010 20:29
script to automate creation of machines, including dns, dhcp, tftp, foreman and puppet
#!/usr/bin/ruby
require "rubygems"
require "rest_client"
require "json"
require "uri"
fqdn = ARGV[0] || raise("Must define a fqdn")
mac = ARGV[1] || raise("Must define a mac")
@ohadlevy
ohadlevy / gist:674630
Created November 12, 2010 20:32
Deletes a host from dhcp, dns, tftp and foreman using rest api
#!/usr/bin/ruby
require "rubygems"
require "rest_client"
require "json"
require "uri"
fqdn = ARGV[0] || raise("Must define a fqdn")
start = Time.now
User.current = User.find_by_login "admin"
old_name = "Puppet Master"
new_name = "common"
params = Hostgroup.find_by_name(old_name).group_parameters
old_params = params.collect{|p| [p.name, p.value]}
new_group = Hostgroup.find_by_name(new_name)
old_params.each do |param|
new_group.group_parameters << GroupParameter.create(:name => param[0], :value => param[1])