Ask Your Question
0

how to use before keyword, if I want to run a part of code before running a method [closed]

asked 2014-04-16 09:10:31 -0600

Sajauddin gravatar image

updated 2014-04-16 10:35:39 -0600

ffrank gravatar image

In /etc/puppet/modules/abc/manifests/init.pp

file {"/etc/abc.txt":
  source => 'puppet:///abc.txt',
  owner  => 'root',
  group  => 'root',
  mode   => 0644,
  before  => Foo::Myfoo::Foo_a{"Hello"},
}

In /etc/puppet/modules/foo/manifests/fooa/fooa.pp

define foo::myfoo::foo_a ($string)
{ ...
}

I have written my code so that whenever foo_a is called, before running that method, file[/etc/abc.txt] should be called. I want to use before keyword for this. I am getting below error.

Error: Could not call 'find' on 'catalog': Invalid relationship: File[vm] { before  => Foo::Myfoo::Foo_a }, because before  => Foo::Myfoo::Foo_a doesn't ...
(more)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Sajauddin
close date 2014-04-17 05:26:38.071183

2 Answers

Sort by ยป oldest newest most voted
1

answered 2014-04-16 10:03:07 -0600

Try use [] instead {} when pass parameters.

Try this above.

 file {"/etc/abc.txt":
   ensure => present,
   source => 'puppet:///abc.txt',
   owner => root,
   group => root,
   mode => '0644',
   before => Foo::Myfoo::Foo_a["Hello"],
 }
edit flag offensive delete link more

Comments

changed as per your suggestion... Please check below error and suggest what can be done.

Sajauddin gravatar imageSajauddin ( 2014-04-17 02:05:47 -0600 )edit

That is a separate issue. Please open a new question for that. Since the immediate issue was resolved, please consider accepting Renan's answer as correct.

ffrank gravatar imageffrank ( 2014-04-17 05:02:56 -0600 )edit
0

answered 2014-04-17 01:59:59 -0600

Sajauddin gravatar image

Below is the exact folder structure and code I am using.

Folder structure and files:

root@build-server:/etc/puppet/modules/testabc# ls -lR *
manifests:
total 8
drwxr-xr-x 2 root root 4096 Apr 17 12:07 foox
-rw-r--r-- 1 root root  286 Apr 17 12:10 init.pp

manifests/foox:
total 4
-rw-r--r-- 1 root root 79 Apr 17 11:25 fooa.pp

Puppet Code:

root@build-server:/etc/puppet/modules/testabc#cat manifests/init.pp

    include testabc::foox

    file {"/tmp/abc.txt":
      source => 'puppet:///packages/abc.txt',
      owner  => 'root',
      group  => 'root',
      mode   => 0644,
      before  => Testabc::Foox::Fooa[$string],
    }

    class testabc {
      testabc ...
(more)
edit flag offensive delete link more

Question Tools

Stats

Asked: 2014-04-16 09:10:31 -0600

Seen: 65 times

Last updated: Apr 17 '14