Ask Your Question
1

assign var after command has run?

asked 2013-05-15 11:53:59 -0600

rynop gravatar image

updated 2013-05-15 14:34:32 -0600

How do you set a var only after a command has run? I thought var assignment was parse order dependent, but its not acting that way in this simple example:

  #find out what version of the uber jar to use
  $theUberJarVersionFile = 'prod_ver.txt'
  my_common::s3cmd::get{ "/tmp/$theUberJarVersionFile":
    s3_object => "s3://mybucket/$theUberJarVersionFile",
    cwd => "/tmp",
    owner => 'deployer',
    before => $theUberJar
  }

  $theUberJar = file("/tmp/$theUberJarVersionFile")

  #download uber jar from S3
  my_common::s3cmd::get{ "/tmp/ws.jar":
    s3_object => "s3://mybucket/$theUberJar",
    cwd => "/tmp",
    owner => 'deploy',
    ensure => $theUberJar,
    require => My_common::S3cmd::Get["/tmp/$theUberJarVersionFile"],
  }

All I'm trying to do is get a remote resource ... (more)

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
3

answered 2013-05-15 14:17:21 -0600

lavaman gravatar image

Variable assignment is parse-order dependent, but the application of resources is not.

So while the definition of your get is parsed before you attempt to assign $theUberJar, there is no way to guarantee that resource is applied before you try to assign that variable. Catalog compilation and application are completely separate steps in a puppet run. This means that all variables are assigned before any resource is applied to the system.

If you need information from the system to use in your manifests, you need to use either a custom fact or a function (only if you are running masterless ... (more)

edit flag offensive delete link more

Comments

Thx for the explanation. That is unfortunate (from a productivity perspective), but I now understand. I ended up doing a chain of bash commands inside a single exec that accomplished ...(more)

rynop gravatar imagerynop ( 2013-05-15 14:27:52 -0600 )edit
0

answered 2013-05-15 13:57:01 -0600

Try that instead to fetch the version :

 $theUberJar = generate("/bin/cat", "/tmp/$theUberJarVersionFile")
edit flag offensive delete link more

Comments

Nope this does not work. See ans from @lavaman

rynop gravatar imagerynop ( 2013-05-15 14:31:00 -0600 )edit

Right my bad, generate is run on the master. Since you go with a single exec, if it's acceptable to get your credentials on the puppet master you can ...(more)

Julien R. gravatar imageJulien R. ( 2013-05-16 14:04:27 -0600 )edit

And reuse the second my_common::s3cmd::get :

  my_common::s3cmd::get{ "/tmp/ws.jar":
     s3_object => "s3://mybucket/$theUberJar",
     cwd => "/tmp",
     owner => 'deploy',
     ensure => $theUberJar,
  }
Julien R. gravatar imageJulien R. ( 2013-05-16 14:12:02 -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

Stats

Asked: 2013-05-15 11:53:59 -0600

Seen: 969 times

Last updated: May 15 '13