Ask Your Question
0

How to condition set of rules on result of executing a command

asked 2014-02-01 04:36:04 -0600

Adam Ryczkowski gravatar image

updated 2014-02-01 14:54:33 -0600

doc75 gravatar image

I'd like to do some stuff, that involves copying files and running scripts, if a certain key in gsettings exists.

I can test for it with a command '/usr/bin/gsettings get org.cinnamon.muffin.keybindings move-to-workspace-down | grep Mod3'.

The "stuff" begins with copying a custom script configuring desktop manager to the client node, but to avoid that copying I'd like to first check if this is necessary.

Idealy I would start with

  file { '/tmp/fixmod3.sh':
    source    => "puppet:///modules/mod3/fixmod3.sh",
    mode      => 0777,
    onlyif => '/usr/bin/gsettings get org.cinnamon.muffin.keybindings move-to-workspace-down | grep Mod3' 
  }

but ... (more)

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2014-02-01 14:51:59 -0600

doc75 gravatar image

I would create my own fact to be true if setting exist and to false otherwise.

To create a new fact, just create a file in your module under: lib/facter/is_mod3.rb.

I would put the following content:

Facter.add(:is_mod3) do
  setcode do
    if `/usr/bin/gsettings get org.cinnamon.muffin.keybindings move-to-workspace-down` =~ /Mod3/
      true
    else
      false
    end
  end
end

Then in your manifest, you can use this new fact and do:

if $is_mod3 {
  file { '/tmp/fixmod3.sh':
    source    => "puppet:///modules/mod3/fixmod3.sh",
    mode      => 0777,
  }
}

Hope this helps.

edit flag offensive delete link more

Comments

Thank you! It works perfectly.

Adam Ryczkowski gravatar imageAdam Ryczkowski ( 2014-02-03 13:18:24 -0600 )edit

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

Stats

Asked: 2014-02-01 04:36:04 -0600

Seen: 147 times

Last updated: Feb 01 '14