Skip to content

Instantly share code, notes, and snippets.

@trondhindenes
trondhindenes / .gitlab-ci.yml
Last active April 17, 2024 10:07
Run KinD (Kubernetes in Docker) as part of Gitlab CI job
#Spin up Kubernetes control plane as part of before_script, and destroys it using after_script
#Some custom logic to get to the right ip address
#Requres the gitlab docker runner, with "pass-thru" to the host docker socket.
stages:
- test
image: python:3.6.6 #the docker image you run in needs Docker installed, and access to the host docker socket.
test_integration_k8s:
tags:
#!powershell
# <COPYRIGHT>
# <CODEGENMETA>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
from hashlib import sha1
import json
def generate_cache_key(start_url, role_name, account_id):
args = {
'startUrl': start_url,
'roleName': role_name,
'accountId': account_id,
}
@trondhindenes
trondhindenes / configure-ansibletarget.ps1
Last active March 5, 2020 13:05
Configure Windows 2008R2/2012/2012R2 for SSL-based remoting
Param (
[string]$SubjectName = $env:COMPUTERNAME,
[int]$CertValidityDays = 365,
$CreateSelfSignedCert = $true
)
#region function defs
Function New-LegacySelfSignedCert
{
# Lots of other resources are created and all of that stuff works so I'm just skipping the not-so-relevant parts.
resource "aws_route_table" "private" {
for_each = toset(var.public_subnets)
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.natgw[each.key].id #this ressource exists andd is based on a foreach of the public_subnets variable, I just omitted it from the example here.
}
# Script to set a windows computer up for remoting
# The script checks the current WinRM/Remoting configuration and makes the necessary changes
# set $VerbosePreference="Continue" before running the script in order to see the output of the script
#
# Written by Trond Hindenes <trond@hindenes.com>
#
# Version 1.0 - July 6th, 2014
Param (
# Change line 138/139 from
# except AuthenticationError:
# raise AnsibleError('Invalid credentials provided.')
#to:
except AuthenticationError as e:
raise AnsibleError(str(e))
#This will surface the actual exception from azure, instead of just printing a generic one.
#It might be possible to use `(e)` instead of `(str(e))` depending on what param AnsibleError takes. It might provide more info
@trondhindenes
trondhindenes / doit.py
Last active March 29, 2019 19:43
testing out the aws-cdk for Python
#Install pips:
#aws-cdk-cdk
#aws-cdk-aws-ec2
import json
from aws_cdk import cdk
from aws_cdk import aws_ec2
app = cdk.App()
stack = cdk.Stack(app, 'MyStack')
Workflow Dummy-WFInner
{
Param (
[Parameter(Mandatory=$true)]
[PsCredential]$credential,
[Parameter(Mandatory=$true)]
[String]$subscriptionid,
[Parameter(Mandatory=$true)]
workflow set-MITPrestageADComputer
{
Param (
[String]$CompName,
[string]$OU,
$Credential
)
Write-Output "Prestaging computer $CompName, OU $OU"