"I am trying to use ansible as a test tool. at the end of each
sucess/faiure i want to append a string at the end of a file and this file
can be used as a test report.
i Have tried this code but it did not log anything in the file."

This sounds like a good use for a callback plugin. A custom callback plugin
could append to a file on *_ok/*_fail callbacks.
I would base it around the python 'logging' module, but it could be
something simpler.

The 'junit' callback might be a good example and could possibly be used
directly if a junit.xml file is useful for your test tool.

On Thu, Jul 27, 2017 at 4:35 AM, Kai Stian Olstad <
[email protected]> wrote:

> On 27.07.2017 02:08, Vijay Misra wrote:
>
>>    I am trying to use ansible as a test tool. at the end of each
>> sucess/faiure i want to append a string at the end of a file and this file
>> can be used as a test report.
>> i Have tried this code but it did not log anything in the file.
>>
>> - debug: msg="HPQC Create snapshot of a vGPU VM on ESX"
>>   when: taskresult|succeeded
>> - debug: msg="HPQC Failed Create snapshot of a vGPU VM on ESX"
>>   when: taskresult|failed
>>
>
> Debug only writes to the stdout so you only get those on screen.
>
>
> - shell: echo "HPQC Passed Create snapshot of a vGPU VM on ESX" >>
>> results.txt
>>   when: taskresult|succeeded
>> - shell: echo "HPQC Failed Create snapshot of a vGPU VM on ESX" >>
>> results.txt
>>   when: taskresult|failed
>>
>
> This will store the text in the file results.txt on the remote host, not
> on the host you are running ansible playbook on.
> To write to a file on localhost you need to add  delegate_to: localhost
>
> The problem occur if you run against more than one host, you'll have
> several processes trying to write to the same file at once, this is very
> error prone.
> One solution to overcome that is run_once with a loop.
>
>   - shell: echo "HPQC {{ (hostvars[item].result | succeeded) |
> ternary('Passed', 'Failed') }} Create snapshot of a vGPU VM on ESX"
> >>results.txt
>     with_items: "{{ ansible_play_hosts }}"
>     delegate_to: localhost
>     run_once: yes
>
>
> --
> Kai Stian Olstad
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> To view this discussion on the web visit https://groups.google.com/d/ms
> gid/ansible-project/050bee11a57a65b96f4d54e4c64accac%40olstad.com.
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/CAOJNLf_RvPT%3D1josShCApQ94qrkZWAdU5KD%2BM8BZL_LvzsJAfA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to