You need to quote and use {{}} correctly.
- hosts: localhost tags: s16 gather_facts: no tasks: - shell: echo 'variable_1;variable_2;variable_3' register: result - local_action: debug msg="values ("{{ item[0] }}","{{ item[1] }}","{{ item[3] }}");'" with_items: [ "{{result.stdout.split(';')[0]}}", "{{result.stdout.split(';')[1]}}", "{{result.stdout.split(';')[2]}}" ]
It will output something like:
TASK: [debug msg="values ("{{ item[0] }}","{{ item[1] }}","{{ item[3] }}");'"] *** ok: [localhost -> 127.0.0.1] => (item=variable_1) => { "item": "variable_1", "msg": "values (\"v\",\"a\",\"i\");'" } ok: [localhost -> 127.0.0.1] => (item=variable_2) => { "item": "variable_2", "msg": "values (\"v\",\"a\",\"i\");'" } ok: [localhost -> 127.0.0.1] => (item=variable_3) => { "item": "variable_3", "msg": "values (\"v\",\"a\",\"i\");'" }
As you can see with item[0], .., item[2] , you index the string "variable_1" instead of the array ["variable_1","variable_2","variable_3"]
The simplest (and much stronger) way to do this:
- hosts: localhost tags: s17 gather_facts: no tasks: - shell: echo 'variable_1;variable_2;variable_3' register: result - debug: msg="insert into tt values ("{{result.stdout|replace(';', '","')}}");'"
source share