Skip to content

Instantly share code, notes, and snippets.

View ohadlevy's full-sized avatar

Ohad Levy ohadlevy

  • Red Hat
  • Israel
View GitHub Profile
@ohadlevy
ohadlevy / d
Created December 15, 2011 13:54
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index e9af70b..8186708 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -64,9 +64,10 @@ module ApplicationHelper
def link_to_add_puppetclass klass, type
options = klass.name.size > 28 ? {:'data-original-title'=>klass.name, :rel=>'twipsy'} : {}
content_tag(:span, truncate(klass.name, :length => 28), options).html_safe +
- link_to_function("", "add_puppet_class(this)", :'data-class-id'=>klass.id,
- :'data-original-title'=>"Click to add #{klass}", :rel=>'twipsy',
module Virt
class Cache
attr_accessor :ttl
def initialize args
# default TTL is one hour
@ttl = args[:ttl] || 3600
reset
end
@ohadlevy
ohadlevy / gist:1546708
Last active September 29, 2015 04:27
$hosts = foreman(item => 'hosts',
search => 'last_report > "1 week ago" and hostgroup = Clients',
per_page => 1000)
vpn_access{$hosts: ensure => enabled}
# hosts with ip address and gateway facts
$hosts = foreman("fact_values", "fact = ipaddress or fact = gateway"
{"hostA":{"ipaddress":"10.35.27.3","gateway":"10.35.27.62"},"hostsB":{"ipaddress":"192.168.1.123","gateway":"192.168.1.254"}
# hosts with ip address and gateway facts
$hosts = foreman(item => 'fact_values', search => 'fact = ipaddress or fact = gateway')
{"hostA":{"ipaddress":"10.35.27.3","gateway":"10.35.27.62"},"hostsB":{"ipaddress":"192.168.1.123","gateway":"192.168.1.254"}
#! /bin/sh
#
USER="ci"
PASS="ci"
FOREMAN_URL="https://foreman.domain.org"
NAME=$1
HOSTGROUP_ID="1" # Change this to your favorite hostgroup
curl -s -H "Accept:application/json" \
#! /bin/sh
#
USER="ci"
PASS="ci"
FOREMAN_URL="https://foreman.domain.org"
FQDN=$1
curl -H "Accept:application/json" \
-k -u $USER:$PASS -X DELETE \
$FOREMAN_URL/hosts/$FQDN | prettify_json.rb
gem install foremancli
foremancli -h
Usage: foremancli [options] ...
-d, --debug Output more information
-u, --user USER Foreman user
-p, --pass PASSWORD Foreman password
-s, --server URL Foreman Server URL
--json JSON output
--yaml YAML output
#! /usr/share/foreman/script/rails runner -e production
Host.all.each do |host|
next unless host.dhcp?
print "#{host}..."
dhcp_record = host.dhcp_record
if dhcp_record.valid?
puts "VALID"
elsif dhcp_record.conflicting?
puts "CONFLICT"
@ohadlevy
ohadlevy / gist:1700094
Last active September 30, 2015 01:28
curl http://foreman/unattended/script | bash
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#!/bin/bash
KERNEL="/boot/kernel"
INITRD="/boot/initrd.img"
wget -O "$KERNEL" "http://centos.syn.co.il/5/os/x86_64/images/pxeboot/vmlinuz"