Project

General

Profile

Bug #23382

Editing Smart Class Parameter of type YAML creates malformed value in release 1.17.0

Added by Vadim Bulst 5 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Urgent
Category:
Smart Variables
Target version:
Team Backlog:
Fixed in Releases:
Found in Releases:

Description

When defining smart class parameter values with type YAML and submitted in GUI an Ruby error message gets prepended for each array entry.

Defining an YAML-Array like:

---
- name: foo
  mount_point: /bar
- name: john
  mount_point: /doe

gets saved as:
- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  name: foo
  mount_point: "/bar" 
- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
  name: john
  mount_point: "/doe" 

Just a very simple example our YAML are much more complex. This error appears since the upgrade from 1.16.1 to 1.17.0.

As we need this system for production, we can leave this installation like it is for debugging purposes for a maximum of 36hours.

HOSTNAME: urzlxdeploy.rz.uni-leipzig.de
OS: redhat
RELEASE: CentOS Linux release 7.4.1708 (Core)
FOREMAN: 1.17.0
RUBY: ruby 2.0.0p648 (2015-12-16) [x86_64-linux]
PUPPET: 4.10.11
DENIALS: 0


Related issues

Related to Foreman - Bug #23581: Upgrade to Foreman 1.17 converts YAML to JSON HashResolved
Has duplicate Foreman - Bug #23463: YAML rendering of external nodes generates incorrect data if hashes are usedDuplicate2018-04-30

Associated revisions

Revision d477552c (diff)
Added by Daniel Lobato Garcia 3 months ago

Fixes #23382 - Hashes in arrays are shown properly on ENC

When defining smart class parameter values with type YAML and submitted
in GUI an Ruby error message gets prepended for each array entry.

Defining an YAML-Array like:

---
- name: foo
mount_point: /bar
- name: john
mount_point: /doe

is shown on the ENC as:

- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
name: foo
mount_point: "/bar"
- !ruby/hash:ActiveSupport::HashWithIndifferentAccess
name: john
mount_point: "/doe"

In order to avoid parsing the whole YAML or monkeypatching
HashWithIndifferentAccess the easiest workaround is to convert to
JSON then parse back to YAML

History

#1 Updated by Michael Moll 5 months ago

  • Related to Bug #23463: YAML rendering of external nodes generates incorrect data if hashes are used added

#2 Updated by Michael Moll 5 months ago

  • Legacy Backlogs Release (now unused) changed from 296 to 297

I think this is https://github.com/rails/rails/issues/29013 a fix was maerged to Rails 5.1 branch and will be part of Rails 5.1.7, which is not yet released...

#3 Updated by Henry Spanka 4 months ago

Is there any quick fix? I have upgraded to 1.17.0 recently and now all my Puppet manifests fail because the hashes are malformed? Rails 5.1.7 isn't going to be released anytime soon, so I guess we need a fix for that.
Couldn't we just revert the change that introduced this issue from 1.16.x to 1.17.0?

#4 Updated by Tomer Brisker 4 months ago

  • Legacy Backlogs Release (now unused) changed from 297 to 360

Pushing out to 1.17.2, this won't be fixed in time for 1.17.1.

#5 Updated by Henry Spanka 4 months ago

Well I fixed this in the meantime by manually editing the rails file as mentioned by Michael. Can't we just provide a patched rails release via the foreman repos?

#6 Updated by Tobias Ehrig 4 months ago

The fix mentioned by Henry Spanka doesnt work for me. (Debian Stretch installed via DEB Repositoy)

#7 Updated by Henry Spanka 4 months ago

@Tobias: Have you restarted foreman (Webserver) after applying the fix? Note that you also need to edit the classes again and just save the parameters again so they are correctly stored in the database. It is not required to change them but you need to resave them.

#8 Updated by Tobias Ehrig 4 months ago

@Henry: Yes, I've restarted the whole box. After the fix, the array values are displayed fine - without escaped doublequotes - but the puppet agent still failed with the exception above.

#9 Updated by Tomer Brisker 3 months ago

  • Related to Bug #23581: Upgrade to Foreman 1.17 converts YAML to JSON Hash added

#10 Updated by Daniel Lobato Garcia 3 months ago

  • Triaged set to No

I'm trying hard to reproduce this, but even complex hashes seem to be rendered properly. For example:

classes:
  dhcp:
    bootfiles:
      override_value:
        match: fqdn=server.example.com
        value:
          testvg:
            physical_volumes:
            - "/dev/sdb" 
            - "/dev/sdc" 
            logical_volumes:
              test1:
                size: 128M
                mountpath: "/opt/test1" 
              test2:
                size: 128M
                mountpath: "/opt/test2" 
              test3:
                size: 128M
                mountpath: "/opt/test3" 
              test4:
                size: 128M
                mountpath: "/opt/test4" 
              test5:
                size: 128M
                mountpath: "/opt/test5" 

#11 Updated by Daniel Lobato Garcia 3 months ago

I do see it now, with Arrays:

classes:
  dhcp:
    bootfiles:
    - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
      name: foo
      mount_point: "/bar" 
    - !ruby/hash:ActiveSupport::HashWithIndifferentAccess
      name: john
      mount_point: "/doe" 

#12 Updated by Daniel Lobato Garcia 3 months ago

JSON.parse(@host.info.to_json).to_yaml(:line_width => -1)
- using this in hosts_controller, on the externalNodes method works well

#13 Updated by The Foreman Bot 3 months ago

  • Assignee set to Daniel Lobato Garcia
  • Status changed from New to Ready For Testing
  • Pull request https://github.com/theforeman/foreman/pull/5769 added

#14 Updated by Daniel Lobato Garcia 3 months ago

  • Related to deleted (Bug #23463: YAML rendering of external nodes generates incorrect data if hashes are used)

#15 Updated by Daniel Lobato Garcia 3 months ago

  • Has duplicate Bug #23463: YAML rendering of external nodes generates incorrect data if hashes are used added

#16 Updated by Daniel Lobato Garcia 3 months ago

  • % Done changed from 0 to 100
  • Status changed from Ready For Testing to Closed

#17 Updated by The Foreman Bot 3 months ago

  • Pull request https://github.com/theforeman/foreman/pull/5786 added

#18 Updated by The Foreman Bot 3 months ago

  • Pull request https://github.com/theforeman/foreman/pull/5787 added

Also available in: Atom PDF