Created
May 14, 2021 22:26
-
-
Save frock81/fe6d22215ce3793401e9efd5f53ca76a to your computer and use it in GitHub Desktop.
Produces a list with the operating systems being executed on each host
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: all | |
become: false | |
vars: | |
output_file: os.csv | |
tasks: | |
- block: | |
# For permisison setup. | |
- name: get current user | |
command: whoami | |
register: whoami | |
run_once: true | |
- name: clean file | |
copy: | |
dest: "{{ output_file }}" | |
content: 'hostname,distribution,version,release' | |
owner: "{{ whoami.stdout }}" | |
run_once: true | |
- name: fill os information | |
lineinfile: | |
path: "{{ output_file }}" | |
line: "{{ ansible_hostname }},\ | |
{{ ansible_distribution }},\ | |
{{ ansible_distribution_version }},\ | |
{{ ansible_distribution_release }}" | |
# Tries to prevent concurrent writes. | |
throttle: 1 | |
delegate_to: localhost |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment