# How to gather kernel parameters of remote hosts

**URL:** <https://forum.ansible.com/t/how-to-gather-kernel-parameters-of-remote-hosts/32250>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [February 17, 2020, 12:46pm UTC](https://forum.ansible.com/t/how-to-gather-kernel-parameters-of-remote-hosts/32250 "2020-02-17T12:46:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Vikrant\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/v/8baadc/32.png) [@Vikrant\_Agarwal](https://forum.ansible.com/u/Vikrant_Agarwal)\
**Post date:** [February 17, 2020, 12:46pm UTC](https://forum.ansible.com/t/how-to-gather-kernel-parameters-of-remote-hosts/32250/1 "2020-02-17T12:46:58Z")

</div>

How to i collect remote hosts kernel parameters using ansible. I’m looking to below type collect info of remote hosts . setup module doesn’t collect this info .

And sysctl module is to edit , can i use sysctl module just to list the parameters and not to modify anything ?

net.ipv4.ip\_forward = 0  
net.ipv4.conf.default.rp\_filter = 1  
net.ipv4.conf.default.accept\_source\_route = 0  
kernel.sysrq = 0  
kernel.core\_uses\_pid = 1  
net.ipv4.tcp\_syncookies = 1  
kernel.msgmnb = 65536  
kernel.msgmax = 65536  
kernel.shmmax = 68719476736  
kernel.shmall = 4294967296  
fs.file-max = 209702  
net.core.optmem\_max = 10000000  
net.core.rmem\_default = 10000000  
net.core.rmem\_max = 10000000  
net.core.wmem\_default = 10000000  
net.core.wmem\_max = 10000000  
net.ipv4.conf.all.rp\_filter = 1  
net.ipv4.tcp\_max\_tw\_buckets = 2000000  
net.ipv4.tcp\_mem = 30000000 30000000 30000000  
net.ipv4.tcp\_rmem = 30000000 30000000 30000000  
net.ipv4.tcp\_wmem = 30000000 30000000 30000000  
net.ipv4.ip\_local\_port\_range = 32768 65000  
net.ipv4.ip\_forward = 0  
net.ipv4.conf.default.rp\_filter = 1  
net.ipv4.tcp\_timestamps = 1  
net.ipv4.tcp\_fin\_timeout = 30  
net.ipv4.tcp\_keepalive\_time = 300  
net.ipv4.tcp\_window\_scaling = 1  
net.ipv4.tcp\_sack = 1  
net.ipv4.igmp\_max\_memberships = 4096  
kernel.pid\_max = 131072  
kernel.pid\_max = 131072

Regards  
Vikrant

---

<div class="post-metadata">

**Author:** ![Dick\_Visser](https://avatars.discourse-cdn.com/v4/letter/d/d9b06d/32.png) [@Dick\_Visser](https://forum.ansible.com/u/Dick_Visser)\
**Post date:** [February 17, 2020, 1:47pm UTC](https://forum.ansible.com/t/how-to-gather-kernel-parameters-of-remote-hosts/32250/2 "2020-02-17T13:47:19Z")

</div>

Probably best done in one long cmd, for example:

- hosts: all  
vars:  
params:
- net.ipv4.ip\_forward
- net.ipv4.conf.default.rp\_filter
- net.ipv4.conf.default.accept\_source\_route
- kernel.sysrq
- kernel.core\_uses\_pid
- net.ipv4.tcp\_syncookies
- kernel.msgmnb
- kernel.msgmax
- kernel.shmmax
- kernel.shmall
- fs.file-max
- net.core.optmem\_max
- net.core.rmem\_default
- net.core.rmem\_max
- net.core.wmem\_default
- net.core.wmem\_max
- net.ipv4.conf.all.rp\_filter
- net.ipv4.tcp\_max\_tw\_buckets
- net.ipv4.tcp\_mem
- net.ipv4.tcp\_rmem
- net.ipv4.tcp\_wmem
- net.ipv4.ip\_local\_port\_range
- net.ipv4.ip\_forward
- net.ipv4.conf.default.rp\_filter
- net.ipv4.tcp\_timestamps
- net.ipv4.tcp\_fin\_timeout
- net.ipv4.tcp\_keepalive\_time
- net.ipv4.tcp\_window\_scaling
- net.ipv4.tcp\_sack
- net.ipv4.igmp\_max\_memberships
- kernel.pid\_max
- kernel.pid\_max

tasks:

- name: find out sysctl values  
shell: sysctl {{ params | join(’ ') }}  
register: sysctl\_out

- debug: var=sysctl\_out

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [February 17, 2020, 1:47pm UTC](https://forum.ansible.com/t/how-to-gather-kernel-parameters-of-remote-hosts/32250/3 "2020-02-17T13:47:42Z")

</div>

> How to i collect remote hosts kernel parameters using ansible. I'm looking to below type collect info of remote hosts .  
> setup module doesn't collect this info .
> 
> And sysctl module is to edit , can i use sysctl module just to list the parameters and not to modify anything ?

According to its documentation, no.

But you can read the current values with

&nbsp;&nbsp;&nbsp;command: sysctl -a  
&nbsp;&nbsp;&nbsp;register: sysctl\_settings

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![vbotka](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/vbotka/32/359_2.png) [@vbotka](https://forum.ansible.com/u/vbotka)\
**Post date:** [February 17, 2020, 2:31pm UTC](https://forum.ansible.com/t/how-to-gather-kernel-parameters-of-remote-hosts/32250/4 "2020-02-17T14:31:41Z")

</div>

Optionally ask sysctl to print values only and set dictionary of the  
parameters and values. For example

&nbsp;&nbsp;&nbsp;&nbsp;- command: "sysctl -n {{ params | join(' ') }}"  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;register: sysctl\_out  
&nbsp;&nbsp;&nbsp;&nbsp;- set\_fact:  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;sysctl\_dict: "{{ dict(params|zip(sysctl\_out.stdout\_lines)) }}"

HTH,

&nbsp;&nbsp;-vlado
