This message was deleted.
# puppet
s
This message was deleted.
b
Can you try
Sensitive(Deferred(....))
?
ah this is probably a chicken and egg problem
functions are evaluated on the puppetserver, during catalog compilation
Deferred moves that to the agent
but you use that within another function, postgresql::postgresql_password
which is evaluated on the puppetserver
so you would need to defer both function calls. or none of them
c
I'll try that. I believe I had done that before ( a little bit different setup of vars ) and it worked...however, it was storing a value in the DB for password that wasn't correct.
I changed it to this. The puppet code ran without error and updated the DB password......but it's not correct password hash in the DB 🙁
b
why do you call inline_epp?
c
cause I'm a n00b and that's what I found in other code 😕
b
that defers the inline_epp function
what you want to do is defer postgresql::postgresql_password
c
This?
Copy code
password_hash => Deferred(postgresql::postgresql_password($db_user, $db_password)),
b
that might work. I don't know if the function actually supports it
c
same error of
expects a value of type string.... but got Deferred
b
can you paste the code you currently have?
if possible as actual code, not a screenshot 🙂
and the whole error
c
Copy code
# Setup Postgress for Strapi
class profile::postgresql::config_strapi_db () {

  # DB Variables
  $db_name = 'strapi-db'
  $db_user = 'strapi-admin'
  $db_password_1 = Deferred('vault_key', ['<https://vault00:8200/v1/puppet/data/strapi>', 'puppet-pki', 'tds_strapi_db_password', 'v2'])

# Create Strapi role/user

  # Environment: TDS
  if /^10\.30\./ in $facts['networking']['ip'] {
    $db_password = Deferred('vault_key', ['<https://vault00:8200/v1/puppet/data/strapi>', 'puppet-pki', 'tds_strapi_db_password', 'v2'])
    }
  # Environment: Prod
  elsif /^10\.40\./ in $facts['networking']['hostname'] {
    $db_password = Deferred('vault_key', ['<https://vault00:8200/v1/puppet/data/strapi>', 'puppet-pki', 'prod_strapi_db_password', 'v2'])
  } else {
  # Environment: Infra
  }

  postgresql::server::role { $db_user:
    superuser     => true,
    password_hash => Deferred(postgresql::postgresql_password($db_user, $db_password)),
    hash          => 'scram-sha-256'
  }
  notify { 'debug':
    message => $db_password
  }
  notify { 'debug1':
    message => $db_password_1
  }
# Create Strapi db and assign user

  # postgresql::server::db { $db_name:
  #     user     => $db_user,
  # }
}
Copy code
Error: Could not retrieve catalog from remote server: Error 500 on SERVER: Server Error: Evaluation Error: Error while evaluating a Resource Statement, Evaluation Error: Error while evaluating a Function Call, 'postgresql::postgresql_password' parameter 'password' expects a value of type String, Sensitive[String], or Integer, got Deferred (file: /etc/puppetlabs/code/environments/strapi/local_modules/profile/manifests/postgresql/config_strapi_db.pp, line: 24, column: 31) on node strapi

Warning: Not using cache on failed catalog
Error: Could not retrieve catalog; skipping run
b
can you try
Deferred(postgresql::postgresql_password($db_user, Sensitive($db_password)))
👀 1
c
Copy code
Function Call, 'postgresql::postgresql_password' parameter 'password' expects a value of type String[1], Sensitive[String], or Integer, got Sensitive[Object[{name => 'Deferred', attributes => {'name' => Pattern[/\A[$]?[a-z][a-z0-9_]*(?:::[a-z][a-z0-9_]*)*\z/], 'arguments' => {type => Optional[Array], value => undef}}}]]
b
ah damn
c
Why is this sooo hard. It shouldn't be...ugghh
b
I'm not sure if nesting two deferred function calls is possible
c
the
inline_epp
seems to work without error, but can't figure out why it's populating the wrong value in the DB. Maybe somehow the code is returning an error of
string
type and just passing that in the
password
part and it just hashes that?
b
your inline_epp example does something completely different
c
well initially I had the
dp_password
inside of something like this:;
Copy code
$variables = {
     'db_password' => Deferred('vault_key', .......)
}
And then used a:
Copy code
password_hash => Deferred('inline_epp', [postgresql::postgresql_password($variables[db_user], '<%= $db_password.unwrap %>'),$variables]),
b
and did that work?
because that doesn't look like a valid epp template to me
c
that puts the wrong hash in the db, but no errors on the puppet deploy side.
b
yes. It does not execute the
postgresql::postgresql_password
function
c
it did. it populated the db with a password
just not the one I was expectinig
b
are you sure it was a password? And not just any random string?
c
it was an md5 hash
md5xxxxxxxxxxxxx
b
mhm