Skip to content

Instantly share code, notes, and snippets.

View mgedmin's full-sized avatar

Marius Gedminas mgedmin

View GitHub Profile
@mgedmin
mgedmin / gist:9547214
Created March 14, 2014 12:59
Setting up a Jenkins slave on Linux
# This is how you add a Jenkins slave
# On master:
sudo -u jenkins -H ssh-keygen
# On slave
adduser --system --group --home=/var/lib/jenkins-slave --no-create-home --disabled-password --quiet --shell /bin/bash jenkins-slave
install -d -o jenkins-slave -g jenkins-slave /var/lib/jenkins-slave
@mgedmin
mgedmin / update-tcp-ports-html.py
Created January 14, 2012 00:49
Script to convert netstat -tln output into pretty HTML
#!/usr/bin/python
"""
Update TCP port assignments page in /var/www/HOSTNAME/ports/index.html.
"""
import datetime
import optparse
import os
import pwd
import socket
@mgedmin
mgedmin / conf.py.rst
Created July 22, 2013 10:37
HOWTO add "Show on GitHub" and "Edit on GitHub" links to the Sphinx sidebar

Edit on GitHub links for Sphinx

Create _ext/ and _templates/ subdirectories.

Move edit_on_github.py into the _ext/ subdirectory.

Move sourcelink.html into the _templates/ subdirectory.

Add the following after the import sys, os line :

@mgedmin
mgedmin / letsencrypt.yml
Created June 14, 2021 08:21
Example of an Ansible playbook that uses group_by
---
- hosts: all
tasks:
- group_by: key="{{ 'using_letsencrypt' if letsencrypt_certs|default([]) else 'not_using_letsencrypt' }}"
changed_when: no
tags: always
- group_by: key="{{ ansible_distribution.lower() ~ '_' ~ ansible_distribution_release }}"
changed_when: no
tags: always
import os
from units.compat import mock
from units.compat import unittest
from ansible.modules import apt_key
class AptKeyTestCase(unittest.TestCase):
@mgedmin
mgedmin / prune_libvirt_images.py
Created June 9, 2021 10:40
prune unused vagrant-libvirt images
#!/usr/bin/python3
"""
Script to remove unused libvirt images left lying around by libvirt-vagrant.
This is a workaround for
https://github.com/vagrant-libvirt/vagrant-libvirt/issues/85
"""
import argparse
import functools
@mgedmin
mgedmin / rst-vim.md
Last active March 19, 2021 09:06
ReStructuredText + vim = ?

A list of interesting GH repos:

@mgedmin
mgedmin / strace_process_tree.py
Last active January 13, 2021 15:02
Tool to help me make sense out of `strace -f` output.
in/python
# -*- coding: UTF-8 -*-
"""
Usage:
strace-process-tree filename
Read strace -f output and produce a process tree.
Recommended strace options for best results:
@mgedmin
mgedmin / action_plugin.py
Last active November 18, 2020 16:50
Ansible module for manipulating .ini files
# put this in action_plugins/ini_file_ex.py if you want --diff to work
try:
# Ansible 2: no special hacks necessary
from ansible.plugins.action.normal import ActionModule
except ImportError:
# Ansible 1: hoist 'diff' from result.result
from ansible.runner.action_plugins.normal import ActionModule as _ActionModule
class ActionModule(_ActionModule):
'''Support --diff mode'''
@mgedmin
mgedmin / conftest.py
Created September 9, 2020 11:28
How to get a pytest progress bar in xterm title
# Put this in your top-level conftest.py
class XTermProgress:
def __init__(self, stdout=sys.stdout):
self.init(stdout)
self.session = None
self.reported = set()
self.args = []