Friday, August 31, 2018

Pretty print JSON from command line

echo '{ "element0" : "hi", "element1" : "there" }' | python -m json.tool
prints:
{
    "element0": "hi",
    "element1": "there"
}
You can also cat a JSON file and pipe to the same command

Ansible become_user for a block of commands

use a block to apply a become_user to a block of commands
- block:
    - name: checkout repo
      git:
        repo: https://github.com/some/repo.git
        version: master
        dest: "{{ dst }}"
    - name: change perms
      file:
      dest: "{{ dst }}"
      state: directory
      mode: 0755
      owner: some_user
  become: yes
  become_user: some user