storing dynamic variables in salt

236 views
Skip to first unread message

Mano Nathan

unread,
Jun 18, 2014, 5:28:16 PM6/18/14
to salt-...@googlegroups.com
Hi,

How do i store some dynamic values in salt. For example, I want to cat /proc/meminfo and get the value and do some calculation for hugepages and store the value in /etc/sysctl.conf file. 

How can I do this in salt. Please advise. 

Mano Nathan

unread,
Jun 18, 2014, 6:26:07 PM6/18/14
to salt-...@googlegroups.com
     How can i fix this 

        - Rendering SLS 'sysctl' failed, render error:
        - Jinja syntax error: unexpected char u'`' at 17; line 1
        -
        - ---
        - {% set s_raminkb=`/bin/cat /proc/meminfo | /bin/grep MemTotal: | /bin/awk -F ' ' '{print $2}'`}    <======================

Vitaliy Fuks

unread,
Jun 18, 2014, 7:46:14 PM6/18/14
to salt-...@googlegroups.com
To run a command and use its output:

salt['cmd.run']('/bin/cat /proc/meminfo | /bin/grep MemTotal:').split(': ')[1]

though for your specific example, you could just use:

grains.get('mem_total')

--
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.
For more options, visit https://groups.google.com/d/optout.

Mano Nathan

unread,
Jun 19, 2014, 10:49:19 AM6/19/14
to salt-...@googlegroups.com
How do I dod the calculation and store the new value?

Do I need to use pillar? or any other technique. 

Mano Nathan

unread,
Jun 19, 2014, 11:13:02 AM6/19/14
to salt-...@googlegroups.com


[root@nova ~]# salt 'client.example.com' grains.get mem_total
    996

once I get the men total, I wanted to do the below calculation and store in hugepages. How can i archive this using salt? 

( 996 * 0.4 - 2097152 ) / 2048

Arnold Bechtoldt

unread,
Jun 19, 2014, 12:50:30 PM6/19/14
to salt-...@googlegroups.com
You can find code examples at <https://github.com/saltstack-formulas>
and <https://github.com/bechtoldt?tab=repositories>.

--
Arnold Bechtoldt

Karlsruhe, Germany

Am 19.06.14 16:49, schrieb Mano Nathan:
>> send an email to salt-users+...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout
>> <https://groups.google.com/d/optout>.
>
> --
> 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
> <mailto:salt-users+...@googlegroups.com>.
0xE2356889.asc
signature.asc

Mano Nathan

unread,
Jun 19, 2014, 2:40:16 PM6/19/14
to salt-...@googlegroups.com
{% set hugepages = (grains['mem_total'] * 1024 * 0.4 - 2097152 ) / 2048 %}

i am getting decimal number. How can i convert to whole digit? 

Ryan Lane

unread,
Jun 19, 2014, 4:40:59 PM6/19/14
to salt-...@googlegroups.com
On Thu, Jun 19, 2014 at 11:40 AM, Mano Nathan <mha...@gmail.com> wrote:
{% set hugepages = (grains['mem_total'] * 1024 * 0.4 - 2097152 ) / 2048 %}

i am getting decimal number. How can i convert to whole digit? 


{% set hugepages = (grains['mem_total'] * 1024 * 0.4 - 2097152 ) / 2048 | float %}

See:

http://jinja.pocoo.org/docs/templates/#float

Or did you mean you wanted an int?

{% set hugepages = (grains['mem_total'] * 1024 * 0.4 - 2097152 ) / 2048 | int %}


- Ryan
Reply all
Reply to author
Forward
0 new messages