Thanks kai !
Yes, I don't know how i missed the localhost part after adding "delegateTo:
localhost" I am able to append the line on each test case success/failure.
One more thing i wanted to clarify nomatter what command i se for appending
the line( command/sheel/lineinfile) it always fails and outpus sudo; A
password is required.
am i missing something>
I have my playbook that contained one role and i declared "become: true"
before the role as below
*//vcenter_snaprestore.yml*
- hosts: esx1
become: true
roles:
- ESX_VM_SnapRestore
**********************************************
- lineinfile:
path: /etc/ansible/results.txt
line: 'HPQC Passed Create snapshot of a vGPU VM on ESX'
insertafter: EOF
when: taskresult|succeeded
delegate_to: localhost
vmisra@ubuntu:/etc/ansible$ ansible-playbook vcenter_snaprestore.yml
----
ASK [ESX_VM_SnapRestore : lineinfile]
*********************************************************************************************************************************************************************
fatal: [ -> localhost]: FAILED! => {"changed": false, "failed": true,
"module_stderr": "sudo: a password is required\n", "module_stdout": "",
"msg": "MODULE FAILURE", "rc": 1
Thanks a lot for help!
-Vijay
On Thursday, July 27, 2017 at 1:36:06 AM UTC-7, Kai Stian Olstad 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/msgid/ansible-project/46a0da41-6ffe-438d-809b-a1944d51507d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.