Skip to content

Instantly share code, notes, and snippets.

View glennsarti's full-sized avatar
✍️
Writing code that's soon to be legacy...

Glenn Sarti glennsarti

✍️
Writing code that's soon to be legacy...
View GitHub Profile
@glennsarti
glennsarti / RunPuppetAgent.xml
Last active August 29, 2018 04:17
Running Puppet Under a Specific CodePage
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<Date>2018-08-29T11:50:32</Date>
<Author>RANDOM\USER</Author>
<URI>\RunPuppetAgent</URI>
</RegistrationInfo>
<Triggers>
<TimeTrigger>
<Repetition>

Combining PowerShell, Bolt and Puppet Tasks - Part 2

In Part 1 of this blog servies we created and ran a PowerShell script on our local computer, and then turned that into a Bolt Task. We then packaged the module so others could use the task. In Part 2 we going to look at how to test the PowerShell script.

Why test tasks?

So the most obvious question is, why would I want to test my Puppet Tasks? When we first start writing Tasks it is true that testing isn't really at the front our minds. However if you stop and look at the actions we took in Part 1, you can start to see we were actually testing our code, it was just a manual process, for example;

When we wanted to add Task metadata we did the following;

$EventLogFile = "C:\Source\tmp\PE-23563\FromTicket\DEVAPPVD-718_FAIL_SCALE\DEVAPPVD-718_FAIL_SCALE\EventViewer"
#$EventLogFile = "C:\Source\tmp\PE-23563\FromTicket\DEVAPPVD-723_SUCCESS\DEVAPPVD-723_SUCCESS\EventViewer"
Function Get-Stuff {
# Get Service Start/Stops
$SearchHash = @{
'Path' = $EventLogFile + "\System.evtx"
'ID' = 7036;
}
Get-WinEvent -FilterHashtable $SearchHash | ? { ($_.Properties[0].Value -eq 'Marionette Collective Server') -or ($_.Properties[0].Value -eq 'Puppet Agent') -or ($_.Properties[0].Value -eq 'Puppet PXP Agent') }
@glennsarti
glennsarti / module_lib_facter_infospot_facts.rb
Last active May 2, 2017 18:32
Quick and dirty custom facts for parsing a file
infospot_file = "C:/Source/testmodule/infospot.properties"
Facter.add('infospot_site') do
confine :osfamily => :windows
setcode do
begin
return unless File.exist?(infospot_file)
value = nil
File.open(infospot_file, "r") do |f|
@glennsarti
glennsarti / windows_fact.rb
Created October 19, 2016 20:53
Example WMI Chassis Query
Facter.add('windows_chassistype') do
confine :osfamily => :windows
setcode do
begin
require 'win32ole' if Puppet.features.microsoft_windows?
wmi = WIN32OLE.connect("winmgmts://./root/cimv2")
enclosure = wmi.ExecQuery("SELECT * FROM Win32_SystemEnclosure").each.first
enclosure.ChassisTypes # == [10] for a lpatop
@glennsarti
glennsarti / jjb_installer.sh
Created August 22, 2016 21:32
Python for CJC-Manager for BashOnWindows
# Install python packages
sudo apt-get install python python-pip python-virtualenv
# Install python dev packages
sudo apt-get install python-dev libxml2-dev libxslt-dev
@glennsarti
glennsarti / build-win.cmd
Created August 2, 2016 04:04
Build DSC package
@ECHO OFF
SETLOCAL
choco install 7zip -y
ECHO Cleaning...
RD "%~dp0pkg" /s/q
ECHO Building the puppet module...
@glennsarti
glennsarti / Gemfile
Created August 1, 2016 21:15
Sync Production to Staging Puppet Forges
source ENV['GEM_SOURCE'] || "https://rubygems.org"
# Determines what type of gem is requested based on place_or_version.
def gem_type(place_or_version)
if place_or_version =~ /^git:/
:git
elsif place_or_version =~ /^file:/
:file
else
:gem
@glennsarti
glennsarti / Fresh Ubutnu 14.04
Last active October 20, 2018 01:56
Installing Ruby for puppet windows devs on WSL on Win10
sudo apt-get install -y build-essential git libreadline-dev
sudo apt-get install -y libssl-dev zlib1g-dev
sudo apt-get install -y git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev
sudo apt-get install -y ruby1.9.1-dev zlib1g-dev
sudo apt-get install -y autoconf
sudo apt-get install -y libicu-dev
@glennsarti
glennsarti / Mass modsync
Created July 7, 2016 17:58
Mass modsync
bundle exec msync update -f "acl|powershell|reboot|registry|sqlserver|wsus_client" -n glennsarti -b stable -m "(maint) modulesync 724153ca2" -r ticket/stable/PUP6473
bundle exec msync update -f “choco|dism|dsc” -n glennsarti -b master -m "(maint) modulesync 724153ca2" -r ticket/master/PUP6473