Assumptions
For use with eg CentOS or Ubuntu.
Assumes you have a file /etc/ansible/hosts with groups and members already configured.
A properly formatted .yml-file can be found at the end of the article.
---
- hosts: cyndane2 ceres2
gather_facts: yes
become: false
tasks:
- name: Gather Version
debug:
msg: "The server Operating system is {{ ansible_distribution }} {{ ansible_distribution_version }}"
- name: Write Version
local_action: shell echo "{{ inventory_hostname }} is running {{ ansible_distribution_version }}" >> /home/sorin/hostname-os-version-output.txt
...
Sources
https://serverfault.com/questions/804387/how-to-send-ansible-debug-messages-to-another-file