How SELinux screws with scripts when run over VMware Tools

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

This can be solved two ways:

  • Disabling SELinux: BAD, but easy
  • Writing a custom SELinux policy: complicated but more secure

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

Replace Line In YAML While Keeping Indentation Using Ansible

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. 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. - name: Replace values in YAML file while keeping their indentation lineinfile: backup: true backrefs: true state: present path: foo. [Read More]

Looping Dates 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. [Read More]
macos  bash 

GitLab Merge Request from the CLI

Speed up your work with git by automatically creating Merge Requests for your git push

The Problem 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: Create a MR in draft state with a custom title Create a MR Create a MR and automatically merge if CI/CD pipeline succeeds Manually this is quite the process: Push branch to origin Copy link to create a MR Open the link, change fields to represent wanted state and submit The Solution GitLab offers push options1 that allow us to instruct it to do more than just plain git push. [Read More]

Download Full Website Copy

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
wget 

GumLab

My first ever product

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. [Read More]

Delete Your Old VMware Snapshots

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. Why To put it plainly, they can cause issues - like 03:00 in the morning pager alert issues and additionally eat up storage space like crazy. Degraded performance of the VM having the snapshot Degraded performance to full outages for other VMs on the same data store due to rapidly increasing snapshot sizes VMware recommends a series of steps to reduce risk when using snapshots: [Read More]

Looking back at 2020, Four Months Of Blogging

A look back on four months of blogging and engaging the PowerShell community

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 PS> $firstPost = Get-Date -Year 2020 -Month 09 -Day 13 PS> $latestPost = Get-Date -Year 2020 -Month 12 -Day 22 PS> New-TimeSpan $firstPost $latestPost | Select-Object Days Days ---- 100 So, how are things going? [Read More]

My Stand On Affiliate Links

What I think about affiliate links

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. Lets dig into it, starting with some basic assumptions I am making: Most of my posts are technical content where I do not recommend any products or services, so there are no opportunities for affiliate links to begin with In posts where I reference a product or service I do so because I think it is great and I really want to recommend it There are no negative effects for the reader when using my affiliate links There are benefits for me when you use the affiliate link, either monetary or in credit with the service - This helps me keep this blog up and running for everyone to benefit Given those assumptions I don’t see any reason why I should not use affiliate links. [Read More]

Super-Charged Cmdlet Aliases

It works like magic, but it works - Bring your aliasing to a whole other level!

Backstory 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]

Bash Utilities In Powershell

Replacing common bash utilities in 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. In this series I want to challenge this notion. PowerShell can compete with, an in some cases outperform, the quick scripts and common daily tasks done in Linux shells. [Read More]

Vmware Tools Copy Files

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"