Skip to content

Instantly share code, notes, and snippets.

View trlinkin's full-sized avatar

Thomas Linkin trlinkin

View GitHub Profile
require 'json'
require 'time'
times_file = ARGV[0]
if File.file?(times_file)
times = JSON.parse(File.read(times_file))
else
puts "The argument provided was is either incorrect or not a file."
exit 1

Bolt Apply

In developing Puppet code, as with most things, the ability to iterate rapidly is essential. The ability to quickly experiment enables one to not only find the best solution, but challenge assumptions, and explore new options. Experimentation comes at a cost though, and we typically measure that in time. To make matters worse, we typically only have so much time to develop code or provide our solution before we must move on. Thus, experimentation begins to fall to the wayside as it's cost in time exceeds what we have alloted. As a result, while we may arrive a solution, the benefit of testing multiple hypothesis and the intuition for future solutions it creates is lost. Ultimately, we want to reduce the cost of experiments by removing the perceived cost in time.

The cost of an experiment is not just in the time it takes to create and run the test, but the potential cost of failing and needing to reset for the next attempt. Ideally, we want to cut the cost of time spent for the setup of

So, we want to get into the basics of using rspec-puppet to do high level automated testing for our code? Thats simple enough! The instructions below will help set you up with what is a basic "hello world" of usage. We'll start with the simplest tests we can - does it compile?

First, make sure you have the latest PDK installed. As I believe you mentioned, your modules have all been built using PDK or have been converted to be PDK compliant. Ensure that your modules are recent with the current PDK format by using pdk update on the module.

Now, the PDK will establish the scaffolding for the testing that you need. In the case we discussed we were working with a module that utilized additional modules for added functionality. We need to make sure the testing suite is aware of these dependencies for the module under test. To do this we will work with the .fixtures.yml that the PDK has placed in the module. We can either point to modules are they are on the Puppet Forge, or point to internal Git sources. You

@trlinkin
trlinkin / aug.pp
Created March 5, 2019 22:43
Augeas to resolve duplicates and set the correct entry in sshd_config
augeas { "sshd_config":
changes => [
"rm /files/etc/ssh/sshd_config/AllowTcpForwarding",
"set /files/etc/ssh/sshd_config/AllowTcpForwarding yes",
],
}
<appender name="CACHELOG" class="ch.qos.logback.core.FileAppender">
<file>/var/log/puppetlabs/console-services/console-services-cache.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">
<fileNamePattern>/var/log/puppetlabs/console-services/console-services-cache-%d{yyyy-MM-dd}.%i.log.gz</fileNamePattern>
<!-- each file should be at most 200MB, keep 90 days worth of history, but at most 1GB total-->
<maxFileSize>200MB</maxFileSize>
<maxHistory>90</maxHistory>
<totalSizeCap>1GB</totalSizeCap>
</rollingPolicy>
<append>true</append>
#!/bin/bash
fail=0
amount=0
for f in $(git diff-tree --no-commit-id --name-only -r HEAD)
do
if [[ $f =~ lib/facter/.*rb$ ]]
then
echo "Changed Made to Ruby Fact ${f} - further review needed"
fail=1
@trlinkin
trlinkin / user.json
Created June 26, 2018 17:45
Example Puppet based Task
https://puppet.com/docs/bolt/0.x/writing_tasks.html#concept-4523
if $::is_noop == true {
noop()
}
curl -k -H 'X-Authentication:<TOKEN>' \
https://<HOSTNAME>:<PORT>/orchestrator/v1/command/deploy -X POST \
-H "Content-Type: application/json" \
-d @- <<'EOD'
{
"environment" : "test-env-1",
"task" : "package",
"params" : {
"action" : "install",
"package" : "httpd"