Jira (PUP-10846) Add a subdirectory constructor for modules

13 views
Skip to first unread message

WHK (Jira)

unread,
Jan 2, 2021, 3:49:03 PM1/2/21
to puppe...@googlegroups.com
WHK created an issue
 
Puppet / New Feature PUP-10846
Add a subdirectory constructor for modules
Issue Type: New Feature New Feature
Assignee: Unassigned
Components: Language
Created: 2021/01/02 12:47 PM
Priority: Normal Normal
Reporter: WHK

By example, i have a custom module, by example "thecompany" and have multiple submodules like as helpers for apache:

 

.
└── develrox
    └── manifests
        ├── httpd
        │   └── vhost.pp
        ├── httpd.pp
        └── init.pp

 

Now, call from node like as:

 

# Install basic requirements
{ thecompany : }
 
# Install apache server with custom settings
{ thecompany::httpd : }
 
# Made a new vhost with custom modsecurity rules
{ thecompany::httpd::vhost :
    foo  => bar
}

 

The httpd module have a custom base settings and vhost have a custom settings for all vhosts, files for mod security, etc.

The problem is: have a httpd.pp file out of https subfolder, when have multiple submodules is hard manage, have multiple files and multiple folders with same name for other functions.

The idea: implement a constructor file for each subdirectory module, by example:

.
└── thecompany
    └── manifests
        ├── httpd
        │   ├── init.pp
        │   └── vhost.pp
        └── init.pp

In thecompany/manifests/httpd/init.pp create the constructor class like as

class thecompany::httpd { ... }

 

 

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v8.5.2#805002-sha1:a66f935)
Atlassian logo

Josh Cooper (Jira)

unread,
Jan 8, 2021, 4:37:03 PM1/8/21
to puppe...@googlegroups.com
Josh Cooper commented on New Feature PUP-10846
 
Re: Add a subdirectory constructor for modules

Hi WHK sorry but I'm having trouble following what the problem is that you're trying to solve?

WHK (Jira)

unread,
Jan 8, 2021, 4:54:02 PM1/8/21
to puppe...@googlegroups.com
WHK commented on New Feature PUP-10846

Avoid creating separate files from the directory of each submodule. It is a matter of order. Puppet works via configuration in code and it is not normal or intuitive that in a code you should declare a class outside the directory of the component or package. In all existing programming languages there is a package or component index but puppet does not have one and it is also not possible to create a constructor within the same directory due to file name conflicts. It should by default take the name of the main class of the subdirectory when the file name is an index type name such as "init.pp".

Henrik Lindberg (Jira)

unread,
Jan 10, 2021, 10:04:03 AM1/10/21
to puppe...@googlegroups.com

If you have a module foo, with a name space zoo having classes lion and tiger you can organize them like this:

.
└── foo
    └── manifests
        ├── zoo
        │   ├── lion.pp
        │   └── tiger.pp
        ├── init.pp
        └── zoo.pp

And your foo::zoo::lion and foo::zoo::tiger classes should both use include foo::zoo. The only thing you are not getting is the "magic" processing of the init.pp which is done only at the module level.

What is it you cannot do with this?

WHK (Jira)

unread,
Jan 14, 2021, 4:49:04 PM1/14/21
to puppe...@googlegroups.com
WHK commented on New Feature PUP-10846

With the constructor idea:

foo
├── bar
│   └── init.pp
├── init.pp
└── zoo
    ├── cat
    │   ├── access.pp
    │   ├── food.pp
    │   ├── init.pp
    │   └── security.pp
    ├── catdog
    │   ├── access.pp
    │   ├── food.pp
    │   ├── init.pp
    │   └── security.pp
    ├── dog
    │   ├── access.pp
    │   ├── food.pp
    │   ├── init.pp
    │   └── security.pp
    ├── fish
    │   ├── access.pp
    │   ├── food.pp
    │   ├── init.pp
    │   └── security.pp
    ├── init.pp
    ├── lion
    │   ├── access.pp
    │   ├── food.pp
    │   ├── init.pp
    │   └── security.pp
    ├── monkey
    │   ├── access.pp
    │   ├── food.pp
    │   ├── init.pp
    │   └── security.pp
    ├── phanter
    │   ├── access.pp
    │   ├── food.pp
    │   ├── init.pp
    │   └── security.pp
    └── tiger
        ├── access.pp
        ├── food.pp
        ├── init.pp
        └── security.pp

With the native puppet structure:

foo
├── bar.pp
├── init.pp
├── zoo
│   ├── cat
│   │   ├── access.pp
│   │   ├── food.pp
│   │   └── security.pp
│   ├── catdog
│   │   ├── access.pp
│   │   ├── food.pp
│   │   └── security.pp
│   ├── catdog.pp
│   ├── cat.pp
│   ├── dog
│   │   ├── access.pp
│   │   ├── food.pp
│   │   └── security.pp
│   ├── dog.pp
│   ├── fish
│   │   ├── access.pp
│   │   ├── food.pp
│   │   └── security.pp
│   ├── fish.pp
│   ├── lion
│   │   ├── access.pp
│   │   ├── food.pp
│   │   └── security.pp
│   ├── lion.pp
│   ├── monkey
│   │   ├── access.pp
│   │   ├── food.pp
│   │   └── security.pp
│   ├── phanter
│   │   ├── access.pp
│   │   ├── food.pp
│   │   └── security.pp
│   ├── phanter.pp
│   ├── tiger
│   │   ├── access.pp
│   │   ├── food.pp
│   │   └── security.pp
│   └── tiger.pp
└── zoo.pp

When you have many submodules you notice the difference, the native structure looks very messy, you must necessarily search for the same submodule in multiple directories instead of using just one. The idea is that if you need to create a submodule you create a directory and there you should write all the class logic, if you need to delete it you simply delete the directory, but with the current structure you must have loose files outside the directory of each submodule.

 

Josh Cooper (Jira)

unread,
Sep 14, 2021, 1:18:03 AM9/14/21
to puppe...@googlegroups.com
Josh Cooper commented on New Feature PUP-10846

Ah ok, so you're saying the problem now is you have to create a file cat.pp and directory cat at the same level:

foo
├── zoo
│   ├── cat
│   │   ├── access.pp
│   │   ├── food.pp
│   │   └── security.pp
│   ├── cat.pp

And it would be cleaner if the cat.pp file was replaced with {init.pp}} inside of the cat directory. That way the module is self-contained within the directory and could easily be deleted. And it avoids the messy output where cat and catdog files are interleaved do to the default way tree lists directories followed by files:

zoo
├── cat
├── catdog
├── catdog.pp
└── cat.pp

That all makes sense, but I think it's unlikely we'd implement that given other priorities.

This message was sent by Atlassian Jira (v8.13.2#813002-sha1:c495a97)
Atlassian logo

Ciprian Badescu (Jira)

unread,
Oct 1, 2021, 9:17:02 AM10/1/21
to puppe...@googlegroups.com

Thank you for filing this issue. We agree it is likely an improvement, but due to other issues demanding precedence, we don’t anticipate being able to address this any time soon. As such we are closing this as “Won’t Fix.” We may revisit it at a later time, and if so will re-open this ticket.

Reply all
Reply to author
Forward
0 new messages