Skip to content

Instantly share code, notes, and snippets.

View diversemix's full-sized avatar
🎯
Focusing

Peter Hooper diversemix

🎯
Focusing
View GitHub Profile
@diversemix
diversemix / test.playbook
Created January 6, 2016 11:02
Ansible playbook, using if else syntax to call a handler
---
- hosts: balancer
sudo: yes
serial: 1
vars:
switch: False
name_of_handler: "{{ 'call_this' if switch else 'call_that' }}"
handlers:
@diversemix
diversemix / recusive_npm_install.sh
Created May 19, 2016 08:35
Recusively install npm packages in all the directories below this one
#!/bin/bash
for a in `ls -1`
do
pushd $(dirname $a)
echo ========== `pwd`
npm install
popd
done
@diversemix
diversemix / create_test_vm.sh
Last active June 8, 2016 12:12
[KVM] Creates a test VM with Centos7
#!/bin/bash
sudo virt-install --connect qemu:///system \
-n mytest \
-r 4096 \
--vcpus=4 \
--disk path=/home/vm/images/my_test.img,size=40 \
--graphics vnc,listen=0.0.0.0 \
--noautoconsole \
--os-type linux \
@diversemix
diversemix / clone_base_vm.sh
Created May 19, 2016 10:46
[KVM] Cloning a base VM image
#!/bin/bash
virt-clone --original test_base \
--name new_test \
--file /home/vm/images/new_test.img \
--auto-clone
@diversemix
diversemix / kvm_workaroud.sh
Last active June 1, 2016 11:32
[KVM] Modify definition - bug workaround
# Currently there is a bug (fixed in virt-manager-1.3.2-1.el7) so you will need to edit the xml to remove the channel definition:
NAME=new_test
virsh dumpxml ${NAME} > ${NAME}.xml
virsh undefine ${NAME}
vi ${NAME}.xml ; virsh define ${NAME}.xml ; virsh start ${NAME}
@diversemix
diversemix / self-signing.txt
Created May 24, 2016 08:28
How to create a self-signed certificate
openssl genrsa -out server.key 4096
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
Now copy to the right config folder:
cp server.crt /<configuration folder>/ssl.crt
cp server.key /<configuration folder>/ssl.key
@diversemix
diversemix / test_switch_handler.playbook
Created June 1, 2016 11:33
Test to see if ansible version supports switching the handler based on var
---
- hosts: balancer
sudo: yes
serial: 1
vars:
switch: False
name_of_handler: "{{ 'call_this' if switch else 'call_that' }}"
handlers:
@diversemix
diversemix / install_a_service.sh
Created June 8, 2016 14:45
Installing a service from scripts.
#!/bin/bash
set -x
systemctl stop $1
systemctl disable $1
systemctl daemon-reload
systemctl reset-failed
systemctl status $1 && exit 1
ls -l /etc/systemd/system/$1*
@diversemix
diversemix / docker_registry_funcs.sh
Created June 13, 2016 15:22
[docker] functions to access the registry api v2
#!/bin/bash
HOST=my_registry
getJsonVal () {
python -c "import json,sys;sys.stdout.write(json.dumps(json.load(sys.stdin)$1))";
}
get_tags () {
i_name=$1
@diversemix
diversemix / crontab
Created June 28, 2016 12:16
crontab skeleton
# ┌───────────── min (0 - 59)
# │ ┌────────────── hour (0 - 23)
# │ │ ┌─────────────── day of month (1 - 31)
# │ │ │ ┌──────────────── month (1 - 12)
# │ │ │ │ ┌───────────────── day of week (0 - 6) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * command to execute