Skip to content

Instantly share code, notes, and snippets.

@murrahjm
murrahjm / gist:b2a7af0b54583342579b6445bde81afc
Created October 19, 2023 15:41
Sample template for writing ansible modules in Powershell 7 for use on linux and windows
#!/usr/bin/pwsh
#WANT_JSON
#sample module for using powershell core instead of python for module code
#biggest different is that the legacy windows powershell functions are not available
#example uses a 'main' function as the primary executing code, providing parameter validation and error handling in a powershell-y way
$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"
- name: Influx DB
description: credential object for connecting to InfluxDB databases
inputs:
fields:
- id: influxdb_user
type: string
label: account username
- id: influxdb_pass
type: string
secret: true
@murrahjm
murrahjm / tower_patching.yml
Last active December 13, 2021 19:34
playbook to patch nodes of an ansible tower cluster while staying online
---
- name: pause nodes and install patches
hosts: all
any_errors_fatal: true
strategy: linear
serial: 1
tasks:
- name: get {{inventory_hostname }} instance id
uri:
url: "https://{{tower_alias}}/api/v2/instances?hostname={{inventory_hostname}}"
@murrahjm
murrahjm / json_compare
Created October 9, 2020 15:38
using jq to sort two json files for comparison
jq --argfile a file1.json -n 'def post_recurse(f): def r: (f | select(. != null) | r), .; r; def post_recurse: post_recurse(.[]?); ($a | (post_recurse | arrays) |= sort)' > fmt_file1.json
jq --argfile a file2.json -n 'def post_recurse(f): def r: (f | select(. != null) | r), .; r; def post_recurse: post_recurse(.[]?); ($a | (post_recurse | arrays) |= sort)' > fmt_file2.json
diff -ZEB <(jq -S . fmt_file1.json) <(jq -S . fmt_file2.json))
@murrahjm
murrahjm / psinventory.ps1
Created September 18, 2019 13:02
ansible dynamic inventory script in powershell
#!/usr/bin/env powershell
if ($args -contains '--list') {
$output = @{
'all' = @('server1.domain.com', 'server2.domain.com')
'webservers' = @('server1.domain.com')
'_meta' = @{
'hostvars' = @{
'server1.domain.com' = @{
myvar = 'metavariable'
@murrahjm
murrahjm / gist:c4d38b0667655052eb75feb828bc9644
Created October 11, 2018 19:38
Ansible tasks for bare metal provisioning of ML110 via the ilo 5 redfish REST API
---
- hosts: localhost
connection: local
gather_facts: no
vars:
- ilo_username: Administrator
- ilo_password: somesecretvalue
- serial_number: 1A2B3C456
- ilo_license: "12345-ABCDE-67890-FGHIJ-KLMNO"
tasks:
@murrahjm
murrahjm / dynamicpagewitherror.ps1
Created September 10, 2018 20:03
This is the code for my dynamic page that sometimes reports an error but sometimes works.
$DynamicBacklogListPage = New-UDPage -url "/backlog/:server/:folder" -EndPoint {
Param($server, $folder)
New-UDRow -endpoint {
$query = "Select [BacklogFiles] from [dbo].[dfsrlatestdata] Where Server = `'$server`' and ReplicatedFolder = `'$folder`'"
$BacklogFileList = @(
Foreach ($item in $(invoke-sqlcmd -MaxCharLength 25600 -connectionString $sqlconnectionstring -query $query | convertto-json | convertfrom-json).BacklogFiles.Split(',')) {
new-object psobject -Property @{
Filename = $item
}
}
@murrahjm
murrahjm / Prequel1.ps1
Last active January 18, 2018 21:05
Prequel 1 - Flawless Faction
Function Get-ComputerInfo {
Param (
[Parameter(Position=1, ValueFromPipelineByPropertyName=$True, ValueFromPipeline=$True)]
[alias('Computer','Host','Hostname','Server','ServerName')]
[String[]]$ComputerName = $env:computername,
[pscredential]$Credential = $Null
)
BEGIN{
$ErrorActionPreference = 'Stop'