can sysctl.present have multiple items?

479 views
Skip to first unread message

Yong Zhang

unread,
Jun 22, 2017, 7:59:29 AM6/22/17
to Salt-users
Hi,

I want to use state sysctl.present to config some sysctl settings, is it possible to define multiple items like below (I tested with below state but doesn't work, just want to know how to define multiple items within one sysctl.present)?


sysctlsettings:
  sysctl.present:
    - name: net.ipv4.tcp_tw_reuse
      value: 1
    - name: net.ipv4.ip_local_port_range
      value: 10240    65535
    - name: kernel.sysrq
      value: 1
    - name: net.ipv6.conf.all.disable_ipv6
      value: 1
    - name: net.ipv6.conf.default.disable_ipv6
      value: 1
    - name: net.core.somaxconn
      value: 262144

Viet Hung Nguyen

unread,
Jun 22, 2017, 12:38:09 PM6/22/17
to Salt-users
No, it is not possible doing exactly what you showed.

The code here says that you can set only 1 item with each sysctl.present https://github.com/saltstack/salt/blob/develop/salt/states/sysctl.py#L30

But you can get the same effect by using a Jinja2 loop over all item, so, create different states
This is an example of doing so  https://github.com/hvnsweeting/states/blob/master/sysctl/init.sls

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/fdfb2159-4a4d-40d4-8c52-342825df3d94%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Thanks & Best regards,
Nguyen Viet Hung (Mr)
[a.k.a HVN]

Mobile: 0982090290

Thomas Phipps

unread,
Jun 22, 2017, 3:00:03 PM6/22/17
to Salt-users
actually you can. although getting that many different values together kind of looks ugly to me.

sysctlsettings_true:
  sysctl.present:
    - value: 1
    - names:
      - net.ipv4.tcp_tw_reuse
      - kernel.sysreq
      - net.ipv6.conf.all.disable_ipv6
      - net.ipv6.conf.default.disable_ipv6
      - net.ipv4.ip_local_port_range
        - value: 10240 65535
      - net.core.somaxconn
        - value: 262144






On Thu, Jun 22, 2017 at 9:38 AM Viet Hung Nguyen <h...@familug.org> wrote:
No, it is not possible doing exactly what you showed.

The code here says that you can set only 1 item with each sysctl.present https://github.com/saltstack/salt/blob/develop/salt/states/sysctl.py#L30

But you can get the same effect by using a Jinja2 loop over all item, so, create different states
This is an example of doing so  https://github.com/hvnsweeting/states/blob/master/sysctl/init.sls
On Thu, Jun 22, 2017 at 6:59 PM, Yong Zhang <hisca...@gmail.com> wrote:
Hi,

I want to use state sysctl.present to config some sysctl settings, is it possible to define multiple items like below (I tested with below state but doesn't work, just want to know how to define multiple items within one sysctl.present)?


sysctlsettings:
  sysctl.present:
    - name: net.ipv4.tcp_tw_reuse
      value: 1
    - name: net.ipv4.ip_local_port_range
      value: 10240    65535
    - name: kernel.sysrq
      value: 1
    - name: net.ipv6.conf.all.disable_ipv6
      value: 1
    - name: net.ipv6.conf.default.disable_ipv6
      value: 1
    - name: net.core.somaxconn
      value: 262144

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
--
Thanks & Best regards,
Nguyen Viet Hung (Mr)
[a.k.a HVN]

Mobile: 0982090290

--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/CAJm7hK%2B%2BKhRQmmy95w5ZTuxpMtKhprp-i3bms2OKdZH5WSVm-A%40mail.gmail.com.

Daniel Wallace

unread,
Jun 23, 2017, 9:34:52 AM6/23/17
to Salt-users
Need some colons after somaxconn, and the other ones that have an extra value, but this is how I would do it.
Reply all
Reply to author
Forward
0 new messages