Blog

All my posts and notes. (Browse by tags)

Replace Line In YAML While Keeping Indentation Using Ansible

Notes | 2021-08-08 (updated 2025-10-25) | 1 min read
#ansible #yaml

In theory Ansible should be declarative and have full control over the systems we touch with it.

In practice, this is unfortunately not always the case.

This combination of tasks loads a given yaml file from the remote host, combines a “overwrite dict” onto it, and writes the file back to disk.

- name: Load yaml file contents as fact
  ansible.builtin.slurp:
    src: /etc/some-file.yaml
  register: yaml_file

- name: Parse yaml file contents
  ansible.builtin.set_fact:
    yaml_file_content: "{{ yaml_file.content | b64decode | from_yaml }}"

- name: Create the keys/values that should be overwritten
  ansible.builtin.set_fact:
    yaml_file_content_overwrite:
      some:
        key: "Overwrite value"
      another: "Also overwritten"

- name: Write yaml file with changed values
  ansible.builtin.copy:
    content: "{{ yaml_file_content | combine(yaml_file_content_overwrite, recursive=true) | to_yaml }}"
    dest: /etc/some-file.yaml
I like keeping my learning public. The below is my very old and naive solution I did based on regex.

With this nifty task we can replace the value of a key (given as yaml_key) to a new value (given as new_value) while preserving it’s indentation.

Read more…

How SELinux screws with scripts when run over VMware Tools

Notes | 2021-08-08 (updated 2025-10-25) | 1 min read
#ansible #automation #linux #security #selinux #sysadmin #vmware

SELinux by default prohibits certain things from working through VMware tools (Ansible connection or plain API).

This can be solved two ways:

Note: Adding/Changing this policy through a VMware tools connection is thankfully possible

Example policy

This policy is the base for a VMware tools policy and allows entering the rpm context (yum).

module custom-vmtools 1.0;

require {
        type rpm_script_t;
        type vmtools_unconfined_t;
        class process transition;
}

#============= vmtools_unconfined_t ==============

allow vmtools_unconfined_t rpm_script_t:process transition

curl: Modify DNS Resolution

Notes | 2021-08-08 (updated 2025-10-25) | 1 min read
#curl #productivity #sysadmin

You can intercept normal name resolution in curl with the --resolve parameter allowing you to do things like talk to a specific site of a DNS load-balanced setup or talk to a new deployment not yet made productive.

You can specify the resolve option multiple times so you can even catch redirects and move them to where you want as well.

It’s important to note that this intercept does only work on the ports you specify in the entries.

Read more…

Looping Dates macOS

Notes | 2021-08-07 (updated 2025-10-25) | 1 min read
#bash #macos

date on MacOS does not support --date, so a workaround is needed. Converting Date to unix epoch, adding one day in epoch and converting back.

The Scripty Way

Taken from a blog post

#!/bin/zsh

start=$year-01-01
end=$year-12-31
currentDateTs=$(date -j -f "%Y-%m-%d" $start "+%s")
endDateTs=$(date -j -f "%Y-%m-%d" $end "+%s")
offset=86400

while [ "$currentDateTs" -le "$endDateTs" ]
do
  date=$(date -j -f "%s" $currentDateTs "+%Y-%m-%d")
  echo $date
  currentDateTs=$(($currentDateTs+$offset))
done

The Brew Way

As I found out long after writing the above you can simply brew install coreutils and get a date command with the --date option. The only thing to note there is this: Commands also provided by macOS have been installed with the prefix "g".

Read more…

GitLab Merge Request From the CLI

Posts | 2021-05-06 (updated 2025-10-23) | 2 min read
#git #gitlab #productivity

You want to push a branch to GitLab and automatically create a Merge Request (MR) for it.

There are effectively three scenarios this can cover:

Read more…

Download Full Website Copy

Notes | 2021-04-01 (updated 2025-10-25) | 1 min read
#wget

Sometimes it’s nice to download a best effort version of a website, for example before completely redesigning it.

domain=WEB.SITE
wget $domain --recursive --no-clobber --page-requisites --html-extension --convert-links --restrict-file-names=windows --domains $domain

Linked: Powershell PSDefaultParameterValues

A deep dive into PowerShell parameter defaults

Posts | 2021-03-27 (updated 2025-10-23) | 1 min read
#linked-posts #powershell

I published a post about how to work with parameter defaults in PowerShell over on the ScriptRunner blog.

Read now: English or Deutsch

The Null-Coalescing Operator

A Closer Look at the Null-Coalescing Operator and How It Can Help Us in Writing Smarter, More Concise Scripts.

Posts | 2021-03-22 (updated 2025-10-23) | 1 min read
#powershell #snippets

Today we take a closer look at the null-coalescing operator and how it can help us in writing smarter, more concise scripts.

Read more…

Renovate Bot

Notes | 2021-02-12 (updated 2025-10-25) | 1 min read
#renovate-bot #slashpage-uses

My tool of choice for doing dependency maintenance/update type of stuff for both [[infrastructure-as-code]] and [[software-projects]]

Gumlab

My first ever product

Posts | 2021-01-04 (updated 2025-10-23) | 1 min read
#indie-hacking #personal #products

As part of my goal to write a book I began looking at how to build a following and where to sell the book once it’s finished.

On this journey I found Gumroad, a great place to sell digital products.

Given my idea to sell a comprehensive library of code snippets besides the actual book I took a look at existing integrations between it and GitLab.com, my preferred git host.

Unfortunately I could not find any ready made solution, but given the great APIs from Gumroad and GitLab I set out to build one. The result is GumLab, a easy way to sell access to GiLab projects through Gumroad.

Read more…

Delete Your Old VMware Snapshots

Posts | 2021-01-01 (updated 2025-10-22) | 3 min read
#powershell #sysadmin #vmware-powercli

For the love of Pete, please delete your old snapshots regularly!

Old snapshots have caused incidents and even outages more than once in my career and it is really easy to preemptively look for them and get them removed before anything happens.

Read more…

How to Find With PowerShell

Finding Files, Do I Even Need to Describe How Important This Is?

Posts | 2020-12-31 (updated 2025-10-23) | 5 min read
#powershell
Series: Bash to PowerShell

Finding files, do I even need to describe how important this is?

Read more…

Looking Back at 2020, Four Months of Blogging

A Look Back on Four Months of Blogging and Engaging the PowerShell Community

Posts | 2020-12-22 (updated 2025-10-23) | 4 min read
#personal #yearly-review

The year is coming to an end, with all its ups and downs 2020 surely was challenging to say the least. I wanted to take this time to openly reflect on my first couple months of blogging and what the future holds for ps1.guru

Read more…

Affiliate Links

What I think about affiliate links

Posts | 2020-12-17 (updated 2025-10-23) | 1 min read
#opinion #personal

Lets talk about affiliate links for a moment.

TLDR: I will use affiliate links where it is possible for me, which isn’t often to be honest.

Read more…

Super-Charged Cmdlet Aliases

It Works Like Magic, but It Works - Bring Your Aliasing to a Whole Other Level!

Posts | 2020-12-02 (updated 2025-10-23) | 4 min read
#powershell #productivity

I recently wrote a post about PowerShell Aliasing for the folks over at ScriptRunner.

The one issue I had while researching for this post was this:

You can not create a alias for a function and overwrite one of it’s parameters at the same time while keeping nice features like tab-complete.

For a concrete example of this visit please look at the original post.

At the end of the post I asked if anyone had a solution to this problem - and the internet delivered!

Read more…

Linked: Powershell Aliasing

A deep dive into aliasing with PowerShell

Posts | 2020-12-02 (updated 2025-10-23) | 1 min read
#linked-posts #powershell

I published a post about aliasing with PowerShell over on the ScriptRunner blog.

Read now: English or Deutsch

Powershell 7

Why Installing PowerShell on Windows May Actually Be a Good Idea

Posts | 2020-11-28 (updated 2025-10-23) | 2 min read
#powershell #windows

Q: Wait a minute! Don’t I already have PowerShell?

A: Yes. However you may want to continue reading because things are never as simple as they appear.

Read more…

Collections And Randomization

Randomize Collections in PowerShell

Posts | 2020-11-18 (updated 2025-10-23) | 2 min read
#powershell

Randomizing a collection is useful in a variety of situations and in most languages it is fairly straight forward.

Read more…

How To Grep With PowerShell

It's just like Bash, but more powerful!

Posts | 2020-09-30 (updated 2025-10-23) | 4 min read
#powershell
Series: Bash to PowerShell

Filtering data, from log or config files to data returned by an api, is an important operation to remove noise from it and make further analysis possible.

Read more…

How to Tail With PowerShell

How to Replace Tail in PowerShell

Posts | 2020-09-21 (updated 2025-10-26) | 3 min read
#powershell
Series: Bash to PowerShell

Printing the last or first, few lines of a file is a common operation in day to day operations. On Linux most people will, without thinking twice, use tail and it’s counterpart head to achieve this.

Read more…

Bash Utilities in Powershell

Replacing Common Bash Utilities in PowerShell

Posts | 2020-09-20 (updated 2025-10-23) | 1 min read
#powershell
Series: Bash to PowerShell

Whats the first thing coming to mind when seeing a command line?

For most people it is Linux, be it Ubuntu, Debian or RedHat. And it is completely understandable. A big part of our industry has a background in Linux and sees it as the superior system for quick scripts and the like.

Read more…

Vmware Tools Copy Files

Notes | 2020-09-17 (updated 2025-10-25) | 1 min read
#powershell #vmware

Docs

Copy To Guest

$vm = Get-VM -Name TEST
Get-Item "X:\yourfile.txt" | Copy-VMGuestFile -Destination "c:\temp" -VM $vm -LocalToGuest -GuestUser "Administrator" -GuestPassword "Pa$$w0rd"

Copy From Guest

$vm = Get-VM -Name TEST
Copy-VMGuestFile -Source c:\yourfile.txt -Destination c:\temp\ -VM $vm -GuestToLocal -GuestUser "Administrator" -GuestPassword "Pa$$w0rd"

Hello World

Who am I and what to expect on this blog

Posts | 2020-09-13 (updated 2025-10-23) | 1 min read
#personal

Read more…

Ansible VMware Connection Plugin & Become

Notes | 2020-07-02 (updated 2025-10-25) | 1 min read
#ansible #vmware

When using VMware as the connection plugin to connect to remote hosts you commonly set two facts for username and password:

ansible_vmware_tools_user: "mkamner"
ansible_vmare_tools_password: "Super Secret PW"

This will work just fine for windows and with many tasks on linux.

However, if you want to use become: true on linux it will fail with the strangest error messages.

For example: apt will fail, because it can’t acquire the lock file

The solution is rather simple, become does not honor the VMware facts set, instead it wants two different facts set:

Read more…

IANA To openSSL Ciphers

Notes | 2020-03-07 (updated 2025-10-25) | 1 min read
#openssl

Handy table to map IANA IDs of ciphers to their openSSL IDs used in web server configurations, for example [[nginx]] ssl_ciphers or proxy_ssl_ciphers

https://testssl.sh/openssl-iana.mapping.html

Python

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#python #slashpage-uses

These days Python is my language of choice for both simple scripts and more complex backend applications, usually in combination with [[django]]

PowerShell

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#powershell #slashpage-uses

PowerShell holds a special place in my heart as it was the first ever tool I dived into deeply and used to automate my daily work.

To this day it runs a bunch of fundamental automations in my life.

MacOS

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#macos #slashpage-uses

My operating system of choice on the client, usually on a MacBook Pro.

Kustomize

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#kustomize #slashpage-uses

My prefered tool for writing and provisioning home-built manifests to [[kubernetes]]

Kubernetes

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#k8s #slashpage-uses

I have run and am still running loads of Kubernetes clusters, mostly on-premise.

JQ

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#jq #slashpage-uses

A incredibly powerful tool for manipulating the heaps of JSON files and responses I interact with daily.

A lot of times I also use ijq1 instead, which is a interactive version of jq.

Hugo

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#hugo #slashpage-uses #ssg

My static site generator of choice, used to build my blog among other things.

Helm

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#helm #slashpage-uses

A good way to pull in external dependencies into Kubernetes For writing my own manifests I prefer to use Kustomize.

GitLab

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#gitlab #slashpage-uses

My preferred git server and CI/CD system, either gitlab.com or self-hosted.

Django

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#django #slashpage-uses

My preferred framework for building web apps

ArgoCD

Notes | 2020-01-01 (updated 2025-10-25) | 0 min read
#argocd #slashpage-uses

Ansible

Notes | 2020-01-01 (updated 2025-10-25) | 1 min read
#ansible #slashpage-uses

Need to automate a VM? you need Ansible!

vCenter Cert Bundle

Notes | 2019-05-13 (updated 2025-10-25) | 1 min read
#powershell #vmware

Errors connecting to vCenter or any ESXi server in the cluster without certificate errors?

VMware KB