Closed esfreire closed 7 years ago
Any luck with this Esteban, i'm using ansible 2.0.0.2 , but couldn't find a solution.
I can confirm the same issue in 2.2.0.0
Alright I got around this by creating an extra step using set_fact. Rather than running my commands against the std.out, I run my commands against the new variable which also utilizes regex_replace
name: run script script: /etc/ansible/test.sh register: results
name: create variable out of stdout results. then remove the extra characters set_fact: somevariable: "{{ results.stdout | regex_replace('(\r\n)','') }}"
name: echo the variable without the extraneous characters shell: echo "{{ somevariable }}"
@esfreire can you confirm if the workaround from @oniled helps?
needs_info
Hi @santureddy , @jctanner and @oniled ,
I am sorry for my delay in answering you.
@oniled , thanks for checking it and for the workaround :)
@santureddy , @jctanner , at the end, I decided to change it and do everything through bash on the shell line since I did not know how to solve this. I am sorry but I cannot test this right now since I am not working on this project/company for almost a year now.
Regards, Esteban
I don't know the exact output of the onevm commands, but this pattern is covered in the current docs:
I ran a quick testcase to validate:
- hosts: el6host
connection: local
gather_facts: False
vars:
alist:
- one
- two
- three
tasks:
- shell: echo "{{ item }}"
with_items: "{{ alist }}"
Results ...
TASK [command] ***********************************************************************************************************************************************************************************************************************************************
changed: [el6host] => (item=one) => {"changed": true, "cmd": "echo \"one\"", "delta": "0:00:00.002721", "end": "2017-02-10 11:15:10.206580", "item": "one", "rc": 0, "start": "2017-02-10 11:15:10.203859", "stderr": "", "stderr_lines": [], "stdout": "one", "stdout_lines": ["one"]}
changed: [el6host] => (item=two) => {"changed": true, "cmd": "echo \"two\"", "delta": "0:00:00.002939", "end": "2017-02-10 11:15:10.362759", "item": "two", "rc": 0, "start": "2017-02-10 11:15:10.359820", "stderr": "", "stderr_lines": [], "stdout": "two", "stdout_lines": ["two"]}
changed: [el6host] => (item=three) => {"changed": true, "cmd": "echo \"three\"", "delta": "0:00:00.002696", "end": "2017-02-10 11:15:10.521178", "item": "three", "rc": 0, "start": "2017-02-10 11:15:10.518482", "stderr": "", "stderr_lines": [], "stdout": "three", "stdout_lines": ["three"]}
ISSUE TYPE
Bug Report
COMPONENT NAME
N/A
ANSIBLE VERSION
N/A
SUMMARY
Hi all,
I don't know if it is a bug but I don't know how to solve it. I also have asked about it on the ansible group, https://groups.google.com/forum/#!topic/ansible-project/x2MCN2Qc4GU
I have the two following actions:
This is an output example from the the first action:
The problem is that the second action is not working due to the command expects to received just one argument per time, I mean, I need to execute:
And right now it is not working because it is executing: onevm delete 674 675 , which it does not work because the command does not admit to pass more than one argument.
I followed ansible documentation, https://www.google.com/url?q=https%3A%2F%2Fdocs.ansible.com%2Fplaybooks_loops.html%23iterating-over-the-results-of-a-program-execution&sa=D&sntz=1&usg=AFQjCNHSNuqa9qHFurH5UGrY868zIcz8vA
So I tried
But I got the following issue:
Then, I have tried the following things:
But I got the following issue in all the previous cases:
So, it seems it is splitting the lines according to stdout_lines': [u'685', u'686'] and "stdout": "685\n686", "stdout_lines": ["685", "686"] . The problem is that it is taking the [" characteres as "[u" and I don't know how to remove that.
Any idea is welcome and my apoligize if this is not a bug :)
Thanks in advance, Esteban