Last active
March 21, 2022 15:40
-
-
Save supix/7c576663ceb5759ef41df020e3f26d76 to your computer and use it in GitHub Desktop.
Ansible playbook useful to gather the host kernel version
This file contains hidden or 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
--- | |
- 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