Free cookie consent management tool by TermsFeed Policy Generator



Understanding multi line strings in YAML and Ansible (Part II - Ansible)

YAML, Ansible Comments

In Part I of this series we examined the two block styles of YAML, literal and folded, as well as the three block chomping methods, strip, clip and keep. In this post we want to investigate how these styles and methods interact with different Ansible use cases.

Multi line strings in Modules

The classic usage of a multi line string in Ansible is in the command or shell module. This example is directly taken from the Ansible docs:

# You can use shell to run other executables to perform actions inline
- name: Run expect to wait for a successful PXE boot via out-of-band CIMC
  shell: |
    set timeout 300
    spawn ssh admin@{{ cimc_host }}

    expect "password:"
    send "{{ cimc_password }}\n"

    expect "\n{{ cimc_name }}"
    send "connect host\n"

    expect "pxeboot.n12"
    send "\n"

    exit 0
    executable: /usr/bin/expect
  delegate_to: localhost

A literal style block with clip chomping is used to send several commands. Folded style would not make any sense here, except if you wanted to either pipe the commands or chain them with && or ||.

Understanding multi line strings in YAML and Ansible (Part I - YAML)

YAML, Ansible Comments

I had a strange problem with variables spanning multiple lines in Ansible. During the process of debugging it, I learned a bit about multi line strings which are called “blocks” in the official YAML specification. In this blog post we’ll examine the different YAML block styles and block chomping methods. In Part II we will then learn the use cases and quirks of each style when used in Ansible.

We’ll run this base playbook for each style via ansible-playbook -v playbook.yml and will only replace the variable with the corresponding style.

- hosts: localhost
  connection: local
    my_pattern: |
      With his own sword,
      Which he did wave against my throat, I have ta’en
      His head from him.
    - debug:
        var: my_pattern


There are two basic styles of blocks in YAML, literal and folded. Both have different advantages and disadvantages, especially when used in Ansible.


According to the YAML specification literal is “is the simplest, most restricted, and most readable scalar style”. It’s denoted by the pipe, |:

my_pattern: |
  With his own sword,
  Which he did wave against my throat, I have ta’en
  His head from him.


ok: [localhost] => {                              
    "my_pattern": "With his own sword,\nWhich he did wave against my throat, I have ta’en\nHis head from him.\n"                                                  

Horde: Deleting Duplicates from MySQL Database

MySQL, Horde Comments

I recently encountered a problem with my Horde installation. Due to an app misconfiguration, my wife created hundreds of calendar entries for the same event [Edit 2018-04-17: It turned out, she also created thousand of duplicate tasks. Yay!]. It is tedious to delete every event by hand, so I wanted to drop the entries from the database. As this is something other people might profit from, I’m documenting it. Of course part of this procedure can be done with other MySQL databases as well.

Get listing of double entries

I wanted to see all duplicate entries first, to make safe I’m not deleting important stuff. This can be done with a SELECT COUNT command:

   SELECT event_title,event_start,COUNT(*) c FROM kronolith_events
     GROUP BY event_title,event_start HAVING c > 1 ORDER BY c ASC;

This is the result:

MySQL count duplicates table

Ouch! That are a lot of duplicate entries. Let’s delete them!

Solving multi monitor mouse problems in fullscreen applications

Windows, Gaming Comments

I’ve been an avid gamer for ages. I’ve also been using two monitors for ages. And I’ve had my fair share of problems with this combination already.

Some time ago I broke my arm. Therefore my gaming life was handicapped severely and I was limited to mouse only games. No big deal, there are still a lot of games waiting to be played in my Steam and GoG libraries. As I’m German, I of course decided to start with some economy simulations. Anno 1404 and Tropico 4 were my first choice of games.

Sadly both games had some kind of problem with my second monitor. Tropico 4 didn’t capture my cursor, leading to issues with scrolling via cursor movement to the right edge of the screen. As the cursor moved to the second screen then, a click would lead to a minimization of the game, which was pretty annoying after some time.

Tropico 4

Linux: Empty swap space

Linux Comments

This is the translation of a post I wrote four years ago. I needed an english version of it for a friend of mine.

If you want to empty your swap space on Linux for whatever reason, so you can simply use these commands:

swapoff -a && swapon -a

This deactivates all swap storage first, leading to a drainage of the currently contained data. Afterwards the swap space is activated again.

If the swap space is heavily utilized, this can take a couple of minutes, so don’t worry if nothing happens. To check the progress, you can use this command in another window:

free -s 3 |grep Swap

This command shows the current used swap and refreshes every three seconds. Of course, the used swap space should continously decrease and finally be zero.

If you only want to empty one swap partition, you can substitute the -a switch in the first command with the paritition you want to drain, e.g. /dev/sda2.