6

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: 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:

"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 from yaml or json format without luck , this last add some return carriage with

| to_yaml 
| to_json
| to_nice_yaml
| to_nice_json

Any advice?

1 Answer 1

5

The results that you got returned is a list of lists. So a list of rows, with a list of the cells within that row.

Try something like this.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .