Add a conditional to run npms only when explicitely required

This commit is contained in:
Javier Bértoli 2019-03-10 23:36:03 -03:00
parent df99e1cdcc
commit 9c83969acc
3 changed files with 26 additions and 10 deletions

View file

@ -14,7 +14,12 @@ include:
{% endfor %}
{% endif %}
### REQ PKGS (without these, some of the WANTED PIPS will fail to install)
# As we depend on npm installed, if this state file is invoked every time
# if will fail with 'npm not found'. This condition makes sure it's run
# only when explicitly asking for adding/removing npms
{% if wanted_npms or unwanted_npms %}
### REQ PKGS (without these, some of the WANTED NPMS will fail to install)
npm_req_pkgs:
pkg.installed:
- pkgs: {{ req_pkgs | json }}
@ -66,3 +71,5 @@ wanted_npms:
{{ upn }}:
npm.removed
{% endfor %}
{% endif %}

View file

@ -62,10 +62,10 @@ packages:
- goodbye-world
npms:
# dir: /home/kitchen/npms # The target directory in which to install the package, or None for global installation
# user: kitchen # The user to run NPM with (and to assign to `dir`)
# group: kitchen # The group to assign to `dir`
# mode: 0755 # The permissions to assign to `dir`
dir: /home/kitchen/npms # The target directory in which to install the package, or None for global installation
user: kitchen # The user to run NPM with (and to assign to `dir`)
group: kitchen # The group to assign to `dir`
mode: 0755 # The permissions to assign to `dir`
# registry: None # The NPM registry from which to install the package
# env: None # A list of environment variables to be set prior to execution
# force_reinstall: False # Install the package even if it is already installed

View file

@ -1,3 +1,8 @@
## FIXME! inspec's npm resource fails to check correctly (sudo issues, path issues)
## so I added some "poor man's checks" to ensure, at least, that npms are in place
npms_path = '/home/kitchen/npms'
wanted_npms = {
'hello-world-npm': '1.1.1',
'sax': '1.2.4',
@ -13,12 +18,16 @@ control 'Wanted/Required npm packages' do
os.name == 'debian'
end
describe directory(npms_path) do
it { should exist }
its('owner') { should cmp 'kitchen' }
its('group') { should cmp 'kitchen' }
its('mode') { should cmp '0755' }
end
wanted_npms.each do |p,v|
describe npm(p) do
it { should be_installed }
# FIXME! Testing for version is failing, seems an issue in inspec
# Same happens with testing path, as it performs a cd command and it fails when using sudo
# its('version') { should eq v }
describe directory("#{npms_path}/node_modules/#{p}") do
it { should exist }
end
end
end