[ansible-project] How to gather kernel parameters of remote hosts

957 views
Skip to first unread message

Vikrant Agarwal

unread,
Feb 17, 2020, 7:47:35 AM2/17/20
to ansible...@googlegroups.com
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

Dick Visser

unread,
Feb 17, 2020, 8:47:45 AM2/17/20
to ansible...@googlegroups.com
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

--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAFn3J16xSQXGvmrrzQO1%2BcGS-Ppy_Gah%2ByH09AA4Ezdxh%3D_Xxg%40mail.gmail.com.


--
Dick Visser
Trust & Identity Service Operations Manager
GÉANT

Stefan Hornburg (Racke)

unread,
Feb 17, 2020, 8:48:06 AM2/17/20
to ansible...@googlegroups.com
On 2/17/20 1:46 PM, Vikrant Agarwal wrote:
> 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

command: sysctl -a
register: sysctl_settings

Regards
Racke
> --
> You received this message because you are subscribed to the Google Groups "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> <https://groups.google.com/d/msgid/ansible-project/CAFn3J16xSQXGvmrrzQO1%2BcGS-Ppy_Gah%2ByH09AA4Ezdxh%3D_Xxg%40mail.gmail.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

Vladimir Botka

unread,
Feb 17, 2020, 9:32:01 AM2/17/20
to Vikrant Agarwal, Dick Visser, ansible...@googlegroups.com
On Mon, 17 Feb 2020 14:47:19 +0100
Dick Visser <dick....@geant.org> wrote:

> tasks:
> - name: find out sysctl values
> shell: sysctl {{ params | join(' ') }}
> register: sysctl_out

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

- command: "sysctl -n {{ params | join(' ') }}"
register: sysctl_out
- set_fact:
sysctl_dict: "{{ dict(params|zip(sysctl_out.stdout_lines)) }}"

HTH,

-vlado
Reply all
Reply to author
Forward
0 new messages