Skip to content

Instantly share code, notes, and snippets.

knife azure server create --azure-dns-name aos-chef-poc-01 --azure-vm-size Small `
--azure-source-image 'a699494373c04fc0bc8f2bb1389d6106__Windows-Server-2012-R2-201409.01-en.us-127GB.vhd' --azure-service-location 'West US' `
--winrm-user myadmin --winrm-password 'P@ssw0rd' --bootstrap-protocol winrm --distro 'windows-chef-client-msi'
@mlapida
mlapida / Azure+ChefVM.ps1
Last active August 29, 2015 14:11
Azure + Chef VM Creation
New-AzureVMConfig -ImageName $image.ImageName -Name $VMName -InstanceSize Small -AvailabilitySetName $serviceName |
#Add VM to a domain
Add-AzureProvisioningConfig -EnableWinRMHttp -AdminUsername $VMUserName -Password $VMPassword -WindowsDomain -DomainUsername $DomainUserName -DomainPassword $DomainPassword -Domain $domain -JoinDomain $domain |
#Add a load balanced endpoint
Add-AzureEndpoint -Name "HTTP" -Protocol tcp -LocalPort "80" -LBSetName "HTTPforChef" -PublicPort "80" -DefaultProbe |
Add-AzureDataDisk -CreateNew -DiskSizeInGB 1023 -DiskLabel "Data" -LUN 0 |
Set-AzureSubnet -SubnetNames "Subnet-1" |
#Install the Chef extension
Set-AzureVMChefExtension -ValidationPem $chefpem -Windows -ClientRb $chefclient -RunList $runlist |
New-AzureVM -ServiceName $serviceName -VNetName $vnetName -Location "South Central US" -WaitForBoot
@mlapida
mlapida / AzureVMConfigXML.ps1
Created December 30, 2014 16:10
Azure: VM Export to XML
$subscription = "[Subscription here]"
Select-AzureSubscription -SubscriptionName $subscription
$cloudservice = '[Cloud Service Here]'
Get-AzureVM -ServiceName $cloudservice | foreach {
$path = 'c:\vms' + $_.Name + '.xml'
Export-AzureVM -ServiceName $cloudservice -Name $_.Name -Path $path
}
@mlapida
mlapida / azureVMAgentCheck.ps1
Created January 1, 2015 18:42
Azure: Check VM Agent Health
param (
# Define Parameters
[parameter(Mandatory=$true)]
[string]$sub,
[parameter(Mandatory=$true)]
[string]$vm,
[parameter(Mandatory=$true)]
[string]$service
@mlapida
mlapida / Get-Hero.ps1
Last active August 29, 2015 14:16
A PowerShell script to spit out a random Marvel Superhero when called. This is great for random server naming and automation.
#Hat Tip http://www.virtuallyghetto.com/2014/02/having-some-fun-with-marvel-comics-api.html
#Instructions: Aquire a Marvel API key from https://developer.marvel.com and place them in lines 63 & 64. Import this module into a VM build script and call Get-Hero to grab a random Marvel super hero.
#Imported Get-Hash function (credits http://dbadailystuff.com/2013/03/11/get-hash-a-powershell-hash-function/)
function Get-Hash
{
Param
(

Keybase proof

I hereby claim:

  • I am mlapida on github.
  • I am mlapida (https://keybase.io/mlapida) on keybase.
  • I have a public key whose fingerprint is 4FA6 EF78 A865 B98E 3004 9A74 1FB2 D101 B85F 9F75

To claim this, I am signing this object:

@mlapida
mlapida / EC2-Snapshot-Lambda.py
Last active April 29, 2022 08:10
A lambda function for taking a snapshot of all EC2 instances in a region and cleaning the snapshots up after a set number of days. This ones now works best in conjunction with Asset Tagging https://gist.github.com/mlapida/931c03cce1e9e43f147b A full write up can be found on my site https://empty.coffee/tagging-and-snapshotting-with-lambda/
import boto3
import logging
import datetime
import re
import time
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.ERROR)
@mlapida
mlapida / EC2-Stopped-Tagged-Lambda.py
Last active January 30, 2023 15:09
Using a lambda function, stop all instances that are tagged appropriately.
import boto3
import logging
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.INFO)
#define the connection
ec2 = boto3.resource('ec2')
@mlapida
mlapida / EBS-Orphaned-Report-Lambda.py
Last active April 29, 2022 08:10
Generate a report of orphaned EBS volumes and send an SNS. A full writeup can be found on my site http://mlapida.com/thoughts/lambda-tracking-orphaned-ebs-volumes
import boto3
import logging
from datetime import *
#setup simple logging for INFO
logger = logging.getLogger()
logger.setLevel(logging.WARNING)
#define the connection
ec2 = boto3.resource('ec2', region_name="us-west-2")
@mlapida
mlapida / CloudWatchLogsKinesisFirehose-Lambda.py
Last active October 3, 2019 01:01
A short Lambda Function the can be sent CloudWatch Logs (in the case Flow Logs) and send them to Kinesis Firehose for storage in S3. A full writeup can be found on my site http://mlapida.com/thoughts/exporting-cloudwatch-logs-to-s3-lambda
import boto3
import logging
import json
import gzip
from StringIO import StringIO
logger = logging.getLogger()
logger.setLevel(logging.INFO)
client = boto3.client('firehose')