Skip to content

Commit

Permalink
gapi: Bring back puppet and langpuppet
Browse files Browse the repository at this point in the history
This reverts commit e767655.

In addition, it applies required changes to function with the new CLI backend.
  • Loading branch information
ffrank authored and purpleidea committed Apr 3, 2024
1 parent 22873b3 commit 29ec867
Show file tree
Hide file tree
Showing 17 changed files with 1,465 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ Please read, enjoy and help improve our documentation!
| [style guide](docs/style-guide.md) | for mgmt developers |
| [godoc API reference](https://godoc.org/github.com/purpleidea/mgmt) | for mgmt developers |
| [prometheus guide](docs/prometheus.md) | for everyone |
| [puppet guide](docs/puppet-guide.md) | for puppet sysadmins |
| [development](docs/development.md) | for mgmt developers |
| [videos](docs/on-the-web.md) | for everyone |
| [blogs](docs/on-the-web.md) | for everyone |
Expand Down
16 changes: 13 additions & 3 deletions cli/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ type DeployArgs struct {
NoGit bool `arg:"--no-git" help:"don't look at git commit id for safe deploys"`
Force bool `arg:"--force" help:"force a new deploy, even if the safety chain would break"`

DeployEmpty *cliUtil.EmptyArgs `arg:"subcommand:empty" help:"deploy empty payload"`
DeployLang *cliUtil.LangArgs `arg:"subcommand:lang" help:"deploy lang (mcl) payload"`
DeployYaml *cliUtil.YamlArgs `arg:"subcommand:yaml" help:"deploy yaml graph payload"`
DeployEmpty *cliUtil.EmptyArgs `arg:"subcommand:empty" help:"deploy empty payload"`
DeployLang *cliUtil.LangArgs `arg:"subcommand:lang" help:"deploy lang (mcl) payload"`
DeployYaml *cliUtil.YamlArgs `arg:"subcommand:yaml" help:"deploy yaml graph payload"`
DeployPuppet *cliUtil.PuppetArgs `arg:"subcommand:puppet" help:"deploy puppet graph payload"`
DeployLangPuppet *cliUtil.LangPuppetArgs `arg:"subcommand:langpuppet" help:"deploy langpuppet graph payload"`
}

// Run executes the correct subcommand. It errors if there's ever an error. It
Expand All @@ -87,6 +89,14 @@ func (obj *DeployArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error
name = cliUtil.LookupSubcommand(obj, cmd) // "yaml"
args = cmd
}
if cmd := obj.DeployPuppet; cmd != nil {
name = cliUtil.LookupSubcommand(obj, cmd) // "puppet"
args = cmd
}
if cmd := obj.DeployLangPuppet; cmd != nil {
name = cliUtil.LookupSubcommand(obj, cmd) // "langpuppet"
args = cmd
}

// XXX: workaround https://github.com/alexflint/go-arg/issues/239
gapiNames := gapi.Names() // list of registered names
Expand Down
16 changes: 13 additions & 3 deletions cli/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ import (
type RunArgs struct {
lib.Config // embedded config (can't be a pointer) https://github.com/alexflint/go-arg/issues/240

RunEmpty *cliUtil.EmptyArgs `arg:"subcommand:empty" help:"run empty payload"`
RunLang *cliUtil.LangArgs `arg:"subcommand:lang" help:"run lang (mcl) payload"`
RunYaml *cliUtil.YamlArgs `arg:"subcommand:yaml" help:"run yaml graph payload"`
RunEmpty *cliUtil.EmptyArgs `arg:"subcommand:empty" help:"run empty payload"`
RunLang *cliUtil.LangArgs `arg:"subcommand:lang" help:"run lang (mcl) payload"`
RunYaml *cliUtil.YamlArgs `arg:"subcommand:yaml" help:"run yaml graph payload"`
RunPuppet *cliUtil.PuppetArgs `arg:"subcommand:puppet" help:"run puppet graph payload"`
RunLangPuppet *cliUtil.LangPuppetArgs `arg:"subcommand:langpuppet" help:"run a combined lang/puppet graph payload"`
}

// Run executes the correct subcommand. It errors if there's ever an error. It
Expand All @@ -81,6 +83,14 @@ func (obj *RunArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error) {
name = cliUtil.LookupSubcommand(obj, cmd) // "yaml"
args = cmd
}
if cmd := obj.RunPuppet; cmd != nil {
name = cliUtil.LookupSubcommand(obj, cmd) // "puppet"
args = cmd
}
if cmd := obj.RunLangPuppet; cmd != nil {
name = cliUtil.LookupSubcommand(obj, cmd) // "langpuppet"
args = cmd
}

// XXX: workaround https://github.com/alexflint/go-arg/issues/239
lists := [][]string{
Expand Down
47 changes: 47 additions & 0 deletions cli/util/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,50 @@ type YamlArgs struct {
// Input is the input yaml code or file path or any input specification.
Input string `arg:"positional,required"`
}

// PuppetArgs is the puppet CLI parsing structure and type of the parsed result.
type PuppetArgs struct {
// Input is the input puppet code or file path or just "agent".
Input string `arg:"positional,required"`

// PuppetConf is the optional path to a puppet.conf config file.
PuppetConf string `arg:"--puppet-conf" help:"full path to the puppet.conf file to use"`
}

// LangPuppetArgs is the langpuppet CLI parsing structure and type of the parsed
// result.
type LangPuppetArgs struct {
// LangInput is the input mcl code or file path or any input specification.
LangInput string `arg:"--lang,required" help:"the input parameter for the lang module"`

// PuppetInput is the input puppet code or file path or just "agent".
PuppetInput string `arg:"--puppet,required" help:"the input parameter for the puppet module"`

// copy-pasted from PuppetArgs

// PuppetConf is the optional path to a puppet.conf config file.
PuppetConf string `arg:"--puppet-conf" help:"full path to the puppet.conf file to use"`

// end PuppetArgs

// copy-pasted from LangArgs

// TODO: removed (temporarily?)
//Stdin bool `arg:"--stdin" help:"use passthrough stdin"`

Download bool `arg:"--download" help:"download any missing imports"`
OnlyDownload bool `arg:"--only-download" help:"stop after downloading any missing imports"`
Update bool `arg:"--update" help:"update all dependencies to the latest versions"`

OnlyUnify bool `arg:"--only-unify" help:"stop after type unification"`
SkipUnify bool `arg:"--skip-unify" help:"skip type unification"`

Depth int `arg:"--depth" default:"-1" help:"max recursion depth limit (-1 is unlimited)"`

// The default of 0 means any error is a failure by default.
Retry int `arg:"--depth" help:"max number of retries (-1 is unlimited)"`

ModulePath string `arg:"--module-path,env:MGMT_MODULE_PATH" help:"choose the modules path (absolute)"`

// end LangArgs
}
29 changes: 28 additions & 1 deletion docs/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,33 @@ execute via a `remote` resource.
You can read the introductory blog post about this topic here:
[https://purpleidea.com/blog/2016/10/07/remote-execution-in-mgmt/](https://purpleidea.com/blog/2016/10/07/remote-execution-in-mgmt/)

### Puppet support

You can supply a puppet manifest instead of creating the (YAML) graph manually.
Puppet must be installed and in `mgmt`'s search path. You also need the
[ffrank-mgmtgraph puppet module](https://forge.puppet.com/ffrank/mgmtgraph).

Invoke `mgmt` with the `--puppet` switch, which supports 3 variants:

1. Request the configuration from the puppet server (like `puppet agent` does)

`mgmt run puppet --puppet agent`

2. Compile a local manifest file (like `puppet apply`)

`mgmt run puppet --puppet /path/to/my/manifest.pp`

3. Compile an ad hoc manifest from the commandline (like `puppet apply -e`)

`mgmt run puppet --puppet 'file { "/etc/ntp.conf": ensure => file }'`

For more details and caveats see [puppet-guide.md](puppet-guide.md).

#### Blog post

An introductory post on the puppet support is on
[Felix's blog](http://ffrank.github.io/features/2016/06/19/puppet-powered-mgmt/).

## Reference

Please note that there are a number of undocumented options. For more
Expand Down Expand Up @@ -335,7 +362,7 @@ size of 42, you can expect a semaphore if named: `:42`. It is expected that
consumers of the semaphore metaparameter always include a prefix to avoid a
collision with this globally defined semaphore. The size value must be greater
than zero at this time. The traditional non-parallel execution found in config
management tools such as `Puppet` can be obtained with `--sema 1`.
management tools such as `puppet` can be obtained with `--sema 1`.

#### `--ssh-priv-id-rsa`

Expand Down
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ Welcome to mgmt's documentation!
quick-start-guide
resource-guide
prometheus
puppet-guide

0 comments on commit 29ec867

Please sign in to comment.