Skip to content

Instantly share code, notes, and snippets.

@supix
Last active March 21, 2022 15:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supix/7c576663ceb5759ef41df020e3f26d76 to your computer and use it in GitHub Desktop.
Save supix/7c576663ceb5759ef41df020e3f26d76 to your computer and use it in GitHub Desktop.
Ansible playbook useful to gather the host kernel version
---
- name: gather kernel version
hosts: all
vars:
filename: /tmp/kernelv.txt
dst_folder: /tmp/hosts
tasks:
- name: delete the centralized file
file:
path: "{{ filename }}"
state: absent
delegate_to: localhost
run_once: true
- name: ensure directory exists
file:
path: "{{ dst_folder }}"
state: directory
delegate_to: localhost
run_once: true
- name: do the job
shell: uname -a
register: kernelv
- name: print output to screen
debug:
msg: '{{ kernelv.stdout }}'
- name: print output to file per host
copy:
content: "{{ kernelv.stdout }}"
dest: "{{ dst_folder }}/{{ ansible_hostname }}.txt"
delegate_to: localhost
- name: print output to a centralized file
lineinfile:
path: "{{ filename }}"
line: "{{ ansible_hostname }} {{ kernelv.stdout.split(\" \")[2] }}"
create: true
delegate_to: localhost
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment