Thursday, March 15, 2018

Ansible replace \t or '\t' in Sqlplus Output

Symptom:

     When we run sql via sqlplus to get some output from database via ansible playbook, we get some special characters. ie \t ,example below. The format is not quite friendly.

TASK [display details of sql output] *****************************************************************************************************************************************
ok: [acmsdbv3053.us.oracle.com] => {
    "msg": [
        "",
        "NAME\t\t\t\t\t INST_ID VALUE",
        "---------------------------------------- ------- --------------------------------------------------",
        "compatible\t\t\t\t       1 11.2.0.2.0",
        "compatible\t\t\t\t       2 11.2.0.2.0",
        "noncdb_compatible\t\t\t       1 FALSE",
        "noncdb_compatible\t\t\t       2 FALSE"
    ]
}

Solution:

We use replace function to replace \t (the string)  with ' ' or we need to replace real tab with ' '

To replace replace \t (the string)  with ' ' in the output
 - name: display details of sql output
     debug: msg="{{ sqloutput.stdout_lines|replace('\\t',' ') }}"

To replace real tab with ' ' in the output
- name: display details of sql output
     debug: msg="{{ sqloutput.stdout_lines|replace('\t',' ') }}"

No comments: