jovandeginste / puppet-scoop

Manage your scoops with Puppet
Apache License 2.0
2 stars 1 forks source link

Operator '[]' is not applicable to an Undef Value. #3

Open hopenbr opened 2 years ago

hopenbr commented 2 years ago

What am I doing wrong, it seems that on the initial run of puppet I get below error and continues until we get scoop installed

$facts['scoop'] is not available yet since it first run and we need scoop installed

Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Operator '[]' is not applicable to an Undef Value. (file: /etc/puppetlabs/code/environments/production/modules/scoop/manifests/package.pp, line: 21, column: 27) (file: /etc/puppetlabs/code/environments/production/modules/lfg_gitlab_runner_windows/manifests/init.pp, line: 20) on node ahost.myorg.org

my code looks like

class xxx_gitlab_runner_windows(
  Hash $runners,
  Hash $packages = {},
  Hash $runner_defaults = {
    'url' => 'https://gitlab.XXX.com'
  },
){
  class  { 'scoop':
    packages => [ '7zip', 'pwsh-7.1', 'git', 'gitlab-runner', 'openjdk11' ],
  }

  $_runners = $runners.keys
  lfg_gitlab_runner_windows::runner { $_runners:
    binary           => 'gitlab-runner.exe',
    binary_directory => 'C:\\ProgramData\\scoop\\apps\\gitlab-runner\\current',
    default_config   => $runner_defaults,
    runners_hash     => $runners
  }

  $_packages = $packages.keys
  lfg_gitlab_runner_windows::package { $_packages:
    packages_hash => $packages

  }

}

error hits on line 20 which is

class  { 'scoop':
    packages => [ '7zip', 'pwsh-7.1', 'git', 'gitlab-runner', 'openjdk11' ],
  }

I have tried having

incldue scoop

scoop::package { 'git':
  ensure => 'present',
}

yet same error

jovandeginste commented 2 years ago

I assume you meant include instead of incldue ?

jovandeginste commented 2 years ago

Out of curiosity, what does facter osfamily say on your system?

hopenbr commented 2 years ago

factory osfamily windows

jovandeginste commented 2 years ago

Are you able to change the code where you run puppet?

jovandeginste commented 2 years ago

If so, can you remove the line in lib/facter/scoop.rb, which says confine { basedir } ?

hopenbr commented 2 years ago

sorry for delay, yeah I did so and it failed in same way

hopenbr commented 2 years ago

further

...
Debug: Facter: fact "puppet_stringify_facts" has resolved to false.
Debug: Facter: fact "puppet_vardir" has resolved to "C:/ProgramData/PuppetLabs/puppet/cache".
Debug: Facter: fact "root_home" resolved to null and will not be added.
Error: Facter: error while resolving custom fact "scoop": The system cannot find the file specified.
Debug: Facter: fact "scoop" resolved to null and will not be added.
Debug: Puppet::Type::Service::ProviderBase: file kill does not exist
...

I see above logs when running puppet facts --debug on host I am trying to configure

with or without the confine { basedir } in lib/facter/scoop.rb

not sure what that means, what file?

A lot of this seems like a chicken and egg problem, the module expects things to be there yet they have yet to be installed by module and it fails.

plus I am no puppet expert

hopenbr commented 2 years ago

if I run

 [environment]::SetEnvironmentVariable('scoop', 'c:\programdata\scoop', [System.EnvironmentVariableTarget]::Machine)

than run puppet facts, it works.

looking to see if I can add that env var before hand

jovandeginste commented 2 years ago

Yes, I had a lot of trouble getting the environment to work. This will sound silly, but did you reboot after scoop installation?

hopenbr commented 2 years ago

Work around is in place I just set the environment var SCOOP in the EC2 user_data in my Cloudformation template

Puppet is now installing scoop and the configured scoop packages