Skip to content

Commit

Permalink
Initial tailored interface support
Browse files Browse the repository at this point in the history
  • Loading branch information
reidmv committed Jun 11, 2019
1 parent 214291f commit 37eedf1
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## Release 0.2.0

**Features**

Modifications to support tailored tasks that form custom task interfaces to specific plans.

## Release 0.1.2

**Bugfixes**
Expand Down
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,22 @@ bolt task run taskplan \
--nodes local://localhost \
--params '{"plan":"taskplan::test","params":{"message":"Hello"},"arguments":{"modulepath":"/example/modules"}}'
```

### Plan-specific tailored taskplan task

To create a plan-specific tailored taskplan task, use something like the following:

```ruby
#!/opt/puppetlabs/puppet/bin/ruby
require 'json'

$params = {
'params' => JSON.parse(STDIN.read),
'plan' => 'example::myplan',
'arguments' => [],
}

taskplanrb = File.join($params['params']['_installdir'], 'util', 'files', 'taskplan.rb')

load(taskplanrb)
```
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "reidmv-taskplan",
"version": "0.1.2",
"version": "0.2.0",
"author": "Reid Vandewiele",
"summary": "Run Puppet task plans, using Bolt, via a task",
"license": "Apache-2.0",
Expand Down
29 changes: 15 additions & 14 deletions tasks/init.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
#!/opt/puppetlabs/puppet/bin/ruby
# rubocop:disable Style/GlobalVars
require 'json'
require 'open3'
require 'etc'

# Parameters expected:
# Hash
# String plan
# Hash params
# Hash arguments
# Optional[Boolean] debug
$params = JSON.parse(STDIN.read)
$params ||= JSON.parse(STDIN.read)

# The HOME environment variable is important when invoking Bolt. If HOME is not
# already set, set it.
if ENV['HOME'].nil?
require 'etc'
ENV['HOME'] = Etc.getpwuid.dir
end
ENV['HOME'] ||= Etc.getpwuid.dir

# Bolt is expected on paths that may or may not be in the PATH variable. When
# invoking it, prefer the package, then the gem, then default to PATH.
Expand All @@ -28,20 +27,22 @@
end

def main
cmd = Array.new
cmd = []
cmd << $bolt << 'plan' << 'run'
cmd << $params['plan']
cmd << '--params' << $params['params'].to_json
cmd << '--format' << 'json'

$params['arguments'].each do |key,val|
case val
when true
cmd << "--#{key}"
when false
cmd << "--no-#{key}"
else
cmd << "--#{key}" << val
if $params['arguments']
$params['arguments'].each do |key, val|
case val
when true
cmd << "--#{key}"
when false
cmd << "--no-#{key}"
else
cmd << "--#{key}" << val
end
end
end

Expand Down

0 comments on commit 37eedf1

Please sign in to comment.