在单个文件中定义资源时如何在init.pp或node.pp中使用define资源

时间:2015-01-26 07:49:11

标签: class puppet

如何在其他* .pp中定义某些资源以及如何在init.pp中使用?

我写了一个模块来测试这样的定义:

vsftpd
├── files
│   ├── test
│   │   ├── 1.txt
│   │   ├── 2.txt
│   │   ├── 3.txt
│   │   └── 4.txt
│   └── vsftpd.conf
├── manifests
│   ├── file.pp
│   ├── init.pp
│   ├── test.pp
│   └── user.pp
└── templates

我定义了2个类和一个要测试的定义资源,没有任何定义资源,它运行良好,我也可以定义一个资源并在init.pp中使用它,如 vsftpd :: createfile

但如果我在另一个文件test.pp中定义vsftpd :: test     它只是无法运行,错误:     无法在node agent.jayma.com上找到agent.jayma.com的class :: vsftpd :: test     即使我首先包括:: vsftpd :: test,我搜索了很多,但什么都没找到

file.pp
------------------
class vsftpd::file{
  file{'test':
      ensure    => 'directory',
      path      => '/tmp/test/',
      source    => "puppet://puppet.jaymz.com/modules/vsftpd/test/",
      recurse   => true

  }

}
------------------------
user.pp
------------------------
class vsftpd::user{
  user{'ftp_jaymz':
     ensure     => present,
     uid        => '504',
     home       => '/home/ftp_jaymz',
     shell      => '/sbin/nologin',
     password   => '$1$svfAKdBu$c8MnfTtA.12Nny2131Vb/jhPTR3/',
     gid        => 'ftp',
  }
}
-----------------------------------
test.pp
-----------------------------------
define vsftpd::test ($name=$title,$content){
   file {'abc':
      path      => "/tmp/${name}_text.txt",
      content   => "this is a test ${content}"

   }

}
--------------------------------------
init.pp
-------------------------------------

 - class vsftpd {    package {'vsftpd':
        ensure     => installed,   }

      service {'vsftpd':
        ensure     =>running,
        subscribe  =>File["vsftpd.conf"],    }

      file {'vsftpd.conf':
         path      => '/etc/vsftpd/vsftpd.conf',
         require   => Package["vsftpd"],
         source    => "puppet://broker.jaymz.com/modules/vsftpd/vsftpd.conf"
   }    include ::vsftpd::user   
   include ::vsftpd::file

      define
   vsftpd::createfile($name1=$title,$content1){
         file{"/tmp/$name1.txt":
             ensure => file,
             content => $content1,
             mode    => 0644,

         }


      }    vsftpd::createfile{'nick':
              content1     => "hi nick",    }

      vsftpd::createfile{'jaymz':
              content1     => "hi jaymz",    }

      include ::vsftpd::test   
   ::vsftd::test{'jaymz_test':
              content      =>"hi jaymz_test",    }

   }

----------------------------------------------------

1 个答案:

答案 0 :(得分:0)

您需要从哪个文件来源? 1.txt,2.txt还是其他?如果您需要来自1.txt的源代码,则应进行更改

来自

source    => "puppet://puppet.jaymz.com/modules/vsftpd/test/",

source    => "puppet://puppet.jaymz.com/modules/vsftpd/test/1.txt",