Ask Your Question

Capture stdout of a external command into a puppet variable

asked 2015-01-29 18:50:30 -0500

jflorian gravatar image

Presently, I have the following puppet code:

$sterile_name = $real_mnt_where ? {
    '/'     => '-',
    default => regsubst(regsubst($real_mnt_where, '^/|/$', ''), '/', '-', 'G')

I need to transform this into the puppet equivalent of what I could do in a shell script:

sterile_name="$(systemd-escape --path --suffix=mount $real_mnt_where)"

How can I do that?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2015-01-30 11:54:43 -0500

lavaman gravatar image

If you need that information from a host running the puppet agent, the proper place to do that is via facter:

edit flag offensive delete link more

answered 2015-01-29 19:33:22 -0500

jflorian gravatar image

Looks like this would work, albeit it requires systemd-escape on the Puppet Master and this command is very new -- Fedora 21 has it, but not Fedora 20. Anyway in MODULE/lib/puppet/parser/functions/systemd_escape.rb:

require 'puppet/util/execution'

module Puppet::Parser::Functions
    newfunction(:systemd_escape, :type => :rvalue, :doc => <<-EOS
Returns a file system path as escaped by systemd.
    ) do |args|

        if (args.length != 1) then
            raise Puppet::ParseError, ("validate_cmd(): wrong number of arguments (#{args.length}; must be 1)")

        path = args[0]

        cmd = "systemd-escape --path --suffix=mount #{path}"
        escaped = Puppet::Util::Execution.execute(cmd)

        return escaped

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

1 follower


Asked: 2015-01-29 18:50:30 -0500

Seen: 184 times

Last updated: Jan 30 '15