Closed ColonelPanicks closed 5 years ago
Some background on configure --answers
would probably be useful: IIRC this command was originally added when I created the prototype Metalware GUI, to allow the GUI to configure answers from an external perspective via the usual commands, since the usual configure
process requires repeated user interaction. This is the main reason why the new answers must all be passed and these then replace the existing answers file, as all the new or unchanged answers are intended to be provided at once via a web form submission.
Additionally, I don't think the --answers
-passed answers could be merged with the answers already in the file before updating it, as this means there would be no way to unset answers - once an answer key was in the answers file, using just --answers
would then allow this to be set to false
/null
/""
etc., or it could be left unchanged by not passing it to --answers
, but there's no way by just passing JSON which will be merged with some other JSON to specify a key to be removed.
Given both the above points, having a way to just update rather than replace answers may be useful but goes beyond the previous requirement and possibly should be done via a different option from this (or maybe we can accept that this change would prevent removing keys entirely, not sure if doing this will prevent some use cases). If we do determine that this is a new feature we want to add lets reopen this issue/open a new issue where we can discuss and prioritise making this change. :slightly_smiling_face:.
Until then, you could achieve a similar effect using the current --answers
by doing something like this:
Given an answers file at /var/lib/metalware/answers/nodes/stunode01.yaml
like:
foo: 'foo'
bar: 'bar'
and that you have yq
installed (like jq
but for YAML);
then the following command:
metal configure node stunode01 --answers "$(yq '.foo |= "newFoo"' /var/lib/metalware/answers/nodes/stunode01.yaml --compact-output)"
should be equivalent to:
metal configure node --answers '{"foo": "newFoo", "bar": "bar"}'
but without needing to re-specify the unchanged key.
(Not actually tested this on a running version of Metalware but in principle this should work, even if I've messed up the quoting or something. You should be able to generalize this to updating more answers at once).
We need some sort of solution to this problem as it's come up for me again (where answers are being too destructive) so reopened for further discussion
@ColonelPanicks what's inadequate with using the workaround suggested above? :slightly_smiling_face:
It's cumbersome, requires jq
to be installed and we'll be pretty much always be using that workaround because there's no use case (as far as my side of using metalware goes) where this behaviour is beneficial
OK, thanks - since configure
will likely be moved as part of the re-architecting for underware
, when that occurs we can consider if/how/when things should change to support your use case.
What are your thoughts on something like having options like metal configure node --set-answer "foo" "newFoo" --remove-answer "bar"
to support this? This also allows us to handle the use case of removing already set answers, and removes the need to unnecessarily create JSON to be used for setting answers.
Alternatively if there's a reason to prefer this we could just change --answers
to add to rather than replace the current answers, since the original use case (the Metalware GUI) for the current behaviour now seems obsolete. We would still need a --remove-answer
option (or equivalent) to support that use case though.
This issue was moved to alces-software/underware#2
When using
--answers
it completely removes everything from the answers file and replaces it with only the provided info, this seems oddly destructive instead of just modifying the existing answers (if any)