Uploaded image for project: 'Satellite'
  1. Satellite
  2. SAT-35446

Getting 'invalid metadata' error (Psych::SyntaxError): (<unknown>): did not find expected key while parsing a block mapping at line 2 column 1 when trying to import templates

XMLWordPrintable

    • 2
    • False
    • Moderate
    • sat-endeavour
    • None
    • None
    • None
    • No Coverage

      The process documented in https://docs.redhat.com/en/documentation/red_hat_satellite/6.16/html/administering_red_hat_satellite/synchronizing-template-repositories#Synchronizing_Templates_with_a_Local_Directory_admin or 16.1 , works great as long as there are no indentation issues present in any of the templates being synced\imported into satellite. 

      But if even a minor indentation problem exists, the template import will fail with a rather odd error and without providing any proper hints of what we need to look for and where. 

       

      Steps to reproduce:

      1. Install a Sat 6.16
      2. Set it up in the following way: 
        # ls -ladZ /var/lib/foreman/My_Templates_Dir /var/lib/foreman/My_Templates_Dir/test.erb  
        drwxr-xr-x. 2 foreman root system_u:object_r:foreman_lib_t:s0  22 Jun 26 14:32 /var/lib/foreman/My_Templates_Dir
        -rw-r--r--. 1 foreman root system_u:object_r:foreman_lib_t:s0 346 Jun 26 14:32 /var/lib/foreman/My_Templates_Dir/test.erb
        # cat /var/lib/foreman/My_Templates_Dir/test.erb
        <%#
        kind: snippet
        name: test_snippet
        model: ProvisioningTemplate
        snippet: true
        description: |
           This shows bad indentation
           which should not allow the template to be imported.
          Correct indentation starts from here.
        -%>
        <%
        proxy_uri = host_param('http-proxy') ? "http://#{host_param('http-proxy')}:#{host_param('http-proxy-port')}" : nil
        -%>
        
        # hammer settings info --name template_sync_repo
        Id:            template_sync_repo
        Name:          template_sync_repo
        Description:   Target path to import/export. Different protocols can be used, for example /tmp/dir, git://example.com, https://example.com, ssh://example.com. When exporting to /tmp, note that production deployments may be configured to use private tmp.
        Category:      Template Sync
        Settings type: string
        Value:         /var/lib/foreman/My_Templates_Dir
        

         

           

               3. Try to sync it from WebUI --> Hosts --> Templates --> Sync Templates --> Submit 

                  Or Import via hammer command i.e. 

                  # hammer import-templates --organization-id 1 --verbose true

       

      Actual Behavior:

       

      • The WebUI sync fails and shows the file name test.erb and the error "Failed to parse metadata"
      • The hammer import also fails but shows rather less helpful information. 
        # hammer import-templates --organization-id 1 --verbose true
        Name:     
        Type:     
        Imported: false
        Changed:  false
        Errors:   
            Additional: 
              Failed to parse metadata
        Import finished.
        

         

       

      • The following is logged in production.log
      • 2025-06-26T14:33:09 [W|app|f31e4f70] invalid metadata
        2025-06-26T14:33:09 [I|app|f31e4f70] Backtrace for 'invalid metadata' error (Psych::SyntaxError): (<unknown>): did not find expected key while parsing a block mapping at line 2 column 1
         f31e4f70 | /usr/share/ruby/psych.rb:456:in `parse'
         f31e4f70 | /usr/share/ruby/psych.rb:456:in `parse_stream'
         f31e4f70 | /usr/share/ruby/psych.rb:390:in `parse'
         f31e4f70 | /usr/share/ruby/psych.rb:349:in `safe_load'
         f31e4f70 | /usr/share/foreman/app/models/template.rb:116:in `parse_metadata'
         f31e4f70 | /usr/share/gems/gems/foreman_templates-9.5.1/app/services/foreman_templates/template_importer.rb:54:in `block in parse_files!'
         f31e4f70 | /usr/share/gems/gems/foreman_templates-9.5.1/app/services/foreman_templates/template_importer.rb:49:in `each'
         f31e4f70 | /usr/share/gems/gems/foreman_templates-9.5.1/app/services/foreman_templates/template_importer.rb:49:in `parse_files!'
         f31e4f70 | /usr/share/gems/gems/foreman_templates-9.5.1/app/services/foreman_templates/template_importer.rb:27:in `import_from_files'
         f31e4f70 | /usr/share/gems/gems/foreman_templates-9.5.1/app/services/foreman_templates/template_importer.rb:20:in `import!'
         f31e4f70 | /usr/share/gems/gems/foreman_templates-9.5.1/app/controllers/api/v2/template_controller.rb:28:in `import'
         f31e4f70 | /usr/share/gems/gems/actionpack-6.1.7.8/lib/action_controller/metal/basic_implicit_render.rb:6:in `send_action'

       

      Where the statement "block mapping at line 2 column 1" is a bit too technical to be able to easily understand the source of the issue. 

       

      Expected Behavior:

       

      A) The error message, whether provided by hammer or webui or logged in foreman logs, should clearly say, "There are some indentation issues or syntax issues present in the test.erb template" . In short, it needs to be user friendly as well as meaningful. 

       

      B) The hammer command specifically should mention the name of the template which is failing to be imported. 

       

      Additional note:

      The issue in the template is here:
      description: |
         This shows bad indentation
         which should not allow the template to be imported.
        Correct indentation starts from here.
       

      If we fix it to be 
      description: |
        This shows bad indentation
        which should not allow the template to be imported.
        Correct indentation starts from here.
      that would allow importing the template 

              Unassigned Unassigned
              rhn-support-saydas Sayan Das
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated: