Skip to content
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

undefined local variable or method `password' for #<Puppet::Parser::TemplateWrapper:0x24910d2d> #7

Closed
rujim opened this issue Dec 24, 2019 · 18 comments

Comments

@rujim
Copy link
Contributor

rujim commented Dec 24, 2019

Hello jadestorm,
Please help me to create right Hiera values for bootstrap_users array.

My code (hieradata/product/lsm/tier/inf/env/2.yaml):

profiles::shared::postgresql::patroni::bootstrap_users:
  - 'bamboouser':
    password:
      "password"
    options:
      - 'createrole'
      - 'createdb'

Error is:

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, Failed to parse template patroni/postgresql.yml.erb:
  Filepath: /etc/puppetlabs/code/environments/feature_lsm_6460_bamboo/modules/patroni/templates/postgresql.yml.erb
  Line: 46
  Detail: undefined local variable or method `password' for #<Puppet::Parser::TemplateWrapper:0x24910d2d>
 (file: /etc/puppetlabs/code/environments/feature_lsm_6460_bamboo/modules/patroni/manifests/config.pp, line: 8, column: 16) on node us01vlhapglsm3.saas-n.com

Thank you in advance and happy holidays!

@jadestorm
Copy link
Collaborator

HI @rujim ! Ijust just coming back from the holidays -- to me it looks like you have an extra quote on the createdb line -- could that be what is causing the problem? Also please try to post both configs encased in an "insert code" block so that it doesn't get parsed into something else by github.

@rujim
Copy link
Contributor Author

rujim commented Jan 8, 2020

Updated.

@jadestorm
Copy link
Collaborator

Ok so another thing I see here is -- this should be on the same line:

    password:
      "password"

(change to)

    password: "password"

If it's not, what's happening is instead of password being treated as a string -- it's being treated as a hashed array -- at which point the module doesn't know what to do with it. Everything else at least -looks- fine to me. =)

@rujim
Copy link
Contributor Author

rujim commented Jan 9, 2020

Same error.

@jadestorm
Copy link
Collaborator

Interesting. Looks like you found a bug -- try the latest master and also remove the - from before the bamboouser -- ie:

profiles::shared::postgresql::patroni::bootstrap_users:
  'bamboouser':
    password: "password"
    options:
      - 'createrole'
      - 'createdb'

@rujim
Copy link
Contributor Author

rujim commented Jan 15, 2020

Hello jadestorm,
I reconfigured my Puppet for a current Master branch:

Puppetfile

mod 'jadestorm/patroni',
  :git    => 'https://github.com/jadestorm/puppet-patroni.git',
  :branch => 'master'

.fixtures.yml

    patroni:
      repo: https://github.com/jadestorm/puppet-patroni.git
      ref: master

My Hiera code:
hieradata/product/lsm/tier/inf/env/2.yaml

profiles::shared::postgresql::patroni::bootstrap_users:
  'bamboouser':
    password: "%{lookup('profiles::lsm::postgresql::bamboouser_db_password')}"
    options:
      - 'createrole'
      - 'createdb'

site/profiles/manifests/shared/postgresql/patroni.pp

class profiles::shared::postgresql::patroni (
...
Hash $bootstrap_users = {},
){
...
class { '::patroni':
...
bootstrap_users           => $bootstrap_users,
...

But I got the same issue:

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, Failed to parse template patroni/postgresql.yml.erb:
  Filepath: /etc/puppetlabs/code/environments/feature_lsm_6460_bamboo/modules/patroni/templates/postgresql.yml.erb
  Line: 46
  Detail: undefined local variable or method `password' for #<Puppet::Parser::TemplateWrapper:0x61ad3e63>
 (file: /etc/puppetlabs/code/environments/feature_lsm_6460_bamboo/modules/patroni/manifests/config.pp, line: 8, column: 16) on node us01vlhapglsm3.saas-n.com

Please, help me to fix its.
Tx!

@jadestorm
Copy link
Collaborator

Hrm I think I see the problem. (Btw I don't use Patroni anymore so I'm relying on you to test this) Basically, I was using password in a variable context, not a "string passed as the hash key". Please try the latest master commit. =)

@rujim
Copy link
Contributor Author

rujim commented Jan 16, 2020

Unfortunately, I can't see any changes with my Puppet. Same issue with password.

@jadestorm
Copy link
Collaborator

If you are getting the exact same error, that would most likely imply that the module didn't update. (or wouldn't make sense for you to see that exact same error with the current code) Open up the file it's referencing and go to line 46 and make sure all of the instances of password you see are in quotes. That should tell us if it updated at all.

@rujim
Copy link
Contributor Author

rujim commented Jan 17, 2020

yes, fixed now! Tx!

@jadestorm
Copy link
Collaborator

Awesome! Glad to hear it! =) And thanks for pointing out the bug! I'll get a formal release out hopefully today.

@rujim
Copy link
Contributor Author

rujim commented Jan 23, 2020

Hi Daniel,
I have got a password for my user bamboouser, but w/o options now:
(/etc/patroni/ha-pg-bamboo.yml)

pg_hba:
    - local all all md5
    - host all all 0.0.0.0/0 md5
    - host replication replicauser 0.0.0.0/0 md5
    - host replication replicauser all md5
    - host all postgres 0.0.0.0/0 md5
    - host bamboodb bamboouser 0.0.0.0/0 md5
    - hostssl replication replicauser 0.0.0.0/0 md5
  users:
    bamboouser:
      password: pass
  post_bootstrap: echo 'CREATE DATABASE bamboodb OWNER bamboouser;' | psql -q $1

2.yaml

profiles::shared::postgresql::patroni::bootstrap_users:
  'bamboouser':
    password: "%{lookup('profiles::lsm::postgresql::bamboouser_db_password')}"
    options:
      - 'createrole'
      - 'createdb'

Please, verify code for template.

@jadestorm
Copy link
Collaborator

Hrm. I suspect the erb processor is setting $settings['options'] and treating that as like a true or false rather than a "does this exist". Might have to do some shuffling.

@jadestorm jadestorm reopened this Jan 23, 2020
@jadestorm
Copy link
Collaborator

Can you try this latest master tweak? My logic was all off on that after I took a second look at it -- plus there's a better way to test if a key exists.

@rujim
Copy link
Contributor Author

rujim commented Jan 31, 2020

Last commit doesn't help me to pass options into Patroni conf file (/etc/patroni/ha-pg-bamboo.yml):

 - hostssl replication replicauser 0.0.0.0/0 md5
  users:
    bamboouser:
      password: pass
  post_bootstrap: echo 'CREATE DATABASE bamboodb OWNER bamboouser;' | psql -q $1

Config (hieradata/product/lsm/tier/inf/env/2.yaml):

profiles::shared::postgresql::patroni::bootstrap_users:
  'bamboouser':
    password: "%{lookup('profiles::lsm::postgresql::bamboouser_db_password')}"
    options:
      - 'createrole'
      - 'createdb'

BR,
Ruslan

@jadestorm
Copy link
Collaborator

jadestorm commented Feb 13, 2020

It's looking like it's going to be a bit before I can get around to this. If you have some time to patch it though I certainly accept and appreciate pull requests!

@rujim
Copy link
Contributor Author

rujim commented Feb 14, 2020

Hi Daniel,
I remember that option part was working before our password was fixed. So, I'll take a look.
BR,
Ruslan

@jadestorm
Copy link
Collaborator

Resolved via @rujim 's PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants