Ask Your Question
1

Howto retrieve deep structured facter fact?

asked 2015-05-19 07:34:56 -0500

far4d gravatar image

Given the following output from facter partitions -y

partitions:
  sda1:
    uuid: 93ee8fa2-8423-49d5-a8fe-49c79f912b29
    size: '1024000'
    mount: /boot
    filesystem: ext4
  sda2:
    size: '124803072'
    filesystem: LVM2_member

How do I get all elements of type size?

This works as expected: puppet apply -e 'notify { "${partitions['sda1']['size']}": }' and returns 1024000. But I would like to do something like:

puppet apply -e 'notify { "${partitions['*']['size']}": }'

to get all sizes of all partitions. Since size is a property of the partition, it seems unaccessible if I don't know the name of the partition. I have to make a decision based on the value of size. Is there a way to do it?

edit retag flag offensive close merge delete

Comments

If anyone else is having trouble returning values from a hash in Facter, make sure you have stringify_facts set to false. (https://docs.puppetlabs.com/facter/3.1/fact_overview.html#writing-structured-facts)

Aaron Copley gravatar imageAaron Copley ( 2015-12-17 18:40:38 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2015-05-19 18:37:55 -0500

GregLarkin gravatar image

You will have to use the future parser to do this, but you can iterate through the structured fact like so and extract the size attribute for each partition:

$::partitions.each | $name, $partinfo | {
  $partsize = $::partitions[$name]['size']

  notify { "Partition $name size: $partsize": }
}

You can use the $partsize value to feed into an if statement or whatever you are using to make a decision in your code.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

2 followers

Stats

Asked: 2015-05-19 07:34:56 -0500

Seen: 563 times

Last updated: May 19 '15