.. versionadded:: 0.17.0 Remove a value from a list in the grains config file key The grain key to remove. val The value to remove. delimiter The key can be a nested dict key. Use this parameter to specify the delimiter you use, instead of the
(key, val, delimiter=DEFAULT_TARGET_DELIM)
| 383 | |
| 384 | |
| 385 | def remove(key, val, delimiter=DEFAULT_TARGET_DELIM): |
| 386 | """ |
| 387 | .. versionadded:: 0.17.0 |
| 388 | |
| 389 | Remove a value from a list in the grains config file |
| 390 | |
| 391 | key |
| 392 | The grain key to remove. |
| 393 | |
| 394 | val |
| 395 | The value to remove. |
| 396 | |
| 397 | delimiter |
| 398 | The key can be a nested dict key. Use this parameter to |
| 399 | specify the delimiter you use, instead of the default ``:``. |
| 400 | You can now append values to a list in nested dictionary grains. If the |
| 401 | list doesn't exist at this level, it will be created. |
| 402 | |
| 403 | .. versionadded:: 2015.8.2 |
| 404 | |
| 405 | CLI Example: |
| 406 | |
| 407 | .. code-block:: bash |
| 408 | |
| 409 | salt '*' grains.remove key val |
| 410 | """ |
| 411 | grains = get(key, [], delimiter) |
| 412 | if not isinstance(grains, list): |
| 413 | return f"The key {key} is not a valid list" |
| 414 | if val not in grains: |
| 415 | return f"The val {val} was not in the list {key}" |
| 416 | grains.remove(val) |
| 417 | |
| 418 | while delimiter in key: |
| 419 | key, rest = key.rsplit(delimiter, 1) |
| 420 | _grain = get(key, None, delimiter) |
| 421 | if isinstance(_grain, dict): |
| 422 | _grain.update({rest: grains}) |
| 423 | grains = _grain |
| 424 | |
| 425 | return setval(key, grains) |
| 426 | |
| 427 | |
| 428 | def delkey(key, force=False): |