theforeman / hammer-cli-foreman-templates

CLI plugin with import and export commands
GNU General Public License v3.0
0 stars 6 forks source link

Verbose import and import not taking place #4

Closed treydock closed 6 years ago

treydock commented 6 years ago

Does verbose import actually work? I'm used to using the rake task for import but that's broken at this moment (https://github.com/theforeman/foreman_templates/issues/101) and am used to seeing a diff when importing templates.

I modified one of my templates then ran verbose import, no diff.

[root@foreman-test ~]# hammer import-templates --verbose yes
[Foreman] Username: tdockendorf
[Foreman] Password for tdockendorf: 
Import finished

The help output for import-templates shows verbose but guessing that's just coming from API docs and maybe not supported by CLI tools? Would be very handy to support showing a diff.

Other issue, I modified one of my templates and ran import and the modification is not removed. I'm guessing maybe my settings aren't being respected?

screen shot 2018-07-06 at 9 23 12 am

I enabled debug logging and don't see much:

2018-07-06T09:26:30 [I|app|] Started POST "/api/templates/import" for 10.20.0.24 at 2018-07-06 09:26:30 -0400
2018-07-06T09:26:30 [I|app|e7c94] Processing by Api::V2::TemplateController#import as JSON
2018-07-06T09:26:30 [I|app|e7c94]   Parameters: {"verbose"=>true, "apiv"=>"v2", "template"=>{}}
2018-07-06T09:26:30 [I|app|e7c94] Current user: foreman_admin (administrator)
2018-07-06T09:26:30 [I|app|e7c94] Authorized user tdockendorf(tdockendorf Trey Dockendorf)
2018-07-06T09:26:30 [I|app|e7c94] Current user: tdockendorf (administrator)

The only way I got my import to work was by duplicating the settings I've already set in web UI:

[root@foreman-test ~]# hammer import-templates --verbose yes --branch master --associate always --force yes --lock yes --prefix '' --repo ssh://git@code.osu.edu/osc/osc-foreman-templates.git --dirname /
ofedoren commented 6 years ago

@treydock, currently verbose mode doesn't work (if you don't want to see redundant verbose option, you can upgrade this plugin to 0.1.1).

Unfortunately I couldn't reproduce the second problem. It works fine with those settings and hammer import-templates imports and replaces modified via foreman templates. Could you provide more of the debug output from foreman as well as from hammer?

treydock commented 6 years ago

@ofedoren The second issue is more that the settings for the templates plugin are not used by the CLI interface so I have to explicitly pass things like --repo instead of the value being pulled from settings stored in Foreman. When I used the templates Rake task I was able to run the rake command with no arguments as all values came from the settings set in GUI, like my screenshot in previous comment. Is that what your unable to reproduce?

ofedoren commented 6 years ago

@treydock yes. Because, as I said, I was using hammer import-templates with no options at all, so everything was fetched from settings stored in Foreman (e.g. I changed repo via Foreman GUI, ran import via Hammer) and it worked.

treydock commented 6 years ago

@ofedoren I added <%# FOO %> to the template OSC - include and then ran import and see this in debug:

{"name":"OSC - include","id":null,"changed":false,"imported":false,"additional_errors":"No 'model' found in metadata","exception":null,"validation_errors":{},"file":"OSC-include.erb","type":null}

The full log is here: https://pastebin.com/G73FcPSz. I truncated the logs before running the hammer import-templates command and it appears like to POST were made twice but the modification I made to one template remains.

ofedoren commented 6 years ago

@treydock thanks for the logs, it's much more clear now.

The problem is in templates' metadata. There is no model specification in the template you are importing. See community templates which have recommended specifications in metadata.

treydock commented 6 years ago

@ofedoren Thanks for the pointer, adding model and in some cases snippet: true was necessary to fix template importing of our custom repo.

treydock commented 6 years ago

@ofedoren I don't know if appropriate but the hash that is returned by debug output like the hash below would be useful as output for CLI command:

{"name":"OSC - include","id":231,"changed":true,"imported":false,"additional_errors":null,"exception":null,"validation_errors":{"template_kind_id":"can't be blank"},"file":"OSC-include.erb","type":"provisioning_template"}

Maybe --verbose would iterate over the debug array of hashes returned in templates key and show if things changed or if there were any errors.

ofedoren commented 6 years ago

@treydock already thought about it as well :) I think the next release will return verbose option with some output.

If there is nothing more to add to the current problem, can be this issue closed?

treydock commented 6 years ago

@ofedoren Ya, I'll close.