Skip to content

Instantly share code, notes, and snippets.

@sandipb
Created September 27, 2021 22:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save sandipb/8ad80e6af9d471b04e2ec7948224ff3d to your computer and use it in GitHub Desktop.
Get non-matching kernels on all hosts using ansible
---
- hosts: ubuntu
gather_facts: yes
vars:
kernel_does_not_match: "{{ (ansible_distribution == 'Ubuntu') and ( ansible_kernel != '5.4.0-86-generic') }}"
output_path_local: /tmp/host_kernels
tasks:
- block:
- name: Add matching host to file
lineinfile:
path: "{{ output_path_local }}"
create: yes
regex: '^{{ inventory_hostname }}:'
line: "{{ inventory_hostname }}: {{ ansible_kernel }}"
when: kernel_does_not_match
- name: Remove non-matching hosts from file
lineinfile:
path: "{{ output_path_local }}"
create: yes
regex: '^{{ inventory_hostname }}:'
state: absent
when: not kernel_does_not_match
connection: local
throttle: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment