# Ansible how to get output as variable without brackets and u

**URL:** <https://forum.ansible.com/t/ansible-how-to-get-output-as-variable-without-brackets-and-u/30047>\
**Category:** Ansible Project\
**Created:** [April 3, 2019, 9:35am UTC](https://forum.ansible.com/t/ansible-how-to-get-output-as-variable-without-brackets-and-u/30047 "2019-04-03T09:35:18Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wanexa77](https://avatars.discourse-cdn.com/v4/letter/w/eb8c5e/32.png) [@wanexa77](https://forum.ansible.com/u/wanexa77)\
**Post date:** [April 3, 2019, 9:35am UTC](https://forum.ansible.com/t/ansible-how-to-get-output-as-variable-without-brackets-and-u/30047/1 "2019-04-03T09:35:18Z")

</div>

I have the result of a query from ansible and I tried to use the result as a variable

My playbook is like this

```auto
- name: Query
  oracle_sql:
    username: "{{ user }}"
    password: "{{ password }}"
    service_name: "{{ service_name }}"
    sql: "select smth from table where smth like 'OK_%'"
  register: smth"

```

the result is formatted as below

```auto
"msg": [
    [
        "SMTH"
    ]
]

```

no stdout, no stderr

after this I want to use my variable

```auto
- name: echo
  shell: echo {{ smth.msg[0] }} > /tmp/test

```

and the outuput is like this:

[uSMTH]

How to remove brackets and ‘u’ , I know it s a list but I can t get rid of this

I tried to convert in yaml or json format no luck , this last add some retrun carriage with

```auto
> to_yaml 
> to_json
>to_nice_yaml
> to_nice_json

```

Any advice ?

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 3, 2019, 9:41am UTC](https://forum.ansible.com/t/ansible-how-to-get-output-as-variable-without-brackets-and-u/30047/2 "2019-04-03T09:41:32Z")

</div>

> I have the result of a query from ansible and I tried to use the result as a variable
> 
> My playbook is like this
> 
> \>-name:Queryoracle\_sql:username:"{{ user }}"password:"{{ password }}"service\_name:"{{ service\_name }}"sql:"select smth  
> from table where smth like 'OK\_%'"register:smth"|
> 
> the result is formatted as below
> 
> \>"msg":[["SMTH"]]|
> 
> no stdout, no stderr
> 
> after this I want to use my variable
> 
> \>-name:echo shell:echo {{smth.msg[0]}}\>/tmp/test|
> 
> and the outuput is like this:
> 
> [uSMTH]
> 
> How to remove brackets and 'u' , I know it s a list but I can t get rid of this
> 
> I tried to convert in yaml or json format no luck , this last add some retrun carriage with
> 
> \>\>to\_yaml |to\_json |to\_nice\_yaml |to\_nice\_json|
> 
> Any advice ?

Using smth[0][0] should do the trick (first field in the first sql record).

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![wanexa77](https://avatars.discourse-cdn.com/v4/letter/w/eb8c5e/32.png) [@wanexa77](https://forum.ansible.com/u/wanexa77)\
**Post date:** [April 3, 2019, 9:47am UTC](https://forum.ansible.com/t/ansible-how-to-get-output-as-variable-without-brackets-and-u/30047/3 "2019-04-03T09:47:28Z")

</div>

it works thanks a lot can you explain to me please about the [0][0]  
thanks in advance

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [April 3, 2019, 9:53am UTC](https://forum.ansible.com/t/ansible-how-to-get-output-as-variable-without-brackets-and-u/30047/4 "2019-04-03T09:53:12Z")

</div>

> it works thanks a lot can you explain to me please about the [0][0]  
> thanks in advance

OK, say you have the following query:

select first\_name, last\_name from test\_table

With two results:

Test | Tester  
Foo | Bar

In your smth variable it will look like that:

[["Test", "Tester"]["Foo", "Bar"]]

smth[0][0] = Test  
smth[0][1] = Tester  
smth[1][0] = Foo  
smth[1][1] = Bar

The first index is for the SQL record, the second index for the fields you put into the select statement.

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke
