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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/15123a9a-fc1c-4b8b-8a0a-2f24cf9a06a6n%40googlegroups.com.
[test-vms]
test-vm01
test-vm02
test-vm03
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/783f270f-bf70-4614-9c16-94ba281bd33an%40googlegroups.com.
{"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"
}
}
....
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/110119d1-399c-46d9-84eb-bdc2ba896f68n%40googlegroups.com.