Skip to content

Instantly share code, notes, and snippets.

View WhatsARanjit's full-sized avatar

Ranjit Viswakumar WhatsARanjit

View GitHub Profile
@WhatsARanjit
WhatsARanjit / pry.sh
Created September 13, 2017 22:19
new Types
[1] pry(main)> require 'puppet'
=> true
[2] pry(main)> Puppet::Type.type(:file).new({:ensure => 'file', :path => '/tmp/thing'})
=> #<Puppet::Type::File:0x0000000474ef88
@clients={},
@name_var_cache=:path,
@original_parameters={:ensure=>"file"},
@parameters=
{:path=>#<Puppet::Type::File::ParameterPath:0x0000000474a758 @resource=#<Puppet::Type::File:0x0000000474ef88 ...>, @value="/tmp/thing">,
:provider=>#<Puppet::Type::File::ParameterProvider:0x0000000474a078 @resource=#<Puppet::Type::File:0x0000000474ef88 ...>, @value=:posix>,
@WhatsARanjit
WhatsARanjit / shell.sh
Created August 29, 2017 17:55
Regex array into string
root@centos:~/repos # puppet apply <<'PP'
> $_regex_array = [
> '\d',
> '\w',
> '\d+',
> ]
> if '1a1234' =~ $_regex_array.join('') {
> notice('hi')
> }
> PP
[root@puppet2017 ~]# puppet resource node_group 'PE Master' provider=https --debug
Debug: Runtime environment: puppet_version=4.9.4, ruby_version=2.1.9, run_mode=user, default_encoding=UTF-8
Debug: Failed to load library 'puppetclassify' for feature 'puppetclassify'
Debug: Puppet::Type::Node_group::ProviderPuppetclassify: feature puppetclassify is missing
Debug: Loaded state in 0.15 seconds
Debug: Loaded transaction store file in 0.00 seconds
Debug: Prefetching https resources for node_group
Debug: classifier_url: https://puppet2017.1.1.puppetlabs.vm:4433/classifier-api
Debug: Using SSL authentication
Debug: Finishing transaction 28162460
@WhatsARanjit
WhatsARanjit / Puppetfile
Last active August 4, 2017 16:15
Managing Puppetfile in YAML/JSON
# Look for puppetfile.yaml and then puppetfile.json
begin
require 'yaml'
puppetfile = YAML.load_file('./puppetfile.yaml')
rescue
begin
require 'json'
puppetfile = JSON.parse(File.read('./puppetfile.json'))
rescue
fail 'Could not find file "puppetfile.yaml" or "puppetfile.json"'
@WhatsARanjit
WhatsARanjit / shell.sh
Created August 2, 2017 12:47
Data into hocon
[root@puppet2017 /etc/puppetlabs/code/modules/hocon_funk]# facter dmi
{
bios => {
release_date => "12/01/2006",
vendor => "innotek GmbH",
version => "VirtualBox"
},
board => {
manufacturer => "Oracle Corporation",
product => "VirtualBox",
@WhatsARanjit
WhatsARanjit / .node_managerrc
Last active July 14, 2017 11:57
Puppet-less node_group provider
TOKEN='0ZJ40A1YvorJu20ZDT6qGvDlLsRbWC7nEdTxRpwrV7ro'
@WhatsARanjit
WhatsARanjit / shell.sh
Created June 30, 2017 15:13
Sharing data by jacking exported resources
[root@puppet2017 ~]# cat /tmp/test.pp
$epptemplate = @(EPP/L)
<%- | $nodes | -%>
My nodes:
<% $nodes.each |$n| { -%>
Hostname: <%= $n[0] %>
IP: <%= $n[1] %>
<% } -%>
| EPP
@WhatsARanjit
WhatsARanjit / concat.pp
Last active June 22, 2017 19:54
Format attribute for concat
# Plain text
concat_file { '/tmp/test.txt':
ensure => present,
tag => 'plain_concat',
format => 'plain',
}
concat_fragment { 'header plain':
content => '{ "one": "foo" }',
order => '01',
target => '/tmp/test.txt',
@WhatsARanjit
WhatsARanjit / homedir.rb
Created June 20, 2017 21:06
Homedir fact
require 'puppet/face/resource'
Facter.add(:homedirs) do
setcode do
Puppet::Face[:resource, '0.0.1'].search("user").map { |u| Hash[u.title, u[:home]] }.reduce({}, :merge)
end
end
@WhatsARanjit
WhatsARanjit / shell.sh
Created June 16, 2017 17:38
tgm4883 noop mode
# Noop
[root@puppet2017 ~]# puppet apply /tmp/test.pp --noop
Notice: Compiled catalog for puppet2017.1.1.puppetlabs.vm in environment production in 0.08 seconds
Notice: /Stage[main]/Main/Package[tgm4883]/ensure: current_value purged, should be lalalalalalala (noop)
Notice: Class[Main]: Would have triggered 'refresh' from 1 events
Notice: Stage[main]: Would have triggered 'refresh' from 1 events
Notice: Applied catalog in 0.37 seconds