Uploaded image for project: 'Modules'
  1. Modules
  2. MODULES-7242

postgresql : postgresql_sql replaces $user

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Open
    • Priority: Normal
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: postgresql
    • Labels:
      None
    • Environment:

       

       

    • Template:
      MODULES Bug Template
    • Method Found:
      Needs Assessment
    • QA Risk Assessment:
      Needs Assessment

      Description

      Basic Info
      Module Version: 5.4.0
      Puppet Version: 4.10.11
      OS Name/Version: Ubuntu 16.04

      There seems to be an escaping issue with variables in postgresql_sql command.

      I want to execute SQL like ALTER USER "repmgr" SET search_path TO repmgr, "$user", public. "$user" should stay as it is and should not be replaced by something. Code looks like:

      postgresql_psql { "ALTER USER \"${::repmgr::db_user}\" SET search_path TO repmgr, \"\$user\", public":
          unless => "SELECT 1 FROM pg_roles WHERE rolname = '${::repmgr::db_user}' AND 'search_path=repmgr, \"\$user\", public' = ANY(rolconfig)",
      }

         But this leads to this error message:

      Error: Error executing SQL; psql returned pid 14442 exit 1: 'ERROR:  zero-length delimited identifier at or near """"
      LINE 1: ALTER USER "repmgr" SET search_path TO repmgr, "", public
                                                             ^
      '
      Error: /Stage[main]/Profiles::Repmgr/Postgresql_psql[ALTER USER "repmgr" SET search_path TO repmgr, "$user", public]/command: change from notrun to ALTER USER "repmgr" SET search_path TO repmgr, "$user", public failed: Error executing SQL; psql returned pid 14442 exit 1: 'ERROR:  zero-length delimited identifier at or near """"
      LINE 1: ALTER USER "repmgr" SET search_path TO repmgr, "", public
                                                             ^
      ' 

      You see that Puppet gets the correct command (Postgresql_psql[ALTER USER "repmgr" SET search_path TO repmgr, "$user", public]) but postgresql_psql executes (ALTER USER "repmgr" SET search_path TO repmgr, "", public) with $user being replaced with nothing.

      I tried different ways of escaping this with more backslashes. Using  \"\\\$user\" is going to end up as "\$user" at least.

      Desired Behavior:

       Execute SQL: ALTER USER "repmgr" SET search_path TO repmgr, "$user", public]

      Actual Behavior:

      Executes SQL: ALTER USER "repmgr" SET search_path TO repmgr, "", public]

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            SW Stefan
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:

                Zendesk Support