This message was deleted.
# puppet
s
This message was deleted.
c
See https://github.com/voxpupuli/puppet-nodejs#npm-packages It provides the nodejs installation and a package provider extention for npm. Regarding
npx
vs
npm
i can not help.
j
I think
npx
is kind of a convenience thing for running a node module's commands in the context of the local
package.json
, probably if you just use an
exec
resource and set the current directory to the directory of the
package.json
, you'll get the behavior you need. You may need to put the standard idempotency gates on that
exec
, though (i.e. figure out what file to look for with
creates
or what to check with
onlyif
or
unless
)
c
Thanks @Joel Wilson That was the path I'm currently going down.
What am I doing wrong. This is failing and not actually putting the contents of the variables in the command.
g
are the variables
$::db_name
,
$::db_user
, etc top-scope variables? or where are they defined?
c
They are defined in another profile file that is being included in the role file. Sorry if that is not clear...but I'm still new to Puppet. @glee
g
if they are defined in another profile, you probably need to namespace them to reflect that ie:
${profile::other::dbname}
etc
c
OK, I'll try that
c
this is my role file:
Copy code
class role::strapi {
  include profile::nodejs::install
  include profile::postgresql::install
  include profile::postgresql::config_strapi_db
  include profile::nodejs::strapi_install
}
..and those variables are in the
profile::postgresql::config_strapi_db
g
ok, so
${profile::postgresql::config_strapi_db::db_name}
... etc
c
That still didn't work. I get this error:
Copy code
Error: '/usr/bin/npx --yes create-strapi-app@latest my-proj                 --dbclient postgres --dbname                  --dbhost 127.0.0.1 --dbport 5432                 --dbusername  --dbpassword ' returned 1 instead of one of [0]
Error: /Stage[main]/Profile::nodejs::Strapi_install/Exec[npx create-strapi-app@latest my-proj]/returns: change from 'notrun' to ['0'] failed: '/usr/bin/npx --yes create-strapi-app@latest my-proj                 --dbclient postgres --dbname                  --dbhost 127.0.0.1 --dbport 5432                 --dbusername  --dbpassword ' returned 1 instead of one of [0] (corrective)
g
are those variables set or derived in the config profile? if they are derived it's possible that ordering means the config profile hasn't run yet so it hasn't set those values yet
c
the
db_name
,
db_user
are just a variable at top of file with a string value The
db_pass
is pulled in from and ENC eyaml file
g
if the config profile always must run first (before
profile::nodejs::strapi_install
, then you could possibly add a require to your strapi_install profile
so they're set in the config profile, they're not pulled from other params that are already set
as in, they're not parameters
you could try adding
require profile::postgresql::config_strapi_db
to
profile::nodejs::strapi_install
(ie: after
class rofile::nodejs::strapi_install {
, before your exec)
c
OK, does that re-run config_strapi_db profile again?
g
but that could interfere with other dependencies etc depending on what other interactions you have with the other profiles
no, that specifies ordering ie: config::strapi_db must run before strapi_install
c
so the order they are listed in the role file doesn't do that?
g
no
well, it doesn't enforce it
c
so keep the long variable names
profile::.....::db_user
g
yes you need to keep the namespacing otherwise it won't know where those variables are from
because they've been declared/set in another class, so you need to tell it specifically -- see the prev variables link and also https://www.puppet.com/docs/puppet/7/lang_scope.html#lang_scope for further info
c
OK, I'm closer. I did see that it was using the variables that were just defined as strings in the other profile working (
db_user
and
db_name
) however I'm getting this error now:
Copy code
Error: sh: 1: S: not found

Error: /Stage[main]/Profile::nodejs::Strapi_install/Exec[npx create-strapi-app@latest my-proj]/returns: change from 'notrun' to ['0'] failed: sh: 1: S: not found
 (corrective)
g
so the script/command that the exec is running is returning not found?
or possibly when it's switching to the strapi user?
(ie: in its user profile/shell?)
c
I'm confused as this error doen't make any sense to me.. Maybe I force the
provider => shell
?
g
no
you shouldn't need to specify provider => shell unless you're trying to use specific shell features (which are generally only if you need legacy behaviour)
what happens if you su - strapi on the host manually?
c
Well, this was running before...although the variables were wrong ( before I asked for help in here) , then I change the variables but they were referenced wrong. Now I have the require and correct path to variables...but getting this error that makes no sense to me 😕 Error: sh: 1: S: not found....
g
that error is saying the command that
exec
is running is returning "S: not found" -- ie: something called by npx (or the user profile that you're switching to) is passing
S
to the shell and causing it to return not found
if it was running before (but failing due to vars not being set), it's possible that npx is running now and getting further - ie: it wasn't getting the not found error before as it was failing before that point
c
I'm going to manually run that npx command as the strapi user to see what happens. I thought I did this before and it was fine...but I'll test again.
g
yeah i'd check that first. the other possibility is if the dbname/user/password has spaces or special chars they may need to be escaped for shell
c
Could special characters in the password be messing it up? I do see a
S
in the password...but there are some special characters too. So, I'm wondering if that is why it's messing up and returning the
S
?
Funny..you just said that.. I was typing that and not reading yours until I finished typing 😄
👍 1
g
do you need to quote the password when you pass it to shell manually?
c
yes
g
ok, so try adding quotes to your command for dbpassword -- replace the end of your command with:
--dbpassword \"${profile::postgresql::config_strapi_db::db_pass}\"",
hopefully slack hasn't mangled quotes 😕
ie: around the variable you should have
\"
c
I actually tried single quotes before you typed that......
g
so it will pass the quotes to the shell
c
currently running and I think might be working....
g
single quotes could work as well but i would probably escape them to be safe
c
yeh, the single quotes worked
yay 1
Thanks for your help @glee Appreciate it
👍 1