How to include modules from a different directory in puppet

。_饼干妹妹 提交于 2020-01-05 06:52:06

问题


My module tree is like this

   - modules
     - socle1
       - stdlib
     - socle2
       - ntp

How do I include the stdlib module in my site.pp?

I have tried include socle1::stdlib and it is not working .

Should I modify the environment.conf for the directory environment?


回答1:


If you want to arrange your modules in separate trees, then you may do so. You should then include each base path in your environment's modulepath, and refer to the modules by their regular names. Note in particular that altering the path to a module does not change its name or the names of any of the classes or types it defines -- the path influences only whether the autoloader can find them.

I strongly advise against making subdirectories of the standard module directory, however. Instead, if you want to group modules in multiple directories then create parallel module directories for that purpose:

- modules
- socle1
  - stdlib
- socle2
  - ntp

Should I modify the environment.conf for the directory environment?

In order to support any module directories beyond or instead of the default, yes, you should. The puppet documentation describes how to configure your environment's modulepath. But do consider following @MattSchuchard's advice and instead restricting yourself to the standard module directories.




回答2:


You are not supposed to put modules inside of other modules. Your tree should be like:

- modules
  - socle1
  - stdlib
  - socle2
  - ntp

Also, you would very rarely include stdlib, because stdlib is almost entirely a type/function module, so you would only reference its types and functions. You would not be declaring its classes unless you were planning on using the stages functionality it provides (thanks to John Bollinger for corrections to this paragraph).

However, declaring the ntp module in your site.pp is as simple as:

include ntp

or:

class { 'ntp': }

inside of your node { }.




回答3:


In your init.pp

class classname ( parameters ) { include ::socle2::ntp }

Try this and tell me if this works or not!



来源:https://stackoverflow.com/questions/39202383/how-to-include-modules-from-a-different-directory-in-puppet

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!