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
@cchurch
cchurch / ansible.cow
Created April 18, 2014 17:33
Custom Cowsay file with (A) for Ansible
$the_cow = <<"EOC";
$thoughts ^__^
$thoughts ($eyes)\\_______
(__)\\ (A) )\\/\\
$tongue ||----w.|
|| ||
EOC
@cchurch
cchurch / hosts
Created August 13, 2014 13:08
Sample executable inventory script to read an INI and output in JSON for Ansible.
# Sample hosts file in INI format.
[webservers]
web1.example.com ansible_ssh_host=w1.example.net
web2.example.com ansible_ssh_port=1022
[webservers:vars] # Comment on a section
webvar=blah # Comment on an option
[dbservers]
@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'))
{
"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 / 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
@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 / manage.py
Created July 24, 2013 02:46
Django manage.py example to support .pyc files.
#!/usr/bin/env python
import os
import sys
def find_commands(management_dir):
# Modified version of function from django/core/management/__init__.py.
command_dir = os.path.join(management_dir, 'commands')
commands = []
try:
for f in os.listdir(command_dir):
@cchurch
cchurch / test.yml
Created November 4, 2013 18:52
Simple test Ansible playbook.
---
- hosts: all
connection: local
tasks:
- name: ping
action: ping
@cchurch
cchurch / custom_aggregate.py
Created November 26, 2013 03:42
Custom Django aggregate function for replacing average value of NULL with 0.
import django.db.models.sql.aggregates
import django.db.models.aggregates
class AvgWithZeroForNull(django.db.models.sql.aggregates.Avg):
sql_template = 'COALESCE(%(function)s(%(field)s), 0)'
django.db.models.sql.aggregates.AvgWithZeroForNull = AvgWithZeroForNull
class AvgWithZeroForNull(django.db.models.aggregates.Avg):
name = 'AvgWithZeroForNull'
django.db.models.aggregates.AvgWithZeroForNull = AvgWithZeroForNull
@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: