Skip to content

Instantly share code, notes, and snippets.

def get_hosts_for_role(role, puppetmaster="puppetmaster.mydomain.net"):
""" Query the puppetmaster for hosts of nodes whose server_role fact matches the given role """
return yaml.load(local('ssh -T {0} \'curl -s -k -H "Accept: yaml" https://localhost:8140/production/facts_search/search?facts.server_role={1}\' | awk \'!/baseami/\''.format(puppetmaster, role), capture=True)
### Keybase proof
I hereby claim:
* I am tystr on github.
* I am tylerstroud (https://keybase.io/tylerstroud) on keybase.
* I have a public key whose fingerprint is 51CB 684A 14D0 7C2D 3E41 0964 2D84 6E4B 7781 B996
To claim this, I am signing this object:
server {
listen 80;
server_name ~(?<parentjob>[^_]+)_(?<childjob>[^.]+)\.mydomain\.dev;
location / {
root /var/lib/jenkins/workspace/$parentjob/$childjob/web;
return 200 $childjob;
try_files $uri /app.php$is_args$args;
}
@tystr
tystr / deploy.sh
Created March 3, 2012 00:53
Symfony2 deploy script
#!/bin/bash
# Script variables
SF2_ENVIRONMENT=prod
REPOSITORY=
DEPLOY_BASE_DIR=/var/www
DEPLOY_DIR=$DEPLOY_BASE_DIR/`date +%s`
USAGE="Usage: $0 install|update [git_repository_url]"
# Commands
@tystr
tystr / deps
Created March 13, 2012 00:11
Pagerfanta entries for Symfony 2.0.x deps file
[pagerfanta]
git=http://github.com/whiteoctober/Pagerfanta.git
[WhiteOctoberPagerfantaBundle]
git=http://github.com/whiteoctober/WhiteOctoberPagerfantaBundle.git
target=/bundles/WhiteOctober/PagerfantaBundle
version=origin/symfony2.0
@tystr
tystr / gist:2154747
Created March 22, 2012 00:44
response listener
/**
* @param FilterResponseEvent $event
*/
public function onResponse(FilterResponseEvent $event)
{
$cookie = new Cookie('my_id', 1);
$response = $event->getResponse();
$response->headers->setCookie($cookie);
}
@tystr
tystr / autoload.php
Created March 30, 2012 22:09
phpunit autoload
<?php
// autloload.php.dist
$vendorDir = __DIR__.'/../../../../../vendor';
echo realpath($vendorDir);
require_once $vendorDir.'/symfony/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php';
use Symfony\Component\ClassLoader\UniversalClassLoader;
$loader = new UniversalClassLoader();
{
"name": "my/custom-name",
"autoload": {
"psr-0": { "": "src/" }
},
"repositories": [
{"type": "composer", "url": "http://192.168.11.5/satis/web" },
{"type" : "pear", "url": "pear.amazonwebservices.com"}
],
"require": {
@tystr
tystr / gist:3171977
Created July 24, 2012 19:12
Implementation of Vose's Alias Method
<?php
/**
* Implementation of Vose's Alias Method
*
* @param array $probabilities An array of probabilities
*
* @return int
*/
public function aliasMethod(array $probabilities)
@tystr
tystr / deploy.rb
Created October 8, 2012 22:41
Use puppet facts to retrieve a list of servers that should be deployed to via capifony
# ...
# This method fetches a list of servers to deploy to from the puppetmaster
def get_servers(system_role)
require 'net/https'
http = Net::HTTP.new("puppetmaster.hostname", 8140)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = http.get2("/production/facts_search/search?facts.system_role=#{system_role}", "Accept" => "yaml")
require 'yaml'