We run our database migrations using Ansible with something along these lines:
name: Run database migrations
command: env/bin/python migrate.py -q chdir=$project_dir/releases/$release_date
register: result
changed_when: result.stdout
migrate.py prints the list of applied migrations to stdout.
We try to print this list because our developers want some feedback about which migrations were applied:
debug: msg=“{{result.stdout}}”
when: result.stdout
But all new lines are escaped to \n, which makes the output quite difficult to read.
Is there any solution to this?
In your own projects, how do you execute your database migrations? Do you try to get some feedback as what we try to achieve here? Or do you use another approach?
Yes, but if result.stdout contains new lines, they will show up escaped as
\n instead of "real" new lines, which makes it difficult to read. Any
advice on this?
Yes, I know It was the purpose of the small pull request James accepted
yesterday to update the documentation about Jinja2 expressions in playbooks.
This is why I was a quite surprised by Jesse suggestion. I just gave it a
try to make sure I was not missing something, and hopefully it doesn't work
Any idea on how to solve the problem I stated at the start of this
discussion: We have a playbook that executes database schema migrations,
and I want to print the list of applied migrations on the console?... The
list of applied migrations is printed on stdout by the migration command.
If you are really looking for specialized output, why bother using debug module? Add the following task and create some simple script to parse. The inventory_hostname will give the remote host corresponding to the stdout (you don’t want to mix those up).
Did anything ever come of this? I would really like to be able to print friendly “Provisioning succeeded! Here’s what to do next…” messages at the end of some of my playbooks.