Unable to find a valid module template to use.
Describe the bug
I get the following error when I run pdk new module --skip-interview foo /Users/<user>/Workspace/puppet/foo/foo:
pdk (INFO): Creating new module: foo
pdk (FATAL): Unable to find a valid module template to use.
I installed the VS Code extension and trying to create a new module using VS Code. Of course, the same command doesn't work from cli. Installed pdk using brew on MacOS.
To Reproduce
Install pdk, pdk new module --skip-interview foo /Users/<user>/Workspace/puppet/foo/foo
Expected behavior Should create a module
Additional context
- Your PDK installation method (native packages or via Rubygems): brew
- (If via Rubygems, please include your Ruby version
ruby -v)
- (If via Rubygems, please include your Ruby version
- Your PDK version (
pdk --version): 3.4.0 - Your operating system / platform: MacOS
Can someone help with this please?
Running with debug shows:
pdk (DEBUG): STDERR:
fatal: detected dubious ownership in repository at '/opt/puppetlabs/pdk/share/cache/pdk-templates.git'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/puppetlabs/pdk/share/cache/pdk-templates.git
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
FWIW, this is affecting me too. And I get the same output running with -d.
A temporary workaround is to add the --template-url and --template-ref flags, pointing to the canonical puppetlabs/pdk-templates repo, when creating a new module.
For example:
pdk new module foo --template-url=https://github.com/puppetlabs/pdk-templates --template-ref=main
FWIW: I was able to use the workaround successfully on a Windows 11 workstation, but NOT on a Ubuntu 24.04 instance (same workstation under WSL, both updated to 3.4.0)...
I tried with both ref options:
--template-url=https://github.com/puppetlabs/pdk-templates --template-ref=main
--template-url=https://github.com/puppetlabs/pdk-templates --template-ref=3.4.0
per the workaround in the current known issues on the release notes page.
Not sure what the difference would be, and didn't really take the time to troubleshoot further. Worked fine with previous versions of the PDK in both cases.
I'm always willing to assist in providing more relevant details / helping to troubleshoot this if needed on request.
EDIT: Perhaps we're looking at a certificate issue as well ... which i thought was taken care of with the update to 3.4.0? And also confirming what was shown above for the git directory traversal problem:
#pdk new module --skip-interview testmodule --debug
pdk (INFO): Creating new module: testmodule
pdk (DEBUG): Using '/opt/puppetlabs/pdk/private/git/bin/git' from PDK package.
pdk (DEBUG): Using '/opt/puppetlabs/pdk/private/git/bin/git' from PDK package.
pdk (DEBUG): Executing '/opt/puppetlabs/pdk/private/git/bin/git ls-remote --exit-code https://github.com/puppetlabs/pdk-templates'
pdk (DEBUG): Execution of '/opt/puppetlabs/pdk/private/git/bin/git ls-remote --exit-code https://github.com/puppetlabs/pdk-templates' complete (duration: 0.123733103s; exit code: 128)
pdk (DEBUG): STDOUT: N/A
pdk (DEBUG): STDERR:
fatal: unable to access 'https://github.com/puppetlabs/pdk-templates/': SSL certificate problem: unable to get local issuer certificate
pdk (DEBUG): Using '/opt/puppetlabs/pdk/private/git/bin/git' from PDK package.
pdk (DEBUG): Using '/opt/puppetlabs/pdk/private/git/bin/git' from PDK package.
pdk (DEBUG): Executing '/opt/puppetlabs/pdk/private/git/bin/git ls-remote --exit-code file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git'
pdk (DEBUG): Execution of '/opt/puppetlabs/pdk/private/git/bin/git ls-remote --exit-code file:///opt/puppetlabs/pdk/share/cache/pdk-templates.git' complete (duration: 0.019740061s; exit code: 128)
pdk (DEBUG): STDOUT: N/A
pdk (DEBUG): STDERR:
fatal: detected dubious ownership in repository at '/opt/puppetlabs/pdk/share/cache/pdk-templates.git'
To add an exception for this directory, call:
git config --global --add safe.directory /opt/puppetlabs/pdk/share/cache/pdk-templates.git
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
pdk (FATAL): Unable to find a valid module template to use.
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/pdk-3.4.0/lib/pdk/util/template_uri.rb:249:in `first_valid_uri'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/pdk-3.4.0/lib/pdk/util/template_uri.rb:57:in `initialize'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/pdk-3.4.0/lib/pdk/generate/module.rb:43:in `new'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/pdk-3.4.0/lib/pdk/generate/module.rb:43:in `invoke'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/pdk-3.4.0/lib/pdk/cli/new/module.rb:48:in `block (2 levels) in <module:CLI>'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/cri-2.15.12/lib/cri/command.rb:362:in `run_this'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/cri-2.15.12/lib/cri/command.rb:298:in `run'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/cri-2.15.12/lib/cri/command.rb:316:in `run'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/cri-2.15.12/lib/cri/command.rb:316:in `run'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/pdk-3.4.0/lib/pdk/cli.rb:58:in `run'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/lib/ruby/gems/3.2.0/gems/pdk-3.4.0/exe/pdk:6:in `<top (required)>'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/bin/pdk:25:in `load'
pdk (DEBUG): /opt/puppetlabs/pdk/private/ruby/3.2.5/bin/pdk:25:in `<main>'
Resolution:
Issue seems to be resolved (but maybe not properly from a security perspective) with:
git config --global --add safe.directory /opt/puppetlabs/pdk/share/cache/pdk-templates.git
as is pointed out in the debug.
Not sure if this is the proper thing to add to the installer/upgrade for PDK though, I'll leave that to others to determine.
Hey, this is a known issue for the PDK going forward and has been caused by permission changes in newer versions of git.
Alongside the above solution, if you are not comfortable setting a safe.directory, you can also circumvent it by using chown -R to set the ownership of the files to a local user, or the root if you wish:
sudo chown -R example.user /opt/puppetlabs/pdk/share/cache/pdk-templates.git
That last one seems to be solution for Linux, it matches also known issues on PDK page, however what would be solution for Windows? Chown is not the same there. Git doesn't seem to be required dependency. Even though I have git installed it doesn't seem to be able to configure it during installation process. Did a fresh PDK install on windows.
I think, ultimately, the "real" fix for this is to change the path PDK uses to download things from /opt/puppetlabs... to ~/.puppetlabs/, but that's beyond the scope of a quick change on the command line or changing the git config.