The pdk new command

The command pdk new module brings the user to a prompt, requesting that the user specify the Puppet Forge username, the author's full name, the module license, and the supported operating systems. If you do not have a Forge username or a module license, you can enter in any value. After the prompt, you'll find a new directory that contains code. If you want to send this code to an upstream repository, follow these steps on the command line:

# From directory pdk new module was run in, enter the module, create a
# git repository and add all files to staging
$ cd module
$ git init
$ git add .

# Initial Commit is a good common message as a starting point
$ git commit -m 'Initial Commit'

# Add the upstream remote
$ git remote add origin [email protected]:puppet/module.git

# Push to master and begin regular module development workflow
$ git push origin master

If you're working with a previously created module, you can use the pdk convert command to place any items missing from the template into the existing module. By default, the PDK deploys the templates found at https://github.com/puppetlabs/pdk-templates. If you need to change any of the files found here, you can clone a copy of pdk-templates from the official repository and send it to a central Git repository. You'll need to use the pdk convert --template-url <https>  to select the new template and deploy it to the existing module. The --template-url flag  command will also set the new URL as the default URL on the workstation.

You should feel free to make your own copy of this template, as the one provided by Puppet is fairly extensive and rather opinionated. It even includes some ways to get started with CI/CD systems, such as gitlab-ci. Trim the files for systems that you don't use, and make sure that everything provided by the template makes sense for your organization.

The template repository provides three directories and configuration files to the PDK, as follows:

  • moduleroot: The Ruby templates in this directory will be placed on top of existing files. This is useful when you want to enforce a particular file, like a CI/CD pipeline.
  • moduleroot_init: The Ruby templates in this directory will not override existing files. This is great for starter files, like module templates.
  • object_templates: The Ruby templates that determine the output of the file on commands like pdk new class.
  • config_defaults.yaml: This provides defaults and variables to be used for all Ruby templates in the PDK template.

Once you have your new module template, you can begin to create manifests inside of the module for Puppet code with the PDK. From inside of the new module, we can use pdk new class to begin making manifests. The command creates manifests according to an autoload layout, so running pdk new class server::main would create a file at manifests/server/main.pp. The class created with the default template will start as an empty, non-parameterized class, with Puppet string-style documentation at the top of the file. The pdk new defined_type  command will make a similar file, but will use the defined declaration instead of the class declaration:

$ pdk new class config
pdk (INFO): Creating '/Users/rary/workspace/packt/module/manifests/config.pp' from template.
pdk (INFO): Creating '/Users/rary/workspace/packt/module/spec/classes/config_spec.rb' from template

# Sample with folders
$ pdk new class server::main
pdk (INFO): Creating '/Users/rary/workspace/packt/module/manifests/server/main.pp' from template.
pdk (INFO): Creating '/Users/rary/workspace/packt/module/spec/classes/server/main_spec.rb' from template.

The pdk new task command will create files in the tasks directory, based on the template for use with Puppet tasks. Puppet tasks are a way to automate ad hoc scripts and commands across your infrastructure, using Puppet. pdk new provider is an experimental feature for designing new custom Ruby providers to Puppet. 

Once the new objects are created and developed against, the PDK will also provide a tool suite for syntax and style, with pdk validate.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.17.23.130