Skip to content

Instantly share code, notes, and snippets.

View aabouzaid's full-sized avatar
🐧
I build sustainable solutions!

Ahmed AbouZaid aabouzaid

🐧
I build sustainable solutions!
View GitHub Profile
#!/bin/bash
#5 minutes Ansible module to list groups in inventory :D
#You can see outupt of script like "JSON Pretty Print" outside Ansible by using:
#./listgroups | python -m json.tool
inventory_file=$(awk '/^hostfile/{print $3}' /etc/ansible/ansible.cfg)
groups_array=($(awk 'BEGIN {ORS=" "}; /^\[/{gsub("[\[\]]",""); print}' $inventory_file))
init_array_for_json () {
for group in ${groups_array[@]}; do
#!/bin/bash
#10 minutes Ansible module to list groups in inventory (AWK version) :D
#You can see outupt of script like "JSON Pretty Print" outside Ansible by using:
#./listgroups | python -m json.tool
awk 'BEGIN {ORS=" ";};
/^\[/{gsub("[\[\]]",""); groups_number++; groups_array[groups_number]=$0};
END {
print "{\"Inventory Groups\": [";
for (group_in_array = 1; group_in_array <= groups_number-1; group_in_array++) printf "\"%s\", ",groups_array[group_in_array];
#! /bin/python
#30 minutes Ansible module to list groups in inventory (Python version) :D
#You can print output like "pretty-print" outside Ansible by using:
#./listgroups | python -m json.tool
import os
import re
import json
#get hosts inventory from ansible.cfg file.
#! /bin/python
#Ansible module with Python to list groups in inventory (version 0.2 :D)
#You can print output like "pretty-print" outside Ansible by using:
#./listgroups | python -m json.too
import os
import re
import json
#Get hosts inventory from ansible.cfg file.
#! /bin/bash
count_chains_rules () {
awk '$1 == "Chain" { chain_name = $2 }
chain_name != $2 && $0 != "" { chains[chain_name]++ }
END { ORS="";
for (var in chains) {
print var, chains[var]-1", ";
total += chains[var]-1
}
@aabouzaid
aabouzaid / ssh_conf_to_ansible
Last active August 29, 2015 14:18
Simple snippet to reformat hosts in ssh conf file to Ansible inventory file format.
#! /bin/bash
#This snippet assume each "Host", "Hostname", "Port", "User" in separated line, and valid ssh config file.
ssh_conf_to_ansible () {
awk 'BEGIN{IGNORECASE=1}
{gsub(/\s+/," ");
gsub("Host ","");
gsub("Hostname ","ansible_ssh_host=");
gsub("Port ","ansible_ssh_port=");
gsub("User ","ansible_ssh_user=")};
#! /bin/bash
#
# You can find more info about this competition at following url:
# https://community.trueability.com/t/the-sub-par-assembler-round-1/911
#
#Main section.
spasm_dir_path="."
#spasm_dir_path="/var/lib/spasm"
print_error () {
#!/bin/bash
#
# DESCRIPTION:
# Simple -very simple :D- Nagios script to check CPanel license.
#
# SYNTAX:
# ./check_cpanel_license.sh -H SERVER_IP (or $HOSTADDRESS$ in Nagios/Opsview)
#
# BY:
# Ahmed M. AbouZaid
@aabouzaid
aabouzaid / CaesarCipher.py
Created September 30, 2015 13:41
My solution for "Caesar Cipher" challenge on HackerRank.com - https://www.hackerrank.com/challenges/caesar-cipher-1
#!/usr/bin/python
# Python 2.7.6
#
# My solution for "Caesar Cipher" challenge on HackerRank.com
# https://www.hackerrank.com/challenges/caesar-cipher-1
#
k = 2
k = k%26
n = 11
@aabouzaid
aabouzaid / prepare-commit-msg-ticket-id
Created September 25, 2020 09:39
Add JIRA ticket ID to Git commit message
#!/bin/bash
COMMIT_MSG_FILE=$1
TICKET_ID_PATTERN="INFRA-[0-9]+"
TICKET_ID=$(git symbolic-ref --short HEAD | egrep -o "${TICKET_ID_PATTERN}")
TICKET_MSG_IN_COMMIT=$(grep -c "Related to: ${TICKET_ID}" ${COMMIT_MSG_FILE})
if [[ -n "${TICKET_ID}" && ${TICKET_MSG_IN_COMMIT} -lt 1 ]]; then
echo -e "\nRelated to: ${TICKET_ID}" >> ${COMMIT_MSG_FILE}