Skip to content

Instantly share code, notes, and snippets.

View willthames's full-sized avatar

Will Thames willthames

View GitHub Profile
# Copyright (c) 2017 Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
DOCUMENTATION = '''
name: generator
plugin_type: inventory
version_added: "2.5"
ANSIBLE_DEBUG=1 ansible-inventory --list -i inventory/cluster.config
13396 1509411881.86061: starting run
13396 1509411881.94683: Added group all to inventory
13396 1509411881.94690: Added group ungrouped to inventory
13396 1509411881.94695: Group all now contains ungrouped
13396 1509411881.94806: Loading InventoryModule 'host_list' from /home/will/src/ansible/lib/ansible/plugins/inventory/host_list.py (searched paths: /home/will/src/ansible/lib/ansible/plugins/inventory:/home/will/src/errcd-ansible/plugins/inventory)
13396 1509411881.94827: Loading InventoryModule 'script' from /home/will/src/ansible/lib/ansible/plugins/inventory/script.py (searched paths: /home/will/src/ansible/lib/ansible/plugins/inventory:/home/will/src/errcd-ansible/plugins/inventory)
13396 1509411881.94845: Loading InventoryModule 'yaml' from /home/will/src/ansible/lib/ansible/plugins/inventory/yaml.py (searched paths: /home/will/src/ansible/lib/ansible/plugins/inventory:/home/will/src/errcd-ansible/plugins/inventory)
13396 150
$ ansible-playbook playbook.yml -i testlocal -e remote_host=testlocal
PLAY [localhost] ***************************************************************
TASK [setup] *******************************************************************
ok: [localhost]
TASK [command] *****************************************************************
fatal: [localhost -> testlocal]: FAILED! => {"changed": false, "failed": true, "module_stderr": "/bin/sh: {{: command not found\n", "module_stdout": "", "msg": "MODULE FAILURE"}
to retry, use: --limit @/home/will/tmp/ansible/playbook.retry
#!/usr/bin/env python
import collections
import json
import os
import sys
''' location returns the location portion of the hostname '''
def location(host):
@willthames
willthames / command
Created May 13, 2016 00:33
ansible register test
ansible-playbook hostname.yml -e hosts=some_ansible_group -vv
@willthames
willthames / gist:afbaaab0c9681ed45619
Last active August 29, 2015 14:06
Recreating pull requests from ansible to ansible-modules-core
git checkout branch_containing_your_commit
git rebase f35ed8a6c0dc81 # last commit before the removal of library modules
git format-patch f35ed8a6c0dc81 --stdout > /tmp/patchname.patch
git checkout devel
cd lib/ansible/modules/core/
git checkout -b branch_for_new_pull_request 417309a626 # this is before the module renames
git am -p2 /tmp/patchname.patch # -p2 here strips off the leading directory (in most cases, library)
git rebase devel
git push your_remote_for_your_fork branch_for_new_pull_request
@willthames
willthames / pkilldemo output
Last active June 19, 2018 04:04
Demo of pkill behaviour with Ansible
[will@fedora pkilldemo]$ ansible-playbook pkilldemo.yml
PLAY [localhost] **************************************************************
GATHERING FACTS ***************************************************************
ok: [127.0.0.1]
TASK: [generate random process string] ****************************************
changed: [127.0.0.1]
@willthames
willthames / npm_test.yml
Created March 22, 2014 00:57
NPM improvements
- hosts: localhost
connection: local
tasks:
- npm: name="{{item}}" path="{{installdir}}/A" global=no
with_items:
- hubot
- coffee-script
- npm: name="{{item}}" path="{{installdir}}/B" global=no
@willthames
willthames / hosts
Last active August 29, 2015 13:57
Accidentally defining a group containing a group as a group containing a host raises no error (even though there will be a host and a group with the same names).
[group-a:children]
group-b
# here group-c is actually a host because of the missing :children
[group-b]
group-c
# as a result, host-c is also a host, but doesn't belong to group-b (or group-a)
[group-c]
host-c
@willthames
willthames / dummy
Created February 10, 2014 09:37
Ansible library path merging example
#!/usr/bin/python
import json
print json.dumps({'hello': 'world'})