Skip to content

Instantly share code, notes, and snippets.

View upload.js
var express = require('express')
var multer = require('multer')
var upload = multer({ dest: 'uploads/' })
var app = express()
app.post('/upload', upload.single('test'), function (req, res, next) {
console.log('File received...')
console.log(req.file, req.body)
try {
View http_proxy.py
import urllib3
import json
def lambda_handler(event, context):
http = urllib3.PoolManager()
print(event)
r = http.request('POST', 'http://ip-172-31-72-37.ec2.internal/upload',
View vpc-ecs.template.yaml
---
AWSTemplateFormatVersion: "2010-09-09"
Description: "Template for ECS VPC in two AZ's"
Parameters:
VPCName:
Description: The name of the VPC being created.
Type: String
Default: "vpc-ecs (VPC For ECS with Public and Private Subnets with a NATGW)"
VPCCIDR:
View ocp-trust-private-registry.yml
# extract private registry CA or cert to a crt file
---
- hosts: all
become: yes
vars:
private_registry_fqdn: registry.example.com
tasks:
@jairojunior
jairojunior / automating-deployment-pt1.md
Last active Dec 13, 2018
Automating Deployment Strategies with Ansible - Part I
View automating-deployment-pt1.md

Automating Deployment Strategies with Ansible - Part I

Why Deployment?

When you describe your technology stack, from the bottom to the top layer: hardware, OS, middleware and application - with their respective configurations - it is easy to notice that as we go up in the stack, more frequent are the changes. Your hardware will hardly change, your operating system has a long life cycle and your middleware will keep up with applications needs, the element the most changes, even if your release cycle is long (weeks or months), applications will be the volatile.

tech stack freq of change

In "The Practice of System and Network Administration", the authors categorize the biggest "time sinkholes" in IT as: manual/non-standard provisioning of Operating Systems and application deployments. These time sink holes will consume your time, with either repetitive tasks or unplanned work.

@jairojunior
jairojunior / user-data.sh
Created Nov 30, 2018
Change SSH port during instance launching
View user-data.sh
#!/bin/sh
sed -i -e "/^#*[\\s]*Port\\s.*/s//Port 2222/" /etc/ssh/sshd_config
semanage port -a -t ssh_port_t -p tcp 2222
systemctl restart sshd
@jairojunior
jairojunior / fix-docker-bridge.yml
Created Nov 20, 2018
Change docker bridge CIDR
View fix-docker-bridge.yml
---
- hosts: nodes
tasks:
- name: Fix bridge
lineinfile:
path: /etc/sysconfig/docker
regexp: '^OPTIONS='
line: "OPTIONS='--selinux-enabled --log-driver=journald --bip 10.17.0.1/16'"
@jairojunior
jairojunior / testing-ansible-roles-with-molecule.md
Created Nov 16, 2018
Testing Ansible Roles with Molecule
View testing-ansible-roles-with-molecule.md

Testing Ansible Roles with Molecule

Tests techniques play an important role in software development, and it's no different when we are talking about Infrastructure as Code (IaC).

While developing you are always testing and constant feedback is necessary to drive your development. If you're taking to long to get feedback on a change, your steps might be too large, making errors hard to spot. Baby steps and fast feedback are the essence of TDD (Test Driven Development), but how do I apply this to the development of ad-hoc playbooks or roles?

When you're developing an automation, a typical workflow would start with a new virtual machine. We will use Vagrant to illustrate this idea, but it could be libvirt, Docker, VirtualBox or VMware used directly in your machine and even an instance in a private or public cloud or a virtual machine provisioned in your data center hypervisor (oVirt, Xen, VMware).

> NOTE: When deciding which one to use you'll have to balance feedback speed and similarity with you

View generate-rollups.rb
def missing_hours(vm_id, day)
day_hours=*(0..23)
present_hours = MetricRollup.where(:resource_id => vm_id, :resource_type => 'VmOrTemplate', :capture_interval_name => 'hourly').where("date_trunc('day', timestamp) = '#{day}'").group("resource_id").group("timestamp").select("timestamp").order("timestamp").collect { |rollup| rollup.timestamp.hour }
day_hours - present_hours
end
def generate_missing(vm_id, day)
objs = []
@jairojunior
jairojunior / jboss.yml
Created Jun 5, 2018
JBoss Ansible Modules
View jboss.yml
---
- hosts: 127.0.0.1
connection: local
environment:
JBOSS_MANAGEMENT_USER: ansible
JBOSS_MANAGEMENT_PASSWORD: ansible
JBOSS_MANAGEMENT_HOST: "10.255.0.10"
JBOSS_MANAGEMENT_PORT: 9990
tasks:
- name: Configure datasource