Ansible snippets - manipulating JSON data

Ansible snippets - manipulating JSON data

Recently while working with Ansible, I needed a clean way to extract JSON values and manipulate that data in a very Ansible-esque way. In this particular case, reading JSON files/variables and treating them as if they were Ansible variables, converting that list into a comma-seperated string. Turns out Ansible can handle that pretty easily, using Jinja filters. scenario and demo The following steps will use the example playbook json_example.yml. Let’s say you need to extract JSON values from a file (or variable), for use somewhere else.
Ansible snippets - splitting variables

Ansible snippets - splitting variables

A useful Ansible snippet - splitting a variable value in Ansible. the stuffs - splitting a variable using .split Let’s paint a picture. Say there’s an application that needs upgraded. It’s distributed via a tarball. There is a service setup using a symlink - software -> software-1.2.3. The workflow would be something like… Untar a file. Change the symlink to point to the new folder (software -> software-2.0.0). There’s already a variable for the tar file name.