Skip to content

Instantly share code, notes, and snippets.

View jctanner's full-sized avatar

jctanner

View GitHub Profile
@jctanner
jctanner / gist:7199435
Last active December 26, 2015 19:09
Random Exit Code httpd server
import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
from StringIO import StringIO
import random
class RandomExitCodes(SimpleHTTPRequestHandler):
def list_directory(self, path):
f = StringIO()
@jctanner
jctanner / gist:7457226
Last active December 28, 2015 06:29
language examples
=====================================================================
- name: install formulas
action: >
homebrew
{% if item is mapping %}
name={{item.name}} state=present
{% if 'options' in item %}
install_options={{item.options}}
{% endif %}
@jctanner
jctanner / gist:7602743
Created November 22, 2013 16:31
create an ansible test zone in smartos
imgadm import a1d74530-4212-11e3-8a71-a7247697c8f2
vmadm create <<EOF
{
"alias": "ansible"
,"hostname": "ansible"
,"zfs_root_compression": "on"
,"autoboot": false
,"brand": "joyent"
,"dataset_uuid": "a1d74530-4212-11e3-8a71-a7247697c8f2"
,"max_physical_memory": 256
@jctanner
jctanner / gist:7798778
Created December 5, 2013 01:37
accelerate connection tracking
diff --git a/lib/ansible/runner/__init__.py b/lib/ansible/runner/__init__.py
index 8fec285..cda5b77 100644
--- a/lib/ansible/runner/__init__.py
+++ b/lib/ansible/runner/__init__.py
@@ -188,6 +188,10 @@ class Runner(object):
self.callbacks.runner = self
self.original_transport = self.transport
+ # PATCH
+ import uuid
@jctanner
jctanner / gist:7815571
Created December 5, 2013 22:59
random facts
````
diff --git a/lib/ansible/runner/connection_plugins/ssh.py b/lib/ansible/runner/connection_plugins/ssh.py
index 68c6f17..8f5c468 100644
--- a/lib/ansible/runner/connection_plugins/ssh.py
+++ b/lib/ansible/runner/connection_plugins/ssh.py
@@ -251,6 +251,14 @@ class Connection(object):
if p.returncode != 0 and controlpersisterror:
raise errors.AnsibleError('using -c ssh on certain older ssh versions may not support ControlPersist, s
+
@jctanner
jctanner / gist:7940393
Last active December 2, 2018 18:37
fakecloud
jtanner@u1304:~/ansible$ cat lib/ansible/runner/action_plugins/fakecloud.py
# action plugin
import re
import ansible.constants as C
from ansible import utils
from ansible import errors
from ansible.runner.return_data import ReturnData
from ansible.inventory.host import Host
from ansible.inventory.group import Group
@jctanner
jctanner / gist:8007743
Last active December 31, 2015 15:29
lineinfile guide
<Zart> let me explain how it works at el (docs are pretty unclear): first, the file is split into lines. then it searches for regexp= pattern to find a place to insert line into. if it's not found, it looks for insertbefore/insertafter markers. if regexp was found replaces matched line with line= as-is, if not inserts into insertafter marker if provided or insertbefore if provided. in absence of those append to the end of file
<Zart> all that logic works with backrefs=no
<Zart> with backrefs=yes insertafter/before are irrelevant, and the regexp=/line= becomes like sed -e s/regexp/line/ instead
<Zart> with state=absent it looks for either regexp= match or literal line= match and removes the first hit if found
<Zart> and by "file is split into lines" I mean that pattern is always matched against single lines, never multiple. so matching 'one line\nsecond line' wont work
<Zart> if there are multiple matches state=absent will remove hits one-by-one on each run, so it's not really idempotent in that case. for repl
@jctanner
jctanner / gist:8035026
Last active March 17, 2022 00:06
large fake inventory
$ cat ./0000-travis-accelerate-keys/makeinventory.py
#!/usr/bin/python
import os
import sys
import string
import epdb
import json
extra_data = " ansible_ssh_user=root ansible_ssh_host=192.168.1.148"
@jctanner
jctanner / gist:8045704
Created December 19, 2013 20:28
verbose ansible-pull patch
diff --git a/bin/ansible-pull b/bin/ansible-pull
index 78f4d21..e8a0023 100755
--- a/bin/ansible-pull
+++ b/bin/ansible-pull
@@ -45,6 +45,8 @@ import sys
import datetime
import socket
from ansible import utils
+import shlex
+import select
@jctanner
jctanner / gist:8229044
Last active January 2, 2016 01:18
CELERY + REDIS EXAMPLE
#!/usr/bin/python
####################
# ansiblecaller.py
####################
import os
import sys
import subprocess
import shlex