Skip to content

Instantly share code, notes, and snippets.

View WhatsARanjit's full-sized avatar

Ranjit Viswakumar WhatsARanjit

View GitHub Profile
@WhatsARanjit
WhatsARanjit / python_example.py
Created August 27, 2018 19:00
Python script for Vault IAM auth
#!/usr/bin/env python
import boto3
import json
import base64
import requests
import os
def headers_to_go_style(headers):
retval = {}
for k, v in headers.items():
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
@WhatsARanjit
WhatsARanjit / data_literal.pp
Last active November 21, 2018 20:15
Puppet as a hiera backend
{
'string' => 'foo',
'array' => [
'one',
'two',
'three',
],
'hash' => {
'a' => 1,
'b' => 2,
@WhatsARanjit
WhatsARanjit / merge_env_arrays.pp
Created March 16, 2018 11:12
ENV arrays merge
function test::merge_env_arrays (
Array $array_one,
Array $array_two,
) >> Array {
$hash_one = $array_one.reduce({}) |$memo, $var| {
$v = $var.split('=')
merge($memo, { $v[0] => $v[1] })
}
@WhatsARanjit
WhatsARanjit / mergepaths.pp
Created March 16, 2018 10:44
Prepend path
class test::mergepaths (
$envpath = undef,
) {
$_envpath = $envpath ? {
undef => $::path,
default => join([$envpath, $::path], ':'),
}
notify { 'newpath':
@WhatsARanjit
WhatsARanjit / groups_lookup.rb
Created January 24, 2018 19:08
What groups am I in?
#!/usr/bin/env ruby
require 'puppet'
require 'json'
Puppet.initialize_settings
require File.join(Puppet['plugindest'], 'puppet', 'util', 'nc_https.rb')
nodename = ARGV[0]
raise ArgumentError, 'Please supply a nodename' unless nodename
@WhatsARanjit
WhatsARanjit / autoloading.rb
Created November 21, 2017 18:02
Auto-loading with splat
class_name = 'foo::bar::baz'
parts = class_name.split('::')
module_name = parts.shift
file_name = parts.pop || 'init'
subdirs = parts || []
File.join('modules', module_name, 'manifests', *subdirs, "#{file_name}.pp")
@WhatsARanjit
WhatsARanjit / shell.sh
Created October 31, 2017 13:43
ERB to EPP
[root@node ~]# ./pepper.rb template.erb
<%- | String $str_foo,
Array $list,
Hash $dict,
Array $list_2,
Hash $list_3,
| -%>
My IP is <%= $str_foo %>.
@WhatsARanjit
WhatsARanjit / shell.sh
Created October 30, 2017 20:30
Parenting files
[root@puppet2017 ~]# echo -e "/tmp/foo\n/tmp/bar" > /tmp/whitelist
[root@puppet2017 ~]# ruby /root/test.rb
App_file[/tmp/foo]
App_file[/tmp/bar]
@WhatsARanjit
WhatsARanjit / out.sh
Created October 19, 2017 13:28
External fact task
# puppet task run facter_task --query 'nodes[certname]{}' fact=datacenter
Starting job ...
New job ID: 115
Nodes: 2
Started on node1 ...
Started on puppet2017.3.0.puppetlabs.vm ...
Finished on node node1
status :
Finished on node puppet2017.3.0.puppetlabs.vm