Skip to content

Instantly share code, notes, and snippets.

View cchurch's full-sized avatar
🤖
I'm not a robot.

Chris Church cchurch

🤖
I'm not a robot.
View GitHub Profile

Keybase proof

I hereby claim:

  • I am cchurch on github.
  • I am flyingfred0 (https://keybase.io/flyingfred0) on keybase.
  • I have a public key ASBNH4qEsFwxMks88hGONV4ujTBGyV2t6vPGRVpY0NHhRgo

To claim this, I am signing this object:

@cchurch
cchurch / ansible-inventory
Last active March 30, 2017 19:43
Standalone ansible-inventory script based on https://github.com/bcoca/ansible/blob/a689d6a54bcaff2e686c95f0933a9b3519e9c209/lib/ansible/cli/inventory.py (variables defined under group_vars are not listed separately but still included in host variables)
#!/usr/bin/env python
# (c) 2017, Brian Coca <bcoca@ansible.com>
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
@cchurch
cchurch / timeout.py
Created November 16, 2016 22:05
Timeout class - initialize with a duration, evaluates as boolean True until timeout has expired.
# Python
import time
__all__ = ['Timeout']
class Timeout(object):
def __init__(self, duration=None):
# If initializing from another instance, create a new timeout from the
@cchurch
cchurch / xmlsec_fix.py
Last active August 10, 2016 20:53
Quick fix for xmlsec initialize issue (copy into /etc/tower/conf.d/). Related to https://github.com/onelogin/python-saml/pull/149
import threading
xmlsec_init_lock = threading.Lock()
xmlsec_initialized = False
import dm.xmlsec.binding
original_xmlsec_initialize = dm.xmlsec.binding.initialize
def xmlsec_initialize(*args, **kwargs):
global xmlsec_init_lock, xmlsec_initialized, original_xmlsec_initialize
with xmlsec_init_lock:
@cchurch
cchurch / github_pipeline.py
Created November 12, 2015 20:39
Custom Python social auth pipeline functions to fetch a GitHub user's orgs # and teams.
# Custom Python social auth pipeline functions to fetch a GitHub user's orgs
# and teams.
def fetch_github_user_orgs(backend, details, user=None, *args, **kwargs):
if not user or not hasattr(backend, 'get_json'):
return
response = kwargs.get('response') or {}
if 'organizations_url' not in response or 'access_token' not in response:
return
orgs = backend.get_json(response['organizations_url'],
@cchurch
cchurch / ratelimit.py
Created August 5, 2015 15:03
Ansible callback plugin example for rate limiting tasks
# Python
import time
class CallbackModule(object):
'''
Delay after Rackspace DNS API requests to avoid rate limit (20/minute).
'''
def _rate_limit(self):
role_name = getattr(getattr(self, 'task', None), 'role_name', '')
@cchurch
cchurch / ping_on_windows.yml
Created July 25, 2015 16:49
Proof of concept to run Python ping module on Windows with Ansible
---
- hosts: windows
gather_facts: false
vars:
ansible_python_interpreter: python
tasks:
- win_chocolatey:
name: python2
state: present
{
"log": {
"id": "http://192.168.43.81:8080/api/collections/nodes/node1/log",
"name": "log"
},
"tags": [],
"facts": {
"hardwareisa": "x86_64",
"macaddress": "08:00:27:e7:06:4d",
"architecture": "x86_64",
@cchurch
cchurch / ConfigureForAnsible.ps1
Created November 29, 2014 16:50
Powershell to Download/Run Script for Configure for Ansible Remoting
iex ((new-object net.webclient).DownloadString('https://raw.githubusercontent.com/ansible/ansible/devel/examples/scripts/ConfigureRemotingForAnsible.ps1'))
@cchurch
cchurch / py2clixml.py
Created October 22, 2014 22:52
Convert basic Python objects to PowerShell CLIXML format
def clixml(a, top=True):
import xml.etree.ElementTree as ET
if top:
objects = ET.Element('Objects')
obj = clixml(a, top=False)
obj.tag = 'Object'
objects.append(obj)
return ET.tostring(objects)
elif a is None:
return ET.Element('Property')