Ask Your Question
0

Using variable does not work in some circonstance in a manifest

asked 2016-12-19 03:54:35 -0600

MoBO gravatar image

updated 2016-12-19 12:11:05 -0600

Hello all,

I do face a strange problem using an auto-generated variable data. If the variable is define literally, it work fine. Hope someone can explain me why this is not working.

On the second part (working one), I added * to show the differences.

Non Working Manifest :

    # Note : $myprogram_version is retrieved from a facter

class myprogram {

  # Define path of the latest myprogram installation file
  # Maybe this ca be change to provide puppet:/// URL but not sure....
  $myprogram_path  = "/etc/puppetlabs/code/environments/production/modules/plex/files"

  # Retrieve version on the share folder
  #
  # Get version from the dowloaded installation file
  $myprogram_version_latest  = generate ("/bin/bash", "-c", "ls $myprogram_path/myprogram_* | awk -F'[_]' '{print \$2}' | cut -d- -f1")
  # Get the istallation file full URL (including name
  $myprogram_source          = generate ("/bin/bash", "-c", "ls $myprogram_path/myprogram_*")
  # Get only the basename using stdlib
  $myprogram_filename        = basename($myprogram_source)

  # Check if a newer version is existing
  if versioncmp($myprogram_version_latest, $myprogram_version) > 0 {
    # New Version is Available - Check Sessions
    if Integer($myprogram_session) == 0 {
      # No myprogram Session Running
      # The update code goes below this note
      file { "myprogram_installation_file":
        path   => "/tmp/$myprogram_filename",
        ensure => file,
        mode   => '0777',
        source => "puppet:///modules/plex/$myprogram_filename",
      }

      package { "myprogram_installation_process":
        ensure    =>  installed,
        provider  =>  dpkg,
        source    =>  "/tmp/$myprogram_filename",
        subscribe   => File['myprogram_installation_file'],
      }
      # End of the update code
    } else {
      notify { "Update available but session is running - ABORT": }
    }
  } else {
    # No update, closing
    #notify { "No update available : Current = $myprogram_version : New = $myprogram_latest": }
  }
}

Now, the working version :

# Note : $myprogram_version is retrieved from a facter

class myprogram {

  # Define path of the latest myprogram installation file
  # Maybe this ca be change to provide puppet:/// URL but not sure....
  $myprogram_path  = "/etc/puppetlabs/code/environments/production/modules/plex/files"
  # Fill the installation filename directly
  # ******************************************************
  $install_file          = 'myprogram_1.3.3_amd64.deb'
  # ******************************************************

  # Retrieve version on the share folder
  #
  # Get version from the dowloaded installation file
  $myprogram_version_latest  = generate ("/bin/bash", "-c", "ls $myprogram_path/myprogram_* | awk -F'[_]' '{print \$2}' | cut -d- -f1")
  #  Get only the basename using stdlib
  $myprogram_filename        = basename($myprogram_source)

  # Check if a newer version is existing
  if versioncmp($myprogram_version_latest, $myprogram_version) > 0 {
    # New Version is Available - Check Sessions
    if Integer($myprogram_session) == 0 {
      # No myprogram Session Running
      # The update code goes below this note
      file { "myprogram_installation_file":
        path   => "/tmp/$myprogram_filename",
        ensure => file,
        mode   => '0777',
        # This is the change
        # *****************************************************
        source => "puppet:///modules/plex/$install_file",
        # *****************************************************
      }

      package { "myprogram_installation_process":
        ensure    =>  installed,
        provider  =>  dpkg,
        source    =>  "/tmp/$myprogram_filename",
        subscribe   => File['myprogram_installation_file'],
      }
      # End of the update code
    } else {
      notify { "Update available but session is running - ABORT": }
    }
  } else {
    # No update, closing
    #notify { "No update available : Current = $myprogram_version : New = $myprogram_latest": }
  }
}

Thanks in advance for any advice !

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
0

answered 2016-12-19 11:43:25 -0600

lupin gravatar image
$myprogram_filename        = basename($myprogram_source)

Did that get the value correctly? Did the statement inside the if clause get executed?

if versioncmp($myprogram_version_latest, $myprogram_version) > 0 {
edit flag offensive delete link more
0

answered 2016-12-19 12:24:46 -0600

MoBO gravatar image

Indeed, I made a mistake (correct) on the "non working" section because I removed an important line :

# Get the istallation file full URL (including name
      $myprogram_source          = generate ("/bin/bash", "-c", "ls $myprogram_path/myprogram_*")

And to answer your second question : yes, everything works as expected except the puppet:\\\ source. By the way, this part is the same on both version.

edit flag offensive delete link more

Comments

So you're saying that the only difference between working and non-working is the `source` parameter value? On non working value enclose the variable to ${variable_name}. ie, "puppet:///modules/plex/${myprogram_filename}"

lupin gravatar imagelupin ( 2016-12-19 13:23:14 -0600 )edit

This is so weird to me and I'm unable to figure out. If I define the variable literally within the manifest, it work. If I use the "generate" , it fail (result is a string) I didn't tried with the brackets before the variable name -> ${myvar} I used the "notify" to check all steps & content of vars

MoBO gravatar imageMoBO ( 2016-12-20 00:51:25 -0600 )edit

I will have to wait the next update to check once again. This will take couple of days. I can share all the files if you like to test, it's a self installation but I cannot remove it since it's in a productive status.

MoBO gravatar imageMoBO ( 2016-12-20 04:11:44 -0600 )edit

functions, such as generate() are executed on the Puppet master only, that means the files/etc being reference by the function should be on master else you get unexpected result.

lupin gravatar imagelupin ( 2016-12-20 12:33:31 -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: 2016-12-19 03:54:35 -0600

Seen: 20 times

Last updated: Dec 19 '16