Thanks, Matt.

>> Perhaps you want to set a log file instead...
Well, I don't want to have the whole log file that contains all details of 
different play, but only the output of the play. 

>>you'll want to use a template and build the output in the format you 
want..
I will look into it.

Frank
On Tuesday, December 6, 2022 at 4:05:27 PM UTC-5 Matt Martz wrote:

> Registered results do not contain the full output as seen on the screen.  
> Perhaps you want to set a log file instead, otherwise, you'll want to use a 
> template and build the output in the format you want.  The screen output is 
> controlled by a callback plugin which does extra formatting.
>
> See 
> https://docs.ansible.com/ansible-core/2.14/reference_appendices/config.html#default-log-path
>
> On Tue, Dec 6, 2022 at 3:02 PM Frank Ling <[email protected]> wrote:
>
>> Well as a workaround I could use: ansible-playbook ping_email.yml >> 
>> /tmp/file.txt to save the output as a file. But I hope there could be a 
>> better way.
>>
>> Thanks.
>>
>> On Tuesday, December 6, 2022 at 3:34:47 PM UTC-5 Frank Ling wrote:
>>
>>> >>What makes it weird?
>>> I wanted to save the ansible ping results to /tmp/file.txt so I can 
>>> email out the result.
>>>
>>> After running the playbook, I just got following saved in /tmp/file.txt:
>>>
>>> {"ping": "pong", "failed": false, "changed": false}
>>>
>>> >>What were you expecting instead?
>>>
>>> I added a few lines in the playbook as:
>>>
>>> ---
>>> - hosts: test-vms 
>>>   tasks:
>>>     - name: Ping vms in test-vms
>>>       ansible.builtin.ping: 
>>>       register: ping_pong
>>>       ignore_errors: True
>>>
>>>     - name: Ping result
>>>       ansible.builtin.ping:
>>>       register: ping_screen
>>>
>>>     - name: Ping the result to the screen
>>>       ansible.builtin.debug:
>>>          var: ping_screen
>>>
>>>
>>>
>>>     - name: Copy the output result to /tmp/file.txt 
>>>       ansible.builtin.copy: 
>>>           content: "{{ ping_pong }}"
>>>           dest: /tmp/file.txt
>>>
>>> When I ran it, the ping result would show on the screen as following and 
>>> I would like to save following result to /tmp/file.txt:
>>>
>>> ...
>>>
>>> TASK [Ping the result to the screen] 
>>> ***********************************************************************************
>>> ok: [test-vm01] => {
>>>     "ping_screen": {
>>>         "changed": false,
>>>         "failed": false,
>>>         "ping": "pong"
>>>     }
>>> }
>>> ok: [test-vm02] => {
>>>     "ping_screen": {
>>>         "changed": false,
>>>         "failed": false,
>>>         "ping": "pong"
>>>     }
>>> }
>>> ok: [test-vm03] => {
>>>     "ping_screen": {
>>>         "changed": false,
>>>         "failed": false,
>>>         "ping": "pong"
>>>     }
>>> }
>>>
>>> ....
>>>
>>>
>>>
>>>
>>> On Tuesday, December 6, 2022 at 3:21:44 PM UTC-5 Matt Martz wrote:
>>>
>>>> Also, it helps when you clarify what you want to see, instead of "I got 
>>>> this weird result".
>>>>
>>>> What makes it weird?  What were you expecting instead?
>>>>
>>>> On Tue, Dec 6, 2022 at 2:09 PM Frank Ling <[email protected]> wrote:
>>>>
>>>>> Thanks for the reply.
>>>>>
>>>>> >> You're saving the result for each host to the same file.
>>>>> Yeah, you're right. I am not sure how to save the output in Ansible to 
>>>>> the output in a file like in shell >> /tmp/file 
>>>>>
>>>>> >>And there is something weird with the inventory you use...
>>>>> I had the inventory in /etc/ansible/hosts with:
>>>>>
>>>>> [test-vms]
>>>>> test-vm01
>>>>> test-vm02
>>>>> test-vm03
>>>>>  Frank
>>>>>
>>>>> On Tuesday, December 6, 2022 at 3:00:48 PM UTC-5 [email protected] 
>>>>> wrote:
>>>>>
>>>>>> Several things here. 
>>>>>> You're saving the result for each host to the same file. So you will 
>>>>>> end up with just one result, from the last host.
>>>>>> And there is something weird with the inventory you use. Follow the 
>>>>>> suggestion made by the code (use increased verbosity). 
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Tue, 6 Dec 2022 at 20:54, Frank Ling <[email protected]> wrote:
>>>>>>
>>>>>>> I need some helps for fixing the bug of saving the Ansible ping 
>>>>>>> results to a local file. 
>>>>>>>
>>>>>>> Appreciate your help. 
>>>>>>>
>>>>>>> Thanks in advance.
>>>>>>>
>>>>>>> Frank
>>>>>>>
>>>>>>> After running the playbook, I got this weird result:
>>>>>>>
>>>>>>> cat /tmp/file.txt
>>>>>>>
>>>>>>> {"ping": "pong", "failed": false, "changed": false}
>>>>>>>
>>>>>>> ============================================
>>>>>>>
>>>>>>> Here is the playbook:
>>>>>>>
>>>>>>> ---
>>>>>>> - hosts: test-vms 
>>>>>>>   tasks:
>>>>>>>     - name: Ping vms in test-vms
>>>>>>>       ansible.builtin.ping: 
>>>>>>>          register: ping_pong
>>>>>>>          ignore_errors: True
>>>>>>>
>>>>>>>     - name: Copy the output result to /tmp/file.txt 
>>>>>>>       ansible.builtin.copy: 
>>>>>>>           content: "{{ ping_pong }}"
>>>>>>>           dest: /tmp/file.txt
>>>>>>>
>>>>>>> ===================================================
>>>>>>>
>>>>>>> $ ansible-playbook ping_email.yml
>>>>>>> [WARNING]: Invalid characters were found in group names but not 
>>>>>>> replaced, use -vvvv to see details
>>>>>>> [WARNING]: Found both group and host with same name: localhost
>>>>>>>
>>>>>>> PLAY [test-vms] 
>>>>>>> ********************************************************************************************************
>>>>>>>
>>>>>>> TASK [Gathering Facts] 
>>>>>>> *************************************************************************************************
>>>>>>> ok: [test-vm03]
>>>>>>> ok: [test-vm02]
>>>>>>> ok: [test-vm01]
>>>>>>>
>>>>>>> TASK [Ping vms in test-vms] 
>>>>>>> ********************************************************************************************
>>>>>>> ok: [test-vm03]
>>>>>>> ok: [test-vm02]
>>>>>>> ok: [test-vm01]
>>>>>>>
>>>>>>> TASK [Copy the output result to /tmp/file.txt] 
>>>>>>> *************************************************************************
>>>>>>> changed: [test-vm01]
>>>>>>> changed: [test-vm02]
>>>>>>> changed: [test-vm03]
>>>>>>>
>>>>>>> PLAY RECAP 
>>>>>>> *************************************************************************************************************
>>>>>>> test-vm01                  : ok=3    changed=1    unreachable=0   
>>>>>>>  failed=0    skipped=0    rescued=0    ignored=0   
>>>>>>> test-vm02                  : ok=3    changed=1    unreachable=0   
>>>>>>>  failed=0    skipped=0    rescued=0    ignored=0   
>>>>>>> test-vm03                  : ok=3    changed=1    unreachable=0   
>>>>>>>  failed=0    skipped=0    rescued=0    ignored=0 
>>>>>>>
>>>>>>>
>>>>>>> -- 
>>>>>>> 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 view this discussion on the web visit 
>>>>>>> https://groups.google.com/d/msgid/ansible-project/15123a9a-fc1c-4b8b-8a0a-2f24cf9a06a6n%40googlegroups.com
>>>>>>>  
>>>>>>> <https://groups.google.com/d/msgid/ansible-project/15123a9a-fc1c-4b8b-8a0a-2f24cf9a06a6n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>>>> .
>>>>>>>
>>>>>> -- 
>>>>>> Sent from Gmail Mobile
>>>>>>
>>>>> -- 
>>>>> 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 view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/ansible-project/783f270f-bf70-4614-9c16-94ba281bd33an%40googlegroups.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/ansible-project/783f270f-bf70-4614-9c16-94ba281bd33an%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>
>>>>
>>>> -- 
>>>> Matt Martz
>>>> @sivel
>>>> sivel.net
>>>>
>>> -- 
>> 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 view this discussion on the web visit 
>> https://groups.google.com/d/msgid/ansible-project/110119d1-399c-46d9-84eb-bdc2ba896f68n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/ansible-project/110119d1-399c-46d9-84eb-bdc2ba896f68n%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>>
>
>
> -- 
> Matt Martz
> @sivel
> sivel.net
>

-- 
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/d35c410a-bde8-40f8-9993-b84fc98b0c43n%40googlegroups.com.

Reply via email to