Get UUID of a disk in a salt state

365 views
Skip to first unread message

Kai

unread,
Jan 18, 2016, 11:03:31 AM1/18/16
to Salt-users
Hello,

I want to do the following:

{% set dev_data = '/dev/sdb' %}
{% set dev_data_uuid = (somehow get the uuid of dev_data)%}

Whats the correct way to execute
salt 'server' disk.blkid /dev/sdb

here and than get the UUID.

Thanks,
Kai

Jakub Mikusek

unread,
Jan 18, 2016, 11:34:28 AM1/18/16
to salt-...@googlegroups.com
Hi Kai,
Have you tried the following?

{% set dev_data_uuid = salt['disk.blkid'](dev_data) %}

Let me know if that worked!

Regards,
Jakub

--
"Imagination is more important than knowledge" -> Albert Einstein
tel: +353 83 44 50 623
jabber: ja...@mikusek.org
gg: 3386899 skype: mmmick3y

Kai

unread,
Jan 18, 2016, 12:03:50 PM1/18/16
to Salt-users
Hi,
thanks, but that gives me: {'/dev/sdb': {'TYPE': 'xfs', 'UUID': '882ea96e-0a5e-4720-9b04-cb765206ee98'}}
I only need the UUID.

How do I access just the UUID field in the state?

Thanks,
Kai

Jakub Mikusek

unread,
Jan 18, 2016, 12:24:29 PM1/18/16
to salt-...@googlegroups.com
On 18 January 2016 at 17:03, Kai <kait...@gmail.com> wrote:

> thanks, but that gives me: {'/dev/sdb': {'TYPE': 'xfs', 'UUID':
> '882ea96e-0a5e-4720-9b04-cb765206ee98'}}
> I only need the UUID.

Try adding [0]['UUDI'] or ['UUID'] at the end of the command i gave you earlier.

Kai Timmer

unread,
Jan 19, 2016, 5:05:18 AM1/19/16
to salt-...@googlegroups.com
Jakub Mikusek <ja...@mikusek.org> schrieb am Mo., 18. Jan. 2016 um 18:24 Uhr:

Try adding [0]['UUDI'] or ['UUID'] at the end of the command i gave you earlier.

If I do that, I get:
 Rendering SLS 'base:mystate' failed: Jinja variable dict object has no element 0

This is in my statefile:
{% set dev_data_uuid = salt['disk.blkid'](dev_data) [0]['UUID'] %}

or:

Rendering SLS 'base:mysql.mystate' failed: Jinja variable 'dict object' has no attribute 'UUID'

With this in my statefile:
{% set dev_data_uuid = salt['disk.blkid'](dev_data) ['UUID'] %}

Thank you for your help!

Jakub Mikusek

unread,
Jan 19, 2016, 6:17:15 AM1/19/16
to salt-...@googlegroups.com
Morning Kai,

> If I do that, I get:
> Rendering SLS 'base:mystate' failed: Jinja variable dict object has no
> element 0
>
> This is in my statefile:
> {% set dev_data_uuid = salt['disk.blkid'](dev_data) [0]['UUID'] %}

This below works fine for me - blkid wasn't available on my system but
the following example should
shed some light on how to approach your issue.

{% set dev_data = "/" %}
{% set dev_data_percent = salt['disk.inodeusage']('') %}

/tmp/donkeyballs:
file.append:
- text: |
{{dev_data_percent[dev_data]['free']}}


Give me a shout if you still having problems.
Also check out http://jinja.pocoo.org/docs/dev/templates/#variables

Cheers,
J.
Reply all
Reply to author
Forward
0 new messages