Ansible - Load vault password from keepass

For local playbooks using vaults, I tend to store the vault password in keepassxc. You can use the following method to retrieve the vault password directly from ansible In ~/bin/get_keepass_password.py: add the script to get the password from keepassxc: from pathlib import Path class IncorrectPassword(Exception): pass def get_keepass_password(keepass_database_path: Path, keepass_entry_name: str): import os # --- # KEEPASS PASSWORD try: keepass_password = os.environ['KEEPASS_PASSWORD'] password_provided_by_environment = True except KeyError: keepass_password = input(f'Keepass password for file {keepass_database_path....

May 17, 2023 · 3 min · Jonas DOREL

Configure OpenWrt With Ansible

/!\ Raw excerpt from my internal comparison database I chose to use NN708/ansible-openwrt, with gekmihesg/ansible-openwrt. franciscofregona/OpenWRTConfig https://github.com/franciscofregona/OpenWRTConfig How it works : create local config files through templates. Then through raw commands : upload them and reload openwrt Why I don’t like: use of local config files Maybe it’s faster this way than through uci commands ? archf/ansible-openwrt https://github.com/archf/ansible-openwrt How it works : Custom uci module (-) Only support batch, set and add_list (+) Input is direct command Role configuring DHCP through the custom uci module can configure extroot can install useful packages can install ansible dependencies can configure dhcp Pros :...

November 10, 2021 · 1 min · Jonas DOREL

Javascript Difficulties Learning Promises

I’ve had a hard time trying to learn promises in Javascript. Here is why. What do I mean by learn When I learn something, I learn to understand, not simply to use. In this case, it means understanding the syntax, but also the flow of data and function calls. Why was it difficult Compared to traditional programming, I found that Promises where difficult because: you manipulate callbacks (resolve() and reject()) through an object (using ....

October 19, 2021 · 2 min · Jonas DOREL

Bash - Parse Yaml Front Matter

I just spent the evening trying to parse a YAML Front Matter from bash. It requires to have yq installed. Here is the code: function main() { filepath=$1 project_name=$(get_project_name_from_path ${filepath}) echo -e "${project_name}" } function get_project_name_from_file() { file_path=$1 yaml_front_matter=$(get_yaml_front_matter $file_path) if [[ $? == 0 ]]; then # Case YAML Front Matter exists fdebug "yaml_front_matter:\n\n ${yaml_front_matter}" yaml_project_name=$( get_project_name_from_yaml "${yaml_front_matter}" ) if [[ $? == 0 ]]; then # Case YAML Front Matter defines a project name fdebug "YAML Front Matter defines a project name" project_name=${yaml_project_name} return_value=0 else # Case YAML Front Matter DOES NOT defines a project name fdebug "YAML Front Matter DOES NOT defines a project name" project_name=$( get_end_of_path ${project_path} ) # Return folder name as project name return_value=2 fi fdebug "Returned \$yaml_project_name : $yaml_project_name" else # Case YAML Front Matter DOES NOT exists fdebug "YAML Front Matter DOES NOT exists" project_name=$( get_end_of_path ${project_path} ) # Return folder name as project name return_value=1 fi echo ${project_name} return ${return_value} } function get_yaml_front_matter() { file_path=$1 file_start=$( \head -n 1 $file_path ) if [[ $file_start == "---" ]]; then # Case there might be a YAML Front Matter while IFS='' read -r line; do # IFS='' to keep whitespaces # Check end of YAML Front Matter ( echo $line | grep -- '---' &>/dev/null ) && yaml_front_matter_validated="true" && break yaml_front_matter="${yaml_front_matter}${line}\n" done < <( \tail -n +2 $file_path ) # Skip first line containing --- if [[ $yaml_front_matter_validated == "true" ]]; then # Case there is a YAML Front Matter echo "${yaml_front_matter}" else # Case there is NO VALID a YAML Front Matter return 1 fi else # Case there is NO YAML Front Matter return 1 fi } function get_project_name_from_yaml() { yaml_front_matter=${1} yaml_project_name=$(echo -e $yaml_front_matter | yq -r ....

October 7, 2021 · 2 min · Jonas DOREL

Vim - Highlight Cells in Markdown Tables

As I was currently editing tables in markdown, I wanted to color table cells based on content : green for yes, red for no and yellow for ?. So I made a PR about this for the plugin vim-table-mode. But it’s possible to implement it outside of the plugin by adding the following in your vimrc : syntax match Table '|.\+|' contains=yesCell,noCell,maybeCell syntax match yesCell '|\@<= *yes[^|]*' contained syntax match noCell '|\@<= *no[^|]*' contained syntax match maybeCell '|\@<= *?...

October 5, 2021 · 1 min · Jonas DOREL

How I push updates to my blog

When setting up my blog, I decided that the only action I wanted to do to update the live version was to do git push. To implement this, I skipped setting up a webhook server because I didn’t want to install the webhook server directly on the host : this would have used a port and required manual configuration of my reverse proxy (I use traefik). Instead, I implemented it with :...

September 22, 2021 · 2 min · Jonas DOREL

SSH - Fire and forget command

Run remote scripts asynchronously

September 22, 2021 · 1 min · Jonas DOREL

Ansible - Advanced setup

With the introduction of collections, some content can be migrated in your own collection. This is especially useful when important content from multiple sources. Also, as your ansible repo starts growing, you might not want to mix your inventories with your playbooks in the root folder. Note: this post was initially a documentation PR on github Advanced directory layout With this setup, the root of your repo is quiet simple:...

September 19, 2021 · 2 min · Jonas DOREL

Ansible - Organize your playbooks

Once you start having a lot of playbooks and some reusable tasks, you might want to organize them:: playbooks/ tools/ # Used to manipulate some hosts. Ex: ping, show_groups actions/ # For actions. Ex: update, sync, restart, ... provisionning/ # Run once provisionning playbooks. Ex: configure ssh, install python, ... hosts/ # For playbooks manipulating a single host service/ # Content related to a service manipulation. Ex: deploy monitoring on all hosts ....

September 19, 2021 · 1 min · Jonas DOREL

Ansible - Use absolute path references

Rearrange your tasks and playbooks easily with absolute paths

September 19, 2021 · 1 min · Jonas DOREL