Skip to content

Instantly share code, notes, and snippets.

@funkytaco
Forked from xandout/hosts.csv.out
Created October 25, 2022 14:04
Show Gist options
  • Save funkytaco/c6d504edaaf291e90367c88ae6685260 to your computer and use it in GitHub Desktop.
Save funkytaco/c6d504edaaf291e90367c88ae6685260 to your computer and use it in GitHub Desktop.
1561572401,horse-uat,Ubuntu,16,16.04,xenial
1561572405,moose-uat,Ubuntu,16,16.04,xenial
1561572408,duck-uat,Ubuntu,16,16.04,xenial
1561572413,goat-uat,Ubuntu,16,16.04,xenial
1561572415,horse-dev,Ubuntu,16,16.04,xenial
1561571759,moose-dev,Amazon,2016,NA,NA
1561572422,duck-dev,Ubuntu,16,16.04,xenial
1561572426,goat-dev,Ubuntu,14,14.04,trusty
---
# First, clear the local CSV
- hosts: localhost
tasks:
- name: Clear
copy:
content: ''
dest: "hosts.csv"
run_once: True
delegate_to: 127.0.0.1
# Now write a line per host
- hosts: all
serial: 1
tasks:
- name: Write
lineinfile:
dest: "hosts.csv"
line: '{{ ansible_date_time.epoch }},{{ inventory_hostname }},{{ ansible_distribution }},{{ ansible_distribution_major_version }},{{ ansible_distribution_version }},{{ ansible_distribution_release | default("NONE") }}'
delegate_facts: yes
delegate_to: 127.0.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment