-
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…
-
💡 PowerShell Tip – Find a Windows Firewall rule by port
If you know the port but not the rule name, you can resolve the rule via the port filter: Useful for troubleshooting when an application opens a port but the corresponding firewall rule name is unknown.
-
Adding Colors to Text in Markdown
Introduction Markdown is a lightweight markup language that keeps formatting simple and readable. However, one limitation many users encounter is the lack of native support for colored text. While pure Markdown doesn’t offer this feature, there’s an elegant solution: using LaTeX color commands through inline math notation. In this guide, we’ll explore how to add vibrant colors to your text while maintaining the simplicity and portability of Markdown syntax. The Solution: LaTeX with Markdown The most straightforward way to add colors to text in Markdown is by combining LaTeX’s \textcolor command with inline math delimiters. This works in most Markdown renderers that support LaTeX math notation. Basic Syntax This renders…
-
How to Extract Specific Lines from a File: sed, awk, head/tail, grep, and with powershell
In the command line, it’s often necessary to extract only specific lines from a text file – whether it’s a single line or a range of lines. Fortunately, Bash offers several powerful tools for this. In this blog post, I’ll show you the most common methods using sed, awk, head/tail, and grep. Additionally, I will demonstrate an option when using PowerShell. Extracting Lines with sed sed (Stream EDitor) is a classic for text manipulation in the shell and is excellent for selectively outputting line ranges.Output a Single Line (e.g., Line 102)To output a specific line, such as line 102, you use the p command (print) in combination with the -n…
-
💡Powershell Tip – Search directories and subdirectories for files with specific content
I’d like to share a small PowerShell script that scans all subdirectories for specific files (for example, *.yaml and *.yml) and searches them for a specific string (e.g., “ansible.builtin.template”). The result is returned with the location (name and path of the file, and line number of the search string in the file). What it does: Sometimes I want to save my results to a file and explore them further. To save the results to a CSV file, adapt the script as follows:
-
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:
-
💡Powershell Tip – Find all files larger than X bytes in a directory structure
In order to output all files larger than a certain size on Windows systems, you do not have to use the explorer search. A Powershell script does this very efficiently. The result is shown in a gridview window: If the last part | Out-GridView is omitted, the output in the console is required.