nodebb setup config/scripted admin setup failing (ansible)

Solved Technical Support
  • Re: How to setup admin user in config.json in nodebb

    Trying to setup nodebb via ansible. I provide nodebb setup with a config.json. The config.json file is linted by jsonlint-php, jq and validjson, rc==0.

    However, when running

    cd /opt/nodebb && ./nodebb setup --skip-build "$(cat config.json)"
    Invalid JSON passed as initial config value.
    If you meant to pass in an initial config value, please try again.
    
    2021-06-23T12:50:20.579Z [undefined/905674] - error: uncaughtException: Unexpected end of JSON input
    SyntaxError: Unexpected end of JSON input
        at JSON.parse (<anonymous>)
        at Command.<anonymous> (/opt/nodebb/src/cli/index.js:174:23)
        at Command.listener [as _actionHandler] (/opt/nodebb/node_modules/commander/index.js:922:31)
        at Command._parseCommand (/opt/nodebb/node_modules/commander/index.js:1503:14)
        at Command._dispatchSubcommand (/opt/nodebb/node_modules/commander/index.js:1443:18)
        at Command._parseCommand (/opt/nodebb/node_modules/commander/index.js:1460:12)
        at Command.parse (/opt/nodebb/node_modules/commander/index.js:1292:10)
        at Object.<anonymous> (/opt/nodebb/src/cli/index.js:316:9)
        at Module._compile (node:internal/modules/cjs/loader:1109:14)
    [...]
    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1138:10)","exception":true,"date":"Wed Jun 23 2021 15:01:36 GMT+0200 (Central European Summer Time)","process":{"pid":912816,"uid":998,"gid":998,"cwd":"/opt/nodebb","execPath":"/usr/bin/node","version":"v16.3.0","argv":["/usr/bin/node","/opt/nodebb/nodebb","setup","--skip-build","{\n  admin: {\n    username: nodebb-admin\n  }\n}"]
    [...]
    

    I got to try this as I set up a mongod database "nodebb" as per the installation instructions. The admin user and the "nodebb" db user (named "nodebb-admin", here) are created and verified in mongod. After installing and starting nodebb/nginx a login using "nodebb-admin" is failing, though.

    After running nodebb setup manually and answering the questions for admin user/pw/email (using i.e. "another-admin") a login using "another-admin" is successful. A login using "nodebb-admin" which has been setup in the mongod "nodebb" database is not working.

    This is suggesting there is some additional configuration happening when using nodebb setup
    with a manually typed admin user at the prompt as opposed to a prepared user in the "nodebb" database. What are those invisible steps? Some "nodebb" database objects?

    Why is this so and how to automate the creation of the admin user? The installation instructions given in the nodebb documentation are either not working (anymore) or I missed some point. But what is it?

    npm -v; node -v"
    npm verb cli [ '/usr/bin/node', '/opt/nodebb/node_modules/.bin/npm', '-v' ]
    npm info using [email protected]
    npm info using [email protected]
    

    Thanks for any helpful feedback

  • MWE for config.json used for the above nodebb setup call:

    {
      "admin": {
        "username": "nodebb-admin"
      }
    

    The full blown config.json is equally failing.

  • @bejan You're missing a closing bracket.

  • @bejan Yes, I know. Noticed the typo too late, cannot edit any more. Stupid.

  • My investigation was:

    Case 1:

    • mongodb: db.<collection>.remove({}) # configured admin user will remain in db, though
    • copy config.json in place
    • exec nodebb setup
    • copy config.json in place (req'd as nodebb setup truncates the config which is in itself bad enough)

    config.json contains a valid admin/passwd/email configuration. Mongodb has the same nodebb admin username configured.

    Result: no login possible.

    Case 2:
    => Running nodebb setup without cleaning up mongod database beforehand but with valid admin config in config.json makes nodebb setup create "admin" username with random password.

    Result: login using "admin" username and provided random password is successful.

    Case 3:
    Using environment variables with nodebb setup like this (w/ database cleaned up):

    export admin__username=my-nodebb-admin; export admin__password=mypasswd; export admin__password__confirm=mypasswd; ./nodebb setup
    

    yields:

    [...]
    This looks like a new installation, so you'll have to answer a few questions about your environment before we can proceed.                                                                   
    Press enter to accept the default setting (shown in brackets).
    2021-06-23T21:31:03.849Z [1261005] - info: 
    Now configuring mongo database:
    2021-06-23T21:31:03.979Z [1261005] - info: [database] Checking database indices.
    2021-06-23T21:31:03.984Z [1261005] - info: [database] Checking database indices done!
    2021-06-23T21:31:04.851Z [1261005] - verbose: [minifier] utilizing a maximum of 0 additional threads
    Configuration Saved OK
    Populating database with default configs, if not already set...
    [...]
    Schema update complete!
    

    Result: login with "my-nodebb-admin" username and preconfigured password is successful.

    Tests done with nodebb/v1.17.1 . Switched midway from npm to yarn as npm failed to accomplish it's task once too often.

    Conclusion: automated nodebb setup

    • using environment variables as of the given nodebb/node/npm versions is working
    • using preconfigured config.json as of the given nodebb/node/npm versions is NOT working

    Furthermore, nodebb setup truncates a preconfigured config.json, preventing successful startup of nodebb.

    In case preconfigured config.json was once working there is some regression. A possible fix for the above discrepencies/failures should prevent future regressions.

    NB: If there is interest, the final ansible playbook could possibly be open-sourced on github.

  • @bejan
    The setup json that you can provide with --setup=<content> has a different format than config.json, have a look at the github actions scripts in the main nodebb repo.

  • @max-0 the scripts on GitHub use node app --setup but his question is about ./nodebb setup

  • @pitaj Maybe I do not get the main point but IMHO (by looking at the code) you can't simply provide a ready-made config.json because it is a "result" of the install. The --setup <content> provides the answers to the questions the installer would ask but aside from gathering this info, the installer would create the DB schema (and update it if necessary), create default user, push default content.

  • @pitaj Are you familiar with the code in question and if so can you acknowledge or not whether it is the same syntax for both as @Max-0 is suggesting?

  • @bejan ./nodebb setup <config> and node app --setup=<config> should be functionally identical. If they don't behave the same, let me know.

    The "unexpected end of json input" error is either caused by a bad json file or a conflict between how shell arguments are escaped and how our tool expects input.

    The input to these isn't the same format as config.json, but is instead the answers to the setup questions as @Max-0 said. Here's an example of how we do it in GitHub actions:
    https://github.com/NodeBB/NodeBB/blob/edefac964556513dc2a65078f1fb62a26073cfbc/.github/workflows/test.yaml#L95

  • @pitaj Well, this info is golden.

    This clearly needs to be documented well and easily found. The usage message of ./nodebb setup --help should indicate the expected syntax and strikingly point out config.json is the wrong syntax in this case to be fed into ./nodebb setup.

    In the long run, there should be no special case or different syntax between node app --setup and ./nodebb setup.

    Thank you, @PitaJ, @Max-0 .


Suggested Topics


  • 0 Votes
    5 Posts
    382 Views

    Thank you very much! I was able to use the Admin user that was created in this authentification

  • 0 Votes
    1 Posts
    155 Views

    I've had nodebb setup for a bit now and through some bumps and scrapes have always kept it running. After upgrading to V1.13.0 NodeBB would fail to load with a "Internal Server Error". After updating to 1.13.1 the website once again loads, however when trying to view any topics in the forums it times out loading. I've reviewed every possible plugin that could potentially be in the way and disabled several without success. I'm not seeing anything in the logs so may be looking in the wrong place. Everything is fully functional to posting new topics, viewing recent ones, discarding, deleting, purging, and the admin console. The only issue comes when its time to actually open a topic fully. The RSS Feeds properly display all the recent topics and content as well.

    My server is running MongoDB and proxied via nginx behind LetsEncrypt SSL Certificate, and can be seen at www.zultyscp.com however does require a login, there is a single public post informing Guests that a login is required where you can see the issue.

    Any help on where to look for this and assistance in resolving would be appreciated.

  • 0 Votes
    2 Posts
    1k Views

    @bernatixer have a look at:

    Deploy NodeBB in a subfolder of a site https://community.nodebb.org/post/43630

    Hope it helps.

  • 0 Votes
    15 Posts
    3k Views

    @frissdiegurke I know. That's why I started it.

  • 0 Votes
    7 Posts
    2k Views

    just bumping