Skip to content

Instantly share code, notes, and snippets.

View amhammett's full-sized avatar

Andrew Hammett amhammett

  • Sydney
View GitHub Profile

Interact with VirtualBox directly

# List Running VMs
VBoxManage list runningvms

# Save State
VBoxManage controlvm <name|uuid> savestate

# Power-off with possible data loss
node('foo') {
step('bar') {
println 'if [foobar] is not avaible, continue'
try {
foobar('me')
} catch (NoSuchMethodError _) {
echo "foobar task available with foobar plugin."
}
}
@amhammett
amhammett / ansible-adding-elements-to-arrays
Created February 21, 2018 20:20
ansible | adding elements to arrays/dictionaries
---
- name: Adding elements to Arrays and Dictionaries
hosts: localhost
connection: local
vars_files:
- ./vars/common.yml
tasks:

suppose you have a file

'foo':
'1.12'
'bar':
'4.3'

and you want to end up with the following without manually updating each file

'foo': '1.12'

@amhammett
amhammett / ansible-output-newlines.md
Created November 28, 2016 23:34
ansible | newline output

if your var has stdout_lines, prettier output is fairly easy

- debug: msg="{{foo.stdout_lines}}"

if your var doesn't, you can still have pretty output

- debug: msg="foo.stderr.split('\n')"
@amhammett
amhammett / ansible-quotes.md
Created October 7, 2016 07:19
ansible | nested quotes

ref: ansible/ansible#6006

sometimes you need have three levels of quoting.

you are unable to do the following

- name: is the application running?
  debug: msg="''{{lookup('pipe', 'ps aux | grep [f]oo.js -c')}}'' != '0'"

this is a lie, the example doesn't work but shows how double-single quotes can be used.

@amhammett
amhammett / ansible-lookup-defaults.md
Created September 29, 2016 02:03
ansible | providing defaults for environment lookups

ref: ansible/ansible#15575

Problem: Horrible dev code requires secrets to be set via environment variables.

- name: show SECRETS environment variable
  debug: msg="{{lookup('env','SECRETS')|default('foo')}}
@amhammett
amhammett / ansible-defaults.md
Created September 29, 2016 01:43
ansible | providing defaults for unset attributes in objects

defaulting unset attributes

Suppose you have some json/object which could have one of the following states.

# lookup success
{
	"applications": [{
		"id": 26097190
 }