design-center icon indicating copy to clipboard operation
design-center copied to clipboard

cf-sketch interactive mode does not work with multi-dimensional arrays

Open nickanderson opened this issue 12 years ago • 20 comments

Try configuring Repository::apt::Maintain

cf-sketch> configure Repository::apt::Maintain

Entering interactive configuration for sketch Repository::apt::Maintain.
Please enter the requested parameters (enter STOP to abort):

Parameter 'repos' must be an array.
Please enter each key and value in turn, empty key to finish.
Please enter next key: handbrake
Please enter value for repos[handbrake]: distrib
Please enter next key: 
Sorry, but KVARRAY validation was requested on a non-array entry value 'distrib'.  We'll fail the validation.
Array validation failed. Resetting, please reenter all the values.

nickanderson avatar Jan 28 '13 20:01 nickanderson

We plan to approach this in two ways:

  • stop using deeply nested arrays so much
  • when we use them, support them better (so yes, this ticket is valid)

tzz avatar Feb 15 '13 16:02 tzz

But I WANT to use deeply nested arrays, it builds character ;)

nickanderson avatar Feb 15 '13 18:02 nickanderson

@zzamboni is working on it.

tzz avatar May 10 '13 16:05 tzz

Interactive configuration mode has now been reimplemented for the new cf-sketch. Please see and test #309.

It still doesn't work with deeply-nested arrays though, since the drive seems to be towards simplification of parameters. I think for complex data structures you are better off editing the JSON file directly anyway.

zzamboni avatar May 22 '13 03:05 zzamboni

yes i got the same issue while configure Users::Local on interactive mode it is very had to set the value and it is not set throw the error. "local" : [ { "name" : "runenv", "type" : "environment" }, { "name" : "metadata", "type" : "metadata" }, { "name" : "users", "type" : "array" }, { "name" : "options", "type" : "array", default: { groupname: "defaultgroup" } }, ], any other way to insert data on interactive mode .?

shreyu82 avatar Dec 19 '13 10:12 shreyu82

@shreyu82 @zzamboni I looked around for tools that implement this kind of editing and can't find any. Pointers and suggestions welcome so we know what kind of patterns already exist.

tzz avatar Dec 19 '13 13:12 tzz

I still think interactive parameter entry is not well suited for complex data structures, it's simply too error prone. The best would be to automatically put the user in an $EDITOR session with the JSON file preloaded, so they can edit the values. Upon exit, validate and if there are any errors, go back to the editor.

zzamboni avatar Dec 20 '13 23:12 zzamboni

I disagree from an ease of use standpoint. Answering questions or a menu based CLI interface is more intuitive, I think we should strive for a rich CLI interface. We could do the editor thing as a stopgap. Or have that first and then a config option that allows you to choose an interactive mode (when we have time to build it) or editor mode. On Dec 20, 2013 3:44 PM, "Diego Zamboni" [email protected] wrote:

I still think interactive parameter entry is not well suited for complex data structures, it's simply too error prone. The best would be to automatically put the user in an $EDITOR session with the JSON file preloaded, so they can edit the values. Upon exit, validate and if there are any errors, go back to the editor.

— Reply to this email directly or view it on GitHubhttps://github.com/cfengine/design-center/issues/240#issuecomment-31050133 .

nickanderson avatar Dec 20 '13 23:12 nickanderson

@zzamboni : but that array things works with Security::SSH modules how ? that is my questations.

see info of Security::SSH ketch Security::SSH Description: Configure and enable sshd Authors: Diego Zamboni [email protected], Ted Zlatanov [email protected] Version: 1.1 License: MIT Tags: cfdc Installed: Yes, under /var/cfengine/masterfiles/sketches Activated: No Parameters: For bundle sshd params: array

but but but it cant work for Security::security_limits & Users::Local

shreyu82 avatar Dec 23 '13 08:12 shreyu82

@shreyu82 the parameter types are different. In Security::SSH is a plain array of key/value pairs, whereas in Users::Local it's a list of arrays, and in Security::security_limits it's a nested array.

zzamboni avatar Dec 23 '13 16:12 zzamboni

@zzamboni but how to pass that nested array using interactive mode using cf-sketch cause i am using that mode only . so any video avaialable to pass or any method ? currently i impret them using .json file .

shreyu82 avatar Dec 24 '13 06:12 shreyu82

Users::Local it's a list of arrays, and in Security::security_limits it's a nested array. how to pass on non-interactive mode ? i passed using as mentioned below

cf-sketch> define params Users::Local

This sketch has multiple accessible bundles. 1. local(users, options) 2. runbased(checker, users, options) Which one do you want to configure? (1-2, Enter to cancel) 1 Please enter a name for the new parameter set (default: Users::Local-local-000): oracle Querying configuration for parameter set 'oracle' for bundle 'local'. Please enter parameter users. (enter STOP to cancel) Next key (Enter to finish): oracle users[oracle]: { 'Oracle user", 1001, 1002, /home/oracle, /bin/bash, 'test'} Next key (Enter to finish): Please enter parameter options. (enter STOP to cancel) Next key (Enter to finish)[groupname]: groupname options[groupname][defaultgroup]: oracle Next key (Enter to finish): Defining parameter set 'oracle' with the entered data.

Parameter set oracle successfully defined.

I attached jpg file too

user_local

" users[oracle]: { 'Oracle user", 1001, 1002, /home/oracle, /bin/bash, 'test'} " which is not work well .

shreyu82 avatar Dec 24 '13 09:12 shreyu82

As I said before, interactive mode in cf-sketch does not support complex data types. You need to store the parameters in a JSON file and load it by passing it as a second argument to the "define params" command, for example:

define params Users::Local /path/to/params.json

Most sketches include sample JSON parameter files under their params/ directory (for example, design-center/sketches/system/users_local/params/demo.json)

--Diego

On Dec 24, 2013, at 3:54 AM, shreyu82 [email protected] wrote:

Users::Local it's a list of arrays, and in Security::security_limits it's a nested array. how to pass on non-interactive mode ? i passed using as mentioned below

cf-sketch> define params Users::Local

This sketch has multiple accessible bundles.

  1. local(users, options)
  2. runbased(checker, users, options) Which one do you want to configure? (1-2, Enter to cancel) 1 Please enter a name for the new parameter set (default: Users::Local-local-000): oracle Querying configuration for parameter set 'oracle' for bundle 'local'. Please enter parameter users. (enter STOP to cancel) Next key (Enter to finish): oracle users[oracle]: { 'Oracle user", 1001, 1002, /home/oracle, /bin/bash, 'test'} Next key (Enter to finish): Please enter parameter options. (enter STOP to cancel) Next key (Enter to finish)[groupname]: groupname options[groupname][defaultgroup]: oracle Next key (Enter to finish): Defining parameter set 'oracle' with the entered data.

Parameter set oracle successfully defined.

I attached jpg file too

" users[oracle]: { 'Oracle user", 1001, 1002, /home/oracle, /bin/bash, 'test'} " which is not work well .

— Reply to this email directly or view it on GitHub.

zzamboni avatar Dec 30 '13 22:12 zzamboni

Okay thanks zzamboni. i also used it like below from non-interactive

/usr/local/bin/cf-sketch --expert --installsource=/var/cfengine/design-center/sketches/system/users_local/params/demo.json --cfpath=/var/cfengine/bin --test --activated --force --standalone --install CFEngine::stdlib --deactivate-all --generate -v --force --standalonerunfile /var/cfengine/inputs/standalone-cf-sketch-runfile.cf --install Utilities::abortclasses --activate Utilities::abortclasses=/var/cfengine/design-center/sketches/utilities/abortclasses/params/test_alert_only.json

Okay got you thanks zzamboni

shreyu82 avatar Jan 01 '14 08:01 shreyu82

Glad you got it working!

--Diego

On Jan 1, 2014, at 2:12 AM, shreyu82 [email protected] wrote:

Okay thanks zzamboni. i also used it like below from non-interactive

/usr/local/bin/cf-sketch --expert --installsource=/var/cfengine/design-center/sketches/system/users_local/params/demo.json --cfpath=/var/cfengine/bin --test --activated --force --standalone --install CFEngine::stdlib --deactivate-all --generate -v --force --standalonerunfile /var/cfengine/inputs/standalone-cf-sketch-runfile.cf --install Utilities::abortclasses --activate Utilities::abortclasses=/var/cfengine/design-center/sketches/utilities/abortclasses/params/test_alert_only.json

Okay got you thanks zzamboni

— Reply to this email directly or view it on GitHub.

zzamboni avatar Jan 07 '14 03:01 zzamboni

Yeah zzamboni but I am still try to find solution for how to pass variable value using nested arrays with interactive mode. ;-)

shreyu82 avatar Jan 07 '14 11:01 shreyu82

@zzamboni any idea why default lib : "manage_variable_values_ini" function not work well in CF3 .it return error while change value in php.ini value should be something like that [ SQL] sql.safe_mode = off ( i want "on" here but it delete whole line when i used "manage_variable_values_ini" function )

shreyu82 avatar Jan 07 '14 11:01 shreyu82

@zzamboni any idea how do i call folder in sketch.json under manifest block { "main.cf": { desc: "main file" }, "files/etc/init.d/firewall": { desc: "firewall init script" }, "files/etc/firewall/firewall": { desc: "firewall init script" }, "target": { "files/etc/firewall/conf.d/": "/etc/firewall/conf.d/" } }, but it gave error

shreyu82 avatar Jan 13 '14 10:01 shreyu82

any idea how it ?

shreyu82 avatar Jan 13 '14 10:01 shreyu82

Hi @shreyu82

The manifest currently does not support directories as an install target. For what you describe, you really want to do the copying to the final destination in the sketch itself.

tzz avatar Jan 15 '14 19:01 tzz