Convering YAML to JSON : For OPA to feed as an input file.

 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 Ansible Link : https://docs.ansible.com/ansible/latest/user_guide/playbooks_filters.html#formatting-data-yaml-and-json

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

 

The Code that is converted :

 

---
- hosts: localhost
 
  tasks:
  - name: Register JSON output as a variable
    ansible.builtin.shell: cat /etc/ansible/playbook/yaamlfile.yml
    register: result

  - name: Set a variable
    ansible.builtin.set_fact:
      myvar: "{{ result.stdout | from_yaml }}"

  - copy:
        content: "{{ myvar }}"
        dest:    /etc/ansible/playbook/convertedtojson.json
[root@cmptest01-cc playbook]# cat yaamlfile.yml
---

- hosts: all
  gather_facts: false
  tasks:

  - name: Create the async directory to prevent race conditions
    file:
      path: ~/.ansible_async
      state: directory
    run_once: true

  - name: Poll a sleep
    shell: "sleep 10"
    async: 30
    poll: 5

  - debug:
      msg: "I'm a debug message."

  - name: Fire and forget a slow command
    shell: |
      sleep 15
      touch /tmp/test_file
    async: 30
    poll: 0
    register: fired

  - debug:
      msg: "I'm another debug message."

  - name: Examine slow command
    async_status: jid={{ fired.ansible_job_id }}
    register: slow_command
    until: slow_command.finished
    retries: 20

  - name: Fire and forget a slow reversal
    shell: |
      sleep 10
      rm -f /tmp/test_file
    async: 30
    poll: 0
    register: fired

  - debug:
      msg: "I'm yet another debug message."

  - name: Examine slow reversal
    async_status: jid={{ fired.ansible_job_id }}
    register: slow_command
    until: slow_command.finished
    retries: 20

 

The File after converting to JSON



Comments

Popular posts from this blog

Jenkins file | declarative pipeline scripting

Jenkins : Webhooks

JENKINS -- My Work -Project - DNS