Skip to content

Instantly share code, notes, and snippets.

View jeremymv2's full-sized avatar
🪂

Jeremy J. Miller jeremymv2

🪂
View GitHub Profile
@jeremymv2
jeremymv2 / search.rb
Last active July 18, 2017 15:28
ruby `knife status --hide-by-min xxx` replacement
require 'chef'
Chef::Config.from_file('/path/to/knife.rb')
hide_by_mins = 15700
query = "*:*"
opts = { filter_result:
{ name: ["name"], ipaddress: ["ipaddress"], ohai_time: ["ohai_time"],
run_list: ["run_list"], platform: ["platform"],
platform_version: ["platform_version"], chef_environment: ["chef_environment"] } }
@jeremymv2
jeremymv2 / install.ps1
Created July 10, 2017 14:35
Install.ps1 for Chef-Client
Function DownloadFileFromWeb($url, $file)
{
Write-Host "Downloading $file..."
[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
(New-Object System.Net.WebClient).DownloadFile($url,$file)
}
Function InstallChefClient($installer)
{
Write-Host "Installing Chef Client..."
@jeremymv2
jeremymv2 / migration.sh
Last active April 2, 2020 11:49
knife-ec-backup examples
#!/bin/bash
set -e
# Customize all these values
# youre source/destination keys and
# configs will differ
BACKUPDIR="backups"
BACKUPLOG="./migration_backup.log"
RESTORELOG="./migration_restore.log"
#!/bin/bash
set -x
# Customize all these values
# youre source/destination keys and
# configs will differ
BACKUPDIR="backups"
SRCWEBUIKEY="conf/src_webui_priv.pem"
DSTWEBUIKEY="conf/dst_webui_priv.pem"
#!/usr/bin/env ruby
require 'chef'
require 'thread'
require 'optparse'
ARGV << '-h' if ARGV.length != 4
options = {}
OptionParser.new do |opts|
@jeremymv2
jeremymv2 / gist:135d9529b702c1f307a5722b3afd4302
Last active December 16, 2016 02:05
dynamic inspec describes
control 'check-directories' do
directories = Dir.glob('/private/tmp/**/**')
directories.each do |d|
describe directory(d) do
it { should exist }
end
end
end
control 'test-the-directoies' do
@jeremymv2
jeremymv2 / gist:a1cf41bbd2d3a5250e3cf97131efa1a5
Last active January 31, 2017 22:21
Automate profile API
# Upload a profile
$ curl -X POST "https://automate-server.test/compliance/profiles/jmiller" \
-H "chef-delivery-enterprise: brewinc" -H "chef-delivery-user: jmiller" \
-H "chef-delivery-token: tzwlbWMtgBC0lo6sxkAYKSShxSJEohnU7IAE4NCUGCg=" \
--form "file=@/Users/jmiller/Devel/compliance-profiles/ssh.tar.gz" -k -D -
HTTP/1.1 100 Continue
HTTP/1.1 200 OK
Server: openresty
@jeremymv2
jeremymv2 / gist:cb34e6dfcad040b1cad50636d256b44e
Last active October 30, 2017 13:28
inspec cli Automate
Inspec Profile storage in Automate requires Automate >= 0.6.6, inspec >= 1.7.0
# login via inspec cli with data collector token
inspec compliance login_automate https://automate-server.test --insecure true --user admin --dctoken 93a49a4f2482c64126f7b6015e6b0f30284287ee4054ff8807fb63d9cbd1c506 --ent brewinc
# get user token
delivery token -u jmiller -s automate-server.test -e brewinc
# login with user token
inspec compliance login_automate https://automate-server.test --insecure true --user jmiller --usertoken tzwlbWMtgBC0lo6sxkAYKSShxSJEohnU7IAE4NCUGCg= --ent brewinc
Here we have two resources and an if statement.
The bug happens because the ::File.exist? check will run at compile time, and even though it is
after the file resource, at that point in the execution the file hasn’t actually been written yet.
The solution in this case is to use an only_if guard like:
file '/foo' do
content 'bar'
end
execute 'myapp /foo' do
afile = '/foo.txt'
file afile do
content 'bar'
end
if ::File.exist?(afile)
execute "myapp #{afile}"
end