Facts Variable in Smart Class Parameter of type hash

Problem:
I will reach the goal that foreman/puppet deploy a docker container on every Node in a class. I use docker puppet module for that. I declare the docker containers over the docker::run_instance method of type hash. My problem is now, that i have to set an individual part of the docker instantiation. Example of my smart class parameter:
mysqld_exporter:
image: mysqld-exporter:latest
env:

  • DATA_SOURCE_NAME=mysqlexporter:Password@(<%= @fqdn %>:3306)/
    ports: 9104:9104
    restart_service: true
    extra_parameters:
  • “–restart=unless-stopped”

i have seen the topic: Use facts in smart variables
but this wont go because of error message: “no implicit conversion of String into Hash”

I’m not good in foreman puppet and so on, but i think it is a problem that the erb output is a string and the smart class parameter should be a hash.

Expected outcome:
I hope that it is possible to use a fact variable in the smart class parameter to reach my goal. example:
mysqld_exporter:
image: mysqld-exporter:latest
env:

  • DATA_SOURCE_NAME=mysqlexporter:Password@(host.example.com:3306)/
    ports: 9104:9104
    restart_service: true
    extra_parameters:
  • “–restart=unless-stopped”

Foreman and Proxy versions:
Foreman: 3.4.0
foreman-tasks 7.0.0
foreman_discovery 21.0.1
foreman_puppet 4.0.1
foreman_remote_execution 8.0.0
foreman_templates 9.3.0
katello 4.6.0

Distribution and version:
Rocky Linux release 8.6 (Green Obsidian)

No one there who can help a little bit?
Could i do anything or is there further information needed to clarify the problem?

thanks in advance
jörn

If I understand your problem correctly, you just need to format the data you want in the parameter into a hash.
The text you enter as a value should look something like this (replace with the keys and values you actually need:

{"DATA_SOURCE_NAME": "mysqlexporter:Password@(<%= @fqdn %>:3306)/", "ports": "9104:9104", "restart_service": true, "extra_parameters: ["–restart=unless-stopped"]}

If this is not actually what your question is about or you need further help, please elaborate more on the issue :slight_smile:

Hi areyus,
thanks for your answer and the explanation. I have now tested a little bit and have now a result why there are the problems. Also i have now rebuild my ruleset for all my Host Groups and by doing that, i have found the problem.
First i have inserted the following parameter (Smart Class Parameter Type is hash):

{
  "mysqld_exporter": {
    "image": "nexus1:8090/prom/mysqld-exporter:latest",
    "env": [
      "DATA_SOURCE_NAME=mysqlexporter:password@(<%= @host.name %>:3306)/"
    ],
    "ports": "9104:9104",
    "restart_service": true,
    "extra_parameters": [
      "--restart=unless-stopped"
    ]
  }
}

thats valid JSON and all is ok. Then i have tested the following notation:

mysqld_exporter:
  image: nexus1:8090/prom/mysqld-exporter:latest
  env:
    - DATA_SOURCE_NAME=mysqlexporter:password@(<%= @host.name %>:3306)/
  ports: 9104:9104
  restart_service: true
  extra_parameters:
    - "--restart=unless-stopped"

thats also accepted from Foreman and for both values, in the output from node.rb is all clear:

  docker::run_instance:
    instance:
      mysqld_exporter:
        image: nexus1:8090/prom/mysqld-exporter:latest
        env:
        - DATA_SOURCE_NAME=mysqlexporter:password@(dns1-stage:3306)/
        ports: 9104:9104
        restart_service: true
        extra_parameters:
        - "--restart=unless-stopped"

This is in hiera notation.
With these input values, on the managed node all is fine and running.

Problem Description
After that, i have reconfigured my ruleset for different host groups in foreman. Some in the JSON notation, some in the hiera notation. This is also running if the ‘Merge Overrides’ functionality isn’t activated.


in the picture not enabled.

Now comes an update to my question.
Is this normal behaviour or should foreman replace these erb macros also in this usecase with value merging?

Sincerely Jörn

I have never tested this myself, but erb replacement should also work with value merging.

ok, thank you areyus for the reply.
think i will further investigate and probably open a bug report.

many thanks for your help.

Have today updated the foreman katello to Version 3.5 & 4.7.
Now the problem seems to be solved. Have backported my hiera hash definitions to rules on different hierarchy levels.
Check with /etc/puppetlabs/puppet/node.rb [hostname] on different hosts now runs as expected.