Skip to content

Instantly share code, notes, and snippets.

View samdoran's full-sized avatar

Sam Doran samdoran

View GitHub Profile
@samdoran
samdoran / generate-inventory.py
Created October 31, 2019 15:28
Generate an Ansible inventory with a lot of hosts
#!/usr/bin/env python
import argparse
import os
import sys
import yaml
parser = argparse.ArgumentParser()
parser.add_argument('--number', '-n', default=100)
parser.add_argument('--name', '-f', default='hosts.yml')
@samdoran
samdoran / anisble-py38-st
Created October 16, 2019 16:54
Python 3.8 stack trace
Traceback (most recent call last):
File "/Users/sdoran/Source/ansible/bin/ansible-playbook", line 110, in <module>
exit_code = cli.run()
File "/Users/sdoran/Source/ansible/lib/ansible/cli/playbook.py", line 123, in run
results = pbex.run()
File "/Users/sdoran/Source/ansible/lib/ansible/executor/playbook_executor.py", line 169, in run
result = self._tqm.run(play=play)
File "/Users/sdoran/Source/ansible/lib/ansible/executor/task_queue_manager.py", line 249, in run
play_return = strategy.run(iterator, play_context)
@samdoran
samdoran / merge-pr.py
Created October 14, 2019 21:16
Merge GitHub PRs when the web UI is being dumb
#!/usr/bin/env python
import argparse
import re
import os
from github3 import GitHub
parser = argparse.ArgumentParser()
parser.add_argument('prs', nargs='+')
require "language/haskell"
class Shellcheck < Formula
include Language::Haskell::Cabal
desc "Static analysis and lint tool, for (ba)sh scripts"
homepage "https://www.shellcheck.net/"
url "https://github.com/koalaman/shellcheck/archive/v0.4.6.tar.gz"
sha256 "1c3cd8995ebebf6c8e5475910809762b91bebf0a3827ad87a0c392c168326de2"
head "https://github.com/koalaman/shellcheck.git"
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (c) 2019 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'network'}
@samdoran
samdoran / reboot.yml
Last active April 24, 2019 19:49
Soft reboot, then hard reboot
- hosts: lab-centos7
become: yes
gather_facts: yes
module_defaults:
group/cpm:
cpm_url: oob.r1.acme.com
cpm_username: "{{ vault_cpm_username }}"
cpm_password: "{{ vault_cpm_password }}"
use_https: yes
@samdoran
samdoran / test_sunos_get_uptime_facts.py
Last active April 11, 2019 21:19
Example pytest unit test
import time
from ansible.module_utils.facts.hardware import sunos
def test_sunos_get_uptime_facts(mocker):
kstat_output = '\nunix:0:system_misc:boot_time\t1548249689\n'
module_mock = mocker.patch('ansible.module_utils.basic.AnsibleModule')
module = module_mock()
module.run_command.return_value = (0, kstat_output, '')
require 'formula'
class Sshpass < Formula
url 'http://sourceforge.net/projects/sshpass/files/sshpass/1.06/sshpass-1.06.tar.gz'
homepage 'http://sourceforge.net/projects/sshpass'
sha256 'c6324fcee608b99a58f9870157dfa754837f8c48be3df0f5e2f3accf145dee60'
def install
system "./configure", "--disable-debug", "--disable-dependency-tracking",
"--prefix=#{prefix}"
def _maketrans(self, replace_chars, replacement_chars, delete_chars):
if PY3:
return str.maketrans(replace_chars, replacement_chars, delete_chars)
if not isinstance(replace_chars, text_type) or not isinstance(replacement_chars, text_type):
raise ValueError('replace_chars and replacement_chars must both be strings')
if len(replace_chars) != len(replacement_chars):
raise ValueError('replacement_chars must be the same length as replace_chars')
table = dict(zip((ord(c) for c in replace_chars), replacement_chars))