Skip to content

Instantly share code, notes, and snippets.

@alces
alces / signalflow_metrics.go
Created November 16, 2022 11:32
Getting metrics from SignalFX
package main
import (
"fmt"
"log"
. "github.com/signalfx/signalfx-go/signalflow"
)
const (
@alces
alces / ansible_ad_hoc_inventories.md
Last active September 2, 2022 07:17
Using Ad-hoc Inventories in Ansible

In case you want to run ansible (or ansible-playbook) command against a set of hosts that makes sense only for one run, you can don't bother to create one-time inventory file, but simply define a comma-separated list of hosts as argument of --invertory option (or its short form that's simply -i) as follows:

ansible --inventory=myhost1,myhost2,myhost3 all -m setup -a 'filter=*name*'

(note that all in this command line stands for the target hostname)

If you have only one host to run your playbook against, your inventory string must ends with ,

@alces
alces / getHTTPScertificate.groovy
Last active May 16, 2022 10:33
Get an HTTPS certificates from a given URL
conn = new URL('https://www.example.com').openConnection()
conn.connect()
println conn.serverCertificates.collect {
it.toString()
}.join('\n')
conn.disconnect()
@alces
alces / list_cacerts.groovy
Last active May 16, 2022 10:33
Print a list of certificates stored in Java cacerts file
import java.security.*
ks = KeyStore.getInstance('jks')
new File('/etc/pki/java/cacerts').withInputStream {
ks.load(it, 'changeit'.chars)
}
ks.aliases().collect {
"$it: ${ks.getCertificate(it).toString()}"
@alces
alces / ansible_via_proxy_server.yml
Created December 25, 2015 08:40
Ansible playbook demonstrating easy_install, pip, and yum working via HTTP proxy
#!/usr/bin/env ansible-playbook
---
- name: test how easy_install, pip, and yum modules works via proxy
hosts: all
environment:
http_proxy: http://192.168.1.10:3128
https_proxy: http://192.168.1.10:3128
tasks:
- name: Install easy_install
yum:
@alces
alces / SetBuildEnvVars.groovy
Created December 1, 2016 07:48
Set environment variables during a Jenkins build using Groovy
// should be run as Groovy System Script
import hudson.EnvVars
import hudson.model.Environment
def build = Thread.currentThread().executable
def vars = [ENV_VAR1: 'value1', ENV_VAR2: 'value2']
build.environments.add(0, Environment.create(new EnvVars(vars)))
@alces
alces / gcloud_function_call.sh
Created March 26, 2021 12:20
Call Google Cloud function from command line
gcloud --project my-project-id \
functions call hello-world \
--data '{}' \
--region us-east1
@alces
alces / ec2_instance_creation_time.py
Created November 27, 2020 13:45
Print out "creation time" for EC2 instances (in reality, it's the first network interface attachement time)
import boto3
import datetime
# iterator over EC2 instances for region
def ec2_instances(region):
client = boto3.client('ec2', region_name = region)
for reservation in client.describe_instances().get('Reservations', []):
for instance in reservation.get('Instances', []):
yield instance
@alces
alces / ansible_pass_list.sh
Created October 1, 2020 09:18
Passing a list as a value of an external Ansible variable
ansible-playbook our_playbook.yml -e '{"our_var": ["one", "two", "three",]}'
@alces
alces / lenses-cli-groups.sh
Created July 6, 2020 12:45
Manipulating groups with lenses-cli
# Nice doc is here: https://docs.lenses.io/dev/lenses-cli/index.html
LENSES_CLI_CMD="lenses-cli --host https://10.0.17.20:9991/ --user admin --pass admin --insecure groups"
# Get the list
$LENSES_CLI_CMD get --output JSON
# Group config file
cat > config.yaml << EOF
name: windows_admins
description: "Admins from AD"