ffrank / puppet-mgmtgraph

The mgmt translator for Puppet manifests
Other
11 stars 4 forks source link

Ignore metaparams for default translation as well #7

Closed aequitas closed 6 years ago

aequitas commented 6 years ago

The before metaparam causes the generation of an invalid command (on my system at least):

super_vagrant@faalserver:/vagrant# puppet yamlresource package 'htop' '{"provider": "apt", "ensure": "latest", "before": [{type: "Package", title: "resolvconf",
            tags: {hash: {"package": true, "resolvconf": true}}, parameters: {}}], "configfiles": "keep",
        "reinstall_on_refresh": "false", "loglevel": "notice"}'
Error: Parameter before failed on Package[htop]: Puppet::Resource.new does not take a hash as the first argument. Did you mean ("Package", "resolvconf") ?
Error: Try 'puppet help yamlresource find_or_save' for usage

I have not tested this yet for unwanted side effects.

ffrank commented 6 years ago

Sorry for the late reply. Interesting, I'll try and reproduce next chance I get.

Thanks for making the patch!

aequitas commented 6 years ago

No problem. I must admit I'm not using this module atm and probably won't in the future as afaik it can not be combined with lang, and I prefer to go for lang instead of YAML, so that will be a slow and painful rewrite of my current puppet code. If you have any solutions for this in mind let me know :)

ffrank commented 6 years ago

So I've taken a look at the translations and I think your idea is great! Unfortunately, the patch does not seem to work. The reject block cannot just chain the unwanted cases like this. Could you please

  1. rebase to current master and
  2. change the code to something like this? (Tested this successfully)

    +      [ :name,
    +        # ignore relational metaparameters, those are handled through the actual
    +        # edges in the RAL graph
    +        :before, :require, :notify, :subscribe, ].include? attr

I verified that the relationship edge does indeed survive this treatment:

$ puppet mgmtgraph print --code 'host { "a": before => Host["b"] } host { "b": }'
---
graph: localhost
...
- name: Host[a] -> Host[b]
  from:
    kind: exec
    name: Host:a
  to:
    kind: exec
    name: Host:b
...
ffrank commented 6 years ago

Oh and as for mgmt lang (which needs a proper name, geez) vs. translated code, that has indeed been on my mind. Collected thoughts so far: https://ffrank.github.io/hacks/2018/02/13/thinking-about-migration-from-puppet-to-mgmt/

Any feedback is greatly appreciated (you can open an issue here for example).

aequitas commented 6 years ago

Sorry ruby is not really my strong point :). I'll update the PR tomorrow.

aequitas commented 6 years ago

@ffrank updated, also added a test.

I think the language is referred to as mcl, but maybe it needs a more proper name indeed :)

ffrank commented 6 years ago

Love it! Special thanks for the test!