/dev/blog/ID10T

Advertisement

Introducing Codebites

• Blog • Comments

YAML CodebiteThere is very little post activity on my Blog. Creating posts is no cakewalk, additionally I often don’t see the public interest for a lot of topics. That’s why I added a new feature to the Blog today, Codebites. Codebites are intended to be more “Memo like” posts than real Blog posts. As such, they will be “low detail” creations, the default Codebites site is thusly sorted by category. Little or even no explanatory text, just copy and pastes of solutions and - perhaps - the problem in itself. I hope to put out more of these bites than my current 12 blog posts per year.
As Codebites are a drastically different approach to normal blog posts, I don’t want to bother my current RSS feed subscribers with it (side note: I don’t know if anybody is even reading my RSS feed, I didn’t bother to add any tracking). The current “default feed” will stay the same, only containing full fledged Blog posts. I created two new feeds, one for Codebites only and one containing everything.

The first (rather trivial) Codebite is already online: Ansible: Add two lists, then filter with third list

In other news: I’m aware of the oversized Google Ads, I’ll look into solving that issue in the near future.

Fixing HTTP 405 errors with httpd 2.4 WebDAV

• httpd and Webdav • Comments

While updating an Apache httpd from 2.2 to 2.4 we encountered a strange problem. The web server is used as a reverse proxy for a WebDAV application. Therefore the original httpd 2.2 directive allowed a couple of WebDAV methods. It looked similarly to this:

<Location "/dav">
  <LimitExcept HEAD GET POST CONNECT PUT DELETE OPTIONS PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK TRACE>
    Order       deny,allow
    Allow       from all
  </LimitExcept>
</Location>

Adapting this to httpd 2.4 was not a big deal:

<Location "/dav">
  AllowMethods HEAD GET POST CONNECT PUT DELETE OPTIONS PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK TRACE
  Require all granted
</Location>

But this didn’t work as expected. While OPTIONS did work, PROPFIND, PROPPATCH, etc. were not. My tests with curl always returned HTTP 405.

curl -X PROPFIND https://example.org/dav
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>405 Method Not Allowed</title>
</head><body>
<h1>Method Not Allowed</h1>
<p>The requested method PROPFIND is not allowed for the URL /.</p>
</body></html>

As it turns out, there’s a bug report from 2013 in the Apache bug tracker for a similar issue. For whatever reason an enabled DirectoryIndex directive blocks the WebDAV methods. This bug has been fixed in the httpd 2.5 trunk, but not in http 2.4 (and probably never will). Therefore disabling DirectoryIndex is the mandatory workaround:

<Location "/dav">
  DirectoryIndex disabled
  AllowMethods HEAD GET POST CONNECT PUT DELETE OPTIONS PROPFIND PROPPATCH MKCOL COPY MOVE LOCK UNLOCK TRACE
  Require all granted
</Location>

As this issue didn’t arise until production hours and a quick fix was needed, I’ve yet to confirm if mod_dav and mod_dav_fs are even needed. I suspect they are not.

Using the Spotify Web player on Android

• Android and Web • Comments

A friend of mine asked me if it was possible to use the Spotify Web Player on his Android smartphone.

Spotify Android App

If you are like me and don’t use Spotify on mobile very often, you might not know that the free version of the Spotify app is heavily castrated. I’m not using it a lot, but if I understood correctly, you can’t properly play a playlist or one song, you get force fed “matching” songs. Also you can’t constantly skip songs. To push their Premium Account to you, Spotify additionally prevents mobile browsers from using their less limited Web player.

While I understand that Spotify wants to earn money, I heavily dislike the artificial limitations to push people to a paying account. If you can’t sell your Premium Account with a feature list, you should probably work on the list instead of artificially limiting the features on different devices. Especially the differentiation between PC and mobile browsers triggered me. Therefore I welcomed the challenge of convincing Spotifys Web player to work on Android.

Ansible: Extend variable values in Jinja 2 templates

• Ansible • Comments

In a Jinja 2 Template for one of my Ansible playbooks I wanted to construct a string containing several potentially filled variables to eventually append it to a command execution.

I tried this:

{% set additional_opts = '' %}
{% for opt_arg, opt_name in [
  (item.exclusive_labels|default(''), '--exclusive_labels'),
  (item.ignore_labels|default(''), '--ignore_labels'),
  (item.exclusive_prefixes|default(''), '--exclusive_prefixes'),
  (item.ignore_prefixes|default(''), '--ignore_prefixes')
] %}
{% if opt_arg %}
{% set additional_opts %}{{ additional_opts }} {{ opt_name }}="{{ opt_arg }}"
{%- endset %}
{% endif %}
{% endfor %}

runme.py {{ additional_opts }}

But that didn’t work. The additional_opts variable never contained any value outside of the loop. After some research, I found out, that this is working as intended. This is even mentioned in Jinjas (excellent) Template Designer Documentation:

Please keep in mind that it is not possible to set variables inside a block and have them show up outside of it. This also applies to loops.

And there’s even a proposal how to achieve this use case properly:

As of version 2.10 more complex use cases can be handled using namespace objects which allow propagating of changes across scopes

After reading that, correcting my template didn’t take long. It ended up looking like this:

{% set ns=namespace(additional_opts='') %}
{% for opt_arg, opt_name in [
  (item.exclusive_labels|default(''), '--exclusive_labels'),
  (item.ignore_labels|default(''), '--ignore_labels'),
  (item.exclusive_prefixes|default(''), '--exclusive_prefixes'),
  (item.ignore_prefixes|default(''), '--ignore_prefixes')
] %}
{% if opt_arg %}
{% set ns.additional_opts %}{{ ns.additional_opts }} {{ opt_name }}="{{ opt_arg }}"
{%- endset %}
{% endif %}
{% endfor %}

runme.py {{ ns.additional_opts }}

While this way is a bit less intuitive, it works like a charm.

How I miraculously fixed my Windows 10 startup DNS problems

• Windows • Comments

I once again had a great experience with Windows 10. For some reason my DNS resolution stopped working for roughly two minutes after every startup. Of course there was neither an update around that time, nor were there any unusual messages in the Event Viewer. Therefore I had no idea where to look. I tried a couple of things, manually setting different DNS servers, configuring a static IP, and of course doing the classic ipconfig /flushdns and ipconfig /registerdns. To no avail. I still did not have DNS directly after startup. The DNS issues even occured in the first two minutes of Safe Boot Mode.
So, how did I fix it?

Advertisement