Using salt.modules.mod_random to generate a password in a SLS

689 views
Skip to first unread message

pho...@startledphoenix.com

unread,
Dec 15, 2014, 11:05:48 PM12/15/14
to salt-...@googlegroups.com
How can I use the mod_random module to generate a password?

salt '*' random.get_str 20

Works

However, using a SLS,

{% set test_root = salt['mod_random']('get_str')('20') %}

and

{% set test_root = salt['random']('get_str')('20') %}

both fail.

Any help will be appreciated.

Stephen Spencer

unread,
Dec 16, 2014, 12:40:35 AM12/16/14
to salt-...@googlegroups.com
This day, sir, you do not win The Internet.

No.  Denied!

Not even Lycos or the hollowed out shell that used to be called MySpace.

Seriously, though, the devil is in the function arguments.

def get_str(length=20):
  off_to_pyrcrypto_magicland(length)

It works from the salt CLI because salt does things to make us not hate it (such as passing a number or a string when said type is needed for a certain function call).  Anyway, remove the quotes from around your "number" so it can go on its merry way as the int that it desperately wants to be.

-S
  


--
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.


--
You know, I used to think it was awful that life was so unfair. Then I thought, wouldn't it be much worse if life were fair, and all the terrible things that happen to us come because we actually deserve them? So, now I take great comfort in the general hostility and unfairness of the universe.

Seth House

unread,
Dec 17, 2014, 8:30:01 PM12/17/14
to salt-...@googlegroups.com
Execution modules are available to Jinja in a dictionary keyed by strings in the format of 'module.function'. The correct syntax is this:

{% set test_root = salt['random.get_str'](20) %}

 Also you can pass a real number as the argument instead of a string as Stephen suggested.

pho...@startledphoenix.com

unread,
Dec 18, 2014, 1:08:00 AM12/18/14
to salt-...@googlegroups.com
Ah, there we go.

Thanks for the help :)
Reply all
Reply to author
Forward
0 new messages