Skip to content

Instantly share code, notes, and snippets.

View samdoran's full-sized avatar

Sam Doran samdoran

View GitHub Profile
@samdoran
samdoran / Examples
Last active September 2, 2016 15:40
pasteboard
# Patch files from command line
$ cd ~/ansible-playbooks/playbooks/
$ ansible-playbook -i ~/temp_patches patch_things.yml -e 'target_hosts=all'
# Load ad-hoc inventory patches into Ansible Tower
$ tower-manage inventory_import --source patch_hosts --inventory-name Patches --overwrite --overwrite-vars
===========
# Playbook
- name: Patch all the things
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from random import choice
from ansible.plugins.lookup import LookupBase
class LookupModule(LookupBase):
def run(self, terms, **kwargs):
count = terms.pop(0)
sdoran@sdoran-OSX ~/P/A/P/playbooks (master) [1]> ansible --version
ansible 2.2.0.0
config file = /Users/sdoran/.ansible.cfg
configured module search path = Default w/o overrides
-----------------------
sdoran@sdoran-OSX ~/P/A/P/playbooks (master) [2]> ansible-playbook -i inventory/home vyos.yml -vvv
Using /Users/sdoran/.ansible.cfg as config file
@samdoran
samdoran / cloudforms.py
Created May 31, 2017 16:28
Cloudforms Dynamic inventory with filtering
#!/usr/bin/env python
# vim: set fileencoding=utf-8 :
#
# Copyright (C) 2016 Guido Günther <agx@sigxcpu.org>
#
# This script 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.
#
@samdoran
samdoran / hosts
Last active June 19, 2017 22:29
Test fact delegation
[lab]
lab-1 ansible_host=10.77.1.11
lab-2 ansible_host=10.77.2.11
lab-3 ansible_host=10.77.3.11
@samdoran
samdoran / docktest.fish
Created July 5, 2017 18:01
Fish function to test Ansible roles inside a Docker container
function docktest --description "Test an Ansible role inside a container"
while set -q argv[1]
switch $argv[1]
case '-h' '--help'
echo "-h --help Print out help"
echo "-n --nuke Stop and destroy test container"
echo "-r --rolepath Path to role. Defaults to current directory."
echo "-i --image Docker image OS to run. Defaults to centos7."
set -e argv[1]
@samdoran
samdoran / taskfiles.yml
Created July 12, 2017 14:59
Get a list of task files and run them
- hosts: somehosts
become: yes
tasks:
- name: Get list of task files
find:
paths: /opt/ansible/tasks
patterns: '*.yml'
register: _task_files
@samdoran
samdoran / find_a_playbook.yml
Last active December 23, 2021 00:00
Find a playbook and include it using a lookup
- include: "{{ lookup('pipe', 'find /path/to/search -type f -name cluster.yml') }}"
@samdoran
samdoran / ec2_instances.json
Last active August 23, 2017 17:41
ec2.py output
{
"instances": [
{
"kernel": null,
"root_device_type": "ebs",
"private_dns_name": "ip-172-31-23-35.us-east-2.compute.internal",
"public_ip": "18.220.201.254",
"private_ip": "172.31.23.35",
"id": "i-02d9de367d3e62929",
"ebs_optimized": false,
@samdoran
samdoran / getvaultkey.sh
Created September 13, 2017 17:44
Fetch Ansible Vault password from macOS keychain
#!/bin/bash
# Get Ansible Vault password from macOS Keychain
#
# You will need to create a new password item in the login keychain
SECURITY_BIN=$(which security)
set_vault_account() {