Skip to content

Instantly share code, notes, and snippets.

@acidprime
acidprime / create_known_hosts.rb
Last active January 21, 2016 00:02
Create known hosts for r10k ( when not using rugged )
#!/usr/bin/ruby
require 'rubygems'
require 'puppet'
require 'yaml'
# Have puppet parse its config so we can call its settings
Puppet.initialize_settings
# Use puppet to manage host keys
def add_known_host(user, homedir, hostname)
ssh_dir = "#{homedir}/.ssh/"
@acidprime
acidprime / classifier_groups.sh
Created August 31, 2015 18:40
Testing PE classifier groups
curl 'https://console.vm:4433/classifier-api/v1/groups' \
-H "Accept: application/json" -H "Content-Type: application/json" \
-X GET \
--tlsv1 \
--cacert /etc/puppetlabs/puppet/ssl/certs/ca.pem \
--cert /etc/puppetlabs/puppet/ssl/certs/console.vm.pem \
--key /etc/puppetlabs/puppet/ssl/private_keys/console.vm.pem \
yes y | ssh-keygen -t dsa -C "r10k" -f /root/.ssh/id_dsa -q -N ''
curl "http://gitlab.internal.server/api/v3/projects/1/keys" -H "PRIVATE-TOKEN: GDHAHAJggshjgdfssfNOTREAL" -H "Accept: application/json" -H "Content-type: application/json" -X POST --data "{ \"title\": \"`hostname -f`\", \"key\": \"`cat /root/.ssh/id_dsa.pub`\"}"
@acidprime
acidprime / restart.rb
Created July 8, 2015 23:45
Restart a service with puppet
#!/opt/puppetlabs/puppet/bin/ruby
require 'puppet'
service = Puppet::Type.type(:service).new({:name => 'puppet'}).provider
service.restart
Facter.add('root_ssh_key') do
setcode do
pubkey = '/root/.ssh/id_rsa.pub'
File.read(pubkey).split[1] if File.exists? pubkey
end
end
#!/opt/puppet/bin/ruby
require 'puppet'
require 'r10k/deployment/environment'
Puppet.parse_config
keyscan = `ssh-keyscan github.com 2>/dev/null`.split
FileUtils.mkdir_p('/root/.ssh/')
FileUtils.touch('/root/.ssh/known_hosts')
@acidprime
acidprime / read_resource.rb
Last active August 29, 2015 14:19
Use resource_type to retrieve native ruby objects you can use with to_yaml
#!/opt/puppet/bin/ruby
require 'puppet/face'
require 'yaml'
Puppet.parse_config
resources = Puppet::Face[:resource_type, '0.0.1'].search('.*',{:extra => { 'environment' => 'production' }})
output = Hash.new
resources.each do |resource|
resource.arguments.each do |k,v|
@acidprime
acidprime / Puppetfile
Last active August 29, 2015 14:17
This is a Puppetfile that will automatically download all supported+approved modules from the forge
#!/usr/bin/ruby
require 'puppet_forge'
# Example of a module from an internal repo co-existing with forge modules.
#mod 'splunk',
# :git => 'https://internal.git.server/example/puppet-splunk.git',
# :commit => '3ca47046a86aef9fbfdf58cc7b418d8e7254ecb9'
@dependencies = []
@approved = []
@acidprime
acidprime / foo.pp
Last active June 15, 2016 19:07
Empty string change in future parser
cat /tmp/foo.pp
$empty = ''
if $empty {
notify { 'condition is true': }
} else {
notify { 'condition is false': }
}
vagrant:~ zack$ /opt/puppet/bin/puppet apply /tmp/foo.pp
Notice: Compiled catalog for swiftstore2.corp.puppetlabs.net in environment production in 0.02 seconds
@acidprime
acidprime / hosts.pp
Created January 22, 2015 15:26
Remove multiple hosts with augeas
augeas { 'remove_multi_hosts':
context => '/files/etc/hosts',
changes => [
"rm *[canonical = 'foo.bar.com']",
],
}