Created
September 27, 2021 22:58
-
-
Save sandipb/8ad80e6af9d471b04e2ec7948224ff3d to your computer and use it in GitHub Desktop.
Get non-matching kernels on all hosts using ansible
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
--- | |
- 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