Skip to content

feat: add puppetcore agent installation support #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Install Litmus as a gem by running `gem install puppet_litmus`.

- Note if you choose to override the `litmus_inventory.yaml` location, please ensure that the directory structure you define exists.

## Install a specific puppet agent version
## Agent installs

### Install a specific puppet agent version

To install a specific version of the puppet agent, you can export the `PUPPET_VERSION` env var, like below:
```
Expand All @@ -38,6 +40,13 @@ export PUPPET_VERSION=8.8.1

When set, the `litmus:install_agent` rake task will install the specified version. The default is `latest`.

## Installing puppetcore agents

To install a puppetcore puppet agent through the `litmus:install_agent` rake task, you need to export your Forge API key as an env var, like below:
```
export PUPPET_FORGE_TOKEN='<your_forge_api_key>'
```

## matrix_from_metadata_v3

matrix_from_metadata_v3 tool generates a github action matrix from the supported operating systems listed in the module's metadata.json.
Expand Down
7 changes: 6 additions & 1 deletion lib/puppet_litmus/rake_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
require 'puppet_litmus/version'

# helper methods for the litmus rake tasks
module PuppetLitmus::RakeHelper
module PuppetLitmus::RakeHelper # rubocop:disable Metrics/ModuleLength
# DEFAULT_CONFIG_DATA should be frozen for our safety, but it needs to work around https://github.com/puppetlabs/bolt/pull/1696
DEFAULT_CONFIG_DATA = { 'modulepath' => File.join(Dir.pwd, 'spec', 'fixtures', 'modules') } # .freeze # rubocop:disable Style/MutableConstant
SUPPORTED_PROVISIONERS = %w[abs docker docker_exp lxd provision_service vagrant vmpooler].freeze
Expand Down Expand Up @@ -130,13 +130,18 @@ def tear_down(node_name, inventory_hash)
def install_agent(collection, targets, inventory_hash)
include ::BoltSpec::Run
puppet_version = ENV.fetch('PUPPET_VERSION', nil)
forge_token = ENV.fetch('PUPPET_FORGE_TOKEN', nil)
params = {}
params['password'] = forge_token if forge_token
params['collection'] = collection if collection
params['version'] = puppet_version if puppet_version

raise "puppet_agent was not found in #{DEFAULT_CONFIG_DATA['modulepath']}, please amend the .fixtures.yml file" \
unless File.directory?(File.join(DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent'))

raise 'puppetcore agent installs require a valid PUPPET_FORGE_TOKEN set in the env.' \
if collection =~ /\Apuppetcore.*/ && !forge_token

# using boltspec, when the runner is called it changes the inventory_hash dropping the version field. The clone works around this
bolt_result = run_task('puppet_agent::install', targets, params, config: DEFAULT_CONFIG_DATA, inventory: inventory_hash.clone)
targets.each do |target|
Expand Down
23 changes: 22 additions & 1 deletion spec/lib/puppet_litmus/rake_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,34 @@
[{ 'uri' => 'some.host', 'facts' => { 'provisioner' => 'docker', 'container_name' => 'foo', 'platform' => 'some.host' } }] }] }
end
let(:targets) { ['some.host'] }
let(:params) { { 'collection' => 'puppet6' } }
let(:token) { 'some_token' }
let(:params) { { 'collection' => 'puppet6', 'password' => token } }

it 'calls function' do
allow(ENV).to receive(:fetch).with('PUPPET_VERSION', nil).and_return(nil)
allow(ENV).to receive(:fetch).with('PUPPET_FORGE_TOKEN', nil).and_return(token)
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent')).and_return(true)
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('puppet_agent::install', targets, params, config: described_class::DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
install_agent('puppet6', targets, inventory_hash)
end

it 'adds puppet version' do
params = { 'collection' => 'puppet7', 'version' => '7.35.0' }
allow(ENV).to receive(:fetch).with('PUPPET_VERSION', nil).and_return('7.35.0')
allow(ENV).to receive(:fetch).with('PUPPET_FORGE_TOKEN', nil).and_return(nil)
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent')).and_return(true)
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('puppet_agent::install', targets, params, config: described_class::DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
install_agent('puppet7', targets, inventory_hash)
end

it 'fails for puppetcore if no token supplied' do
params = { 'collection' => 'puppetcore7' }
allow(ENV).to receive(:fetch).with('PUPPET_VERSION', nil).and_return(nil)
allow(ENV).to receive(:fetch).with('PUPPET_FORGE_TOKEN', nil).and_return(nil)
allow(File).to receive(:directory?).with(File.join(described_class::DEFAULT_CONFIG_DATA['modulepath'], 'puppet_agent')).and_return(true)
allow_any_instance_of(BoltSpec::Run).to receive(:run_task).with('puppet_agent::install', targets, params, config: described_class::DEFAULT_CONFIG_DATA, inventory: inventory_hash).and_return([])
expect { install_agent('puppetcore7', targets, inventory_hash) }.to raise_error(RuntimeError, /puppetcore agent installs require a valid PUPPET_FORGE_TOKEN set in the env\./)
end
end

context 'with install_module' do
Expand Down