DevOps
-
Conditional Privilege Escalation in Ansible Playbooks
Fixing become_user Failures When Already Logged in as this user, e.g. ansible_user Problem Description This error occurs when an Ansible task is configured with become: true and a become_user that matches the current login user (the remote_user). Even if you are already logged in as the target user, Ansible attempts to wrap the module execution in a privilege escalation command (typically sudo -u target_user). If the target user is not explicitly permitted in the /etc/sudoers file to “sudo to themselves,” the OS rejects the command, requesting a password that Ansible cannot provide. This is the classic “I am who I say I am, but I can’t prove it to myself”…
-
Ansible Formatting Best Practices
Readable and consistent Ansible code makes reviews easier, reduces errors, and helps linters such as yamllint and ansible-lint work reliably. The following conventions have proven useful in larger playbooks and roles. 1. Use folded scalars for long Jinja expressions Multiline Jinja expressions inside a quoted YAML scalar can confuse YAML parsers and linters. Avoid this: The expression is hard to read and may break YAML formatting checks. Use folded scalars instead: Advantages: 2. General YAML formatting Maintain a consistent layout across all playbooks. Recommended conventions: Example: This improves readability and keeps file structure consistent. 3. Always use Fully Qualified Collection Names (FQCN) Using FQCN avoids ambiguity and improves compatibility with…
-
Reliably Fetching Git Tags in GitLab Pipelines (and the GIT_DEPTH Pitfall)
Finding the right version string in a CI/CD pipeline can be surprisingly tricky. If you’ve been searching for a way to grab the “latest” tag in your GitLab runner, you’ve likely stumbled across this specific combination of Git commands. At least I did… Here is a breakdown of what that command does, why it works, and the “gotchas” you need to look out for. The Command Breakdown The command is actually two Git commands nested together: 1. The Inner Command: git rev-list The part inside the parenthesis, git rev-list --tags --max-count=1, acts as a locator. 2. The Outer Command: git describe Once the inner command finds the “hash” (the unique…
-
Get systemd services in ansible plays
Hi, this is a tip to get details about linux (e.g. systemd) services in an ansible play. Just use the ansible service_facts module. You can use it without passing any argument. You can access services by using ansible_facts.services. As this is an dictionary, a single service is addressable by using ansible_facts.services[{{ service-name }}]. A few more examples:
-
use ansible module copy instead of template for small files
In order to adapt files and their content on target servers I am used to using ansible copy module. However, if you only have a small file with just one or a few lines, you can do so without creating a jinja2 template. Here is the little cheat: Just use ansible’s copy module. That’s it. This creates a file with variable content, without need to create a template.
-
merge particular files in another branch
Every now and then I am faced with the question of how I can transfer individual files from a feature branch. git cherry-pick is intended for taking over the contents of a commit. But if I only want to take over individual files, this tool is probably not the solution. In order not to make it too exciting, here is the simple answer: I want to explain it using a specific example. In the feature branch I have the files iWwantThat.yml and alsoNeeded2.py. To transfer these two files and only these to the main branch, I switch to the main branch and run the git checkout:
-
HTTPS Setup für eine Flask Anwendung – Teil 2
Im ersten Teil habe ich die Einrichtung des Ubuntu Servers für meine kleine Webanwendung für den isländisch Kurs beschrieben. Im zweiten Teil möchte ich kurz auf die HTTPS Einrichtung eingehen. Die DigitalOcean Anleitung für Ubuntu 18.04 funktioniert nicht unter Ubunt 20.x. Bitte darauf achren, die Anleitung für das eingesetzte Ubuntu Release (hier 20.04) zu verwenden, falls vorhanden. Das verwendete Repository ppa:certbot/certbot ist im Status DEPRECATED. Daher wird der Certbot für die Let’s Encrypt Zertifikate Ein Apache Virtual Host ist Vorausssetzung für die nächsten Schritte. Die Einrichtung habe ich in Teil 1 beschrieben. HTTPS Zugriff durch die Firewall Der aktuelle Status der Firewall wird mit ufw abgefragt: Um eingehende HTTPS Anfragen…
-
Web Anwendung basierend auf Python Flask – Teil 3
Der dritte Teil beschreibt die Webanwendung meines Isländisch Trainers. Ich habe den Quellcode auf Gihub veröffentlicht. Der hauptteil der Anwendung besteht aus 2 Webseiten. Die erste eröffnet eine Session und zeigt ein Wort aus einer Liste an. Die Wörterliste ist im yaml Format erstellt. Die Struktur entspricht einen Dictionary: Ein Zufallsgenerator suche ein Wort aus dieser Liste und zeigt die deutsche Übersetzung an. Der Lernwillige kann sich die Deklinaktion der Fälle in Singular und Plural, mit und ohne Artikel ansehen. Ob seine Kenntnisse richtig sind, zeigt Seite 2 nach Absenden des Formulars in Form eines simplen Buttons an. Die Lösungsseite zeigt die korrekten Deklinationen an und eine Link auf die…
-
Digitalocean Setup für eine Flask Anwendung – Teil 1
Dieser Blog wird Teil einer Serie für eine Web Anwendung in Python auf einer Cloud Instanz. Ich habe mich für DigialOcean entschieden. Linode, Azure, GCP, … wären alle genau so gut für diesen Zweck. Die Anwendung wird aus einer Liste von Vokabeln ein Wort in Deutsch heraussuchen und anzeigen. Auf einer zweiten Seite wird die Übersetzung des Worts und die Deklination angezeigt. Im ersten Teil werde ich die Einrichtung des Servers beschreiben. Teil 2 wird die HTTPS Konfiguration behandeln. Teil 3 schliesslich beschreibt die Python Flask Anwendung und deren Deployment mit Github Actions. Teil 4 wird die Einrichtung der Subdomain is.hslomka.de und die Umleitung auf meinen Server beinhalten. Das Ergebnis…
-
git Settings
Here are a few Git settings that have proven effective for me in working efficiently: General Settings Display Settings Shortcuts / Alias PowerShell alias Beautification