Contents[Show]

1. 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
 ...

 

 

2. Sources

https://serverfault.com/questions/804387/how-to-send-ansible-debug-messages-to-another-file

https://serverfault.com/questions/901433/how-can-i-log-inventory-hostname-to-a-file-on-the-remote-using-a-playbook

 

 

 

 

 

 

 

Attachments:
Download this file (find-os-version-v2)find-os-version-v2[ ]0.4 kB