Thanks Rick for your help !
I am using lineinfile now and it works partially, only thing is it fails 
initially and outputs Sudo: a password requied". if i give permission 
through cmod 777 results.txt and then try to run the playbook it passes.

- lineinfile:
    path: /etc/ansible/results.txt
    line: 'HPQC1 Passed Create snapshot of a vGPU VM on ESX'
    insertafter: EOF
  when: taskresult|succeeded
  delegate_to: localhost


vcenter_snaprestore.yml
***********************************************


- hosts: esx1
  become: true
  roles:
     - ESX_VM_SnapRestore
**********************************

vmisra@ubuntu:/etc/ansible$ ansible-playbook vcenter_snaprestore.yml


Do you see any reason for sudo: a Password required error message.

Thanks,
Vijay


On Thursday, July 27, 2017 at 12:42:34 AM UTC-7, Rick Stokkingreef wrote:
>
> Hi,
>
> You should use the line in file module, only specify the path and line. 
> This way it will append it to the file.
>
> Op donderdag 27 juli 2017 02:08:53 UTC+2 schreef Vijay Misra:
>>
>>
>>   Hi ,
>>
>>    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
>>
>>
>> - 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
>>
>>
>>   when i run with -vvvv switch, I get the following output but nothing is 
>> appended in the file locataed at /etc/ansible/ directoery( I am running 
>> playbook from /etc/ansible directory)
>>
>>  
>> changed: [] => {
>>     "changed": true, 
>>     "cmd": "echo \"HPQC Passed Create snapshot of a vGPU VM on ESX\" >> 
>> results.txt", 
>>     "delta": "0:00:00.017046", 
>>     "end": "2017-07-27 00:07:14.100974", 
>>     "invocation": {
>>         "module_args": {
>>             "_raw_params": "echo \"HPQC Passed Create snapshot of a vGPU VM 
>> on ESX\" >> results.txt", 
>>             "_uses_shell": true, 
>>             "chdir": null, 
>>             "creates": null, 
>>             "executable": null, 
>>             "removes": null, 
>>             "warn": true
>>         }
>>     }, 
>>     "rc": 0, 
>>     "start": "2017-07-27 00:07:14.083928", 
>>     "stderr": "", 
>>     "stderr_lines": [], 
>>     "stdout": "", 
>>     "stdout_lines": []
>> }
>>
>> TASK [ESX_VM_SnapRestore : command] 
>> ************************************************************************************************************************************************************************
>> task path: /etc/ansible/roles/ESX_VM_SnapRestore/tasks/main.yml:41
>> skipping: [1] => {
>>     "changed": false, 
>>     "skip_reason": "Conditional result was False", 
>>     "skipped": true
>> }
>>
>> Thanks for your help.
>>
>> -VM
>>
>>

-- 
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/6e24d0b5-53e2-4e46-8773-c86521ce89a0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to