Skip to content

Instantly share code, notes, and snippets.

View galvarado's full-sized avatar
🏠
Working from home

Guillermo Alvarado galvarado

🏠
Working from home
View GitHub Profile
@galvarado
galvarado / packer_ami_id
Created December 2, 2022 02:57
Get AMI ID from a packer build
Complete example to get the ami_id from a packer build using HCL sintaxis with a manifest post-processor and jq.
The manifest post-processor writes a JSON file with a list of all of the artifacts packer produces during a run
`
packer {
required_plugins {
amazon = {
version = ">= 0.0.2"
source = "github.com/hashicorp/amazon"
}
@galvarado
galvarado / copy_key.sh
Created November 19, 2021 22:55
Generate and copy ssh key to hosts (in order to play with ansible)
USER=someuser
PASSWORD=somepass
FILENAME="hosts.txt"
echo "Creating ssh key..."
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa -y
echo "Set StrictHostKeyChecking to no (/etc/ssh/ssh_config)..."
sed -i '/StrictHostKeyChecking/c StrictHostKeyChecking no' /etc/ssh/ssh_config
echo "Install sshpass..."
@galvarado
galvarado / update_forked_repo.sh
Created February 8, 2021 17:52
update a GitHub forked repository?
# Add the remote, call it "upstream":
git remote add upstream https://github.com/whoever/whatever.git
# Fetch all the branches of that remote into remote-tracking branches
git fetch upstream
# Make sure that you're on your master branch:
@galvarado
galvarado / create-kubeconfig.sh
Created July 21, 2020 04:43
create-kubeconfig
#!/usr/bin/env bash
# Copyright 2017, Z Lab Corporation. All rights reserved.
# Copyright 2017, Kubernetes scripts contributors
#
# For the full copyright and license information, please view the LICENSE
# file that was distributed with this source code.
set -e
source /home//stack/overcloudrc
openstack volume service list
openstack hypervisor list
openstack network agent list
# Variables
ENDPOINT='dashboard.shcp.gob'
USER='admin'
PASSWORD='wyd0903hw5qdi'
echo -e "\n\n########## Containers unhealthy ##########\n\n"
docker ps | grep unhealthy
echo -e "\n\n########## Pacemaker Status ##########\n\n"
pcs status
echo -e "\n\n########## RabbitMQ Status ##########\n\n"
docker exec -ti $(docker ps | grep -oP "rabbitmq-bundle-docker-[0-9]+") rabbitmqctl cluster_status
echo -e "\n\n########## Galera Status ##########\n\n"
docker exec -ti $(docker ps | grep -oP "galera-bundle-docker-[0-9]+") mysql -e "SHOW GLOBAL STATUS LIKE 'wsrep_%'" | grep -E -- 'wsrep_local_state_comment|wsrep_evs_state'
echo -e "\n\n########## Redis Status ##########\n\n"
docker exec -ti $(docker ps | grep -oP "redis-bundle-docker-[0-9]+") ps -efw
username="myusername"
hash="$(echo -n 'thenewpass{s4lt}' | sha256sum | awk '{print $1;}')"
echo "Changing password for $username"
echo "Password encrypted with SHA-256"
sed -i -E "s/(<passwordHash>.+)/<passwordHash>s4lt:$hash<\/passwordHash>/" /var/lib/jenkins/users/$username/config.xml
echo "Replaced succesfully, restarting jenkins service..."
service jenkins restart
^(?<time>^(\d{4})-(\d{2})-(\d{2}) (\d{2}):(\d{2}):(\d{2}(\.\d{3})?)) (?<id>(\d)*)?\s?(?<severity>(INFO|ERROR|WARNING|CRITICAL)) (?<component>([A-Za-z,\.,\,\_]*(\.)*))+ (?<description>([A-Za-z,\.,\[,\],\s,\:,\-,\d,\(,\),\=,\/,\',\",\_,{,}]*))$
Test case:
2015-10-14 17:16:19.330 INFO nova.osapi_compute.wsgi.server [req-bef63dd4-2450-47ab-92f1-b4388a747ba7 admin demo] 104.131.138.224 "GET /v2.1/ceddd0c4f5214101b2026aef64797d51/limits HTTP/1.1" status: 200 len: 779 time: 0.2924919{}
@galvarado
galvarado / Libvirt XML example
Created August 25, 2014 22:25
Libvirt XML example
<domain type='kvm'>
<name>instance-00000xxx</name>
<uuid>xxxxxxxxxxxxxxxxxx</uuid>
<memory>1048576</memory>
def generate(request):
'''
Generate PDF
'''
data = {'response': 0}
if request.method == 'POST':
css_rules = '''
.redalpha60 {
/* Fallback for web browsers that don't support RGBa */
background-color: rgb(255, 0, 0);