Category: python

Watch for changed files in SyncThing

Author: ads

For syncing files between my devices I'm using SyncThing. This tool is reliable, available on Linux, Android, Mac and iOS. And it encrypts the communication. But sometimes I want to know when files in certain directories have changed - as example in my Obsidian vault. This allows me to post-process the files. Read more

Use namespace as global variable in Ansible Jinja templates

ansiblepython
Author: ads

A simple task, or so I thought: in a Jinja template keep track of the number of items in a loop. And then use that count afterwards. Disclaimer: the number of items is not equal the number of times the loop runs, so I can’t use the loop variables. Turns out that Jinja has other opinions, and variables inside a loop are all local. When a variable is changed inside the loop, the scope of the variable stays local, and once the loop ends the original value of the variable is restored. That’s even true for variables which are created outside the loop. Read more

Certificate expiration date in Ansible

Author: ads

In one of my Ansible Playbooks I’m updating Let’s Encrypt certificates. Because the Playbook is rather long, I want to make sure that Ansible is not spending cycles on a certificate which is not about to expire. Hence I wrote a small filter plugin, which receives the certificate path and the number of days the certificate must be still valid. This plugin is used to filter out any “good” certificate which does not need to be updated. Read more