Search code examples
chef-infraknifeknife-solo

knife delete command unable to remove weird node


I made a error with the bootstrap command and known I have node called -i and I will like to remove that node:

knife node list
-i

But when I try to run the delete command from knife this is the result:

knife node delete -i

Error: invalid option: -i
USAGE: knife node delete [NODE[,NODE]] (options)
    -s, --server-url URL             Chef Server URL
        --chef-zero-host HOST        Host to start chef-zero on
        --chef-zero-port PORT        Port (or port range) to start chef-zero on.  Port ranges like 1000,1010 or 8889-9999 will try all given ports until one works.
    -k, --key KEY                    API Client Key
        --[no-]color                 Use colored output, defaults to enabled
    -c, --config CONFIG              The configuration file to use
        --config-option OPTION=VALUE Override a single configuration option
        --defaults                   Accept default values for all questions
    -d, --disable-editing            Do not open EDITOR, just accept the data as is
    -e, --editor EDITOR              Set the editor to use for interactive commands
    -E, --environment ENVIRONMENT    Set the Chef environment (except for in searches, where this will be flagrantly ignored)
        --[no-]fips                  Enable fips mode
    -F, --format FORMAT              Which format to use for output
        --[no-]listen                Whether a local mode (-z) server binds to a port
    -z, --local-mode                 Point knife commands at local repository instead of server
    -u, --user USER                  API Client Username
        --print-after                Show the data after a destructive operation
    -V, --verbose                    More verbose output. Use twice for max verbosity
    -v, --version                    Show chef version
    -y, --yes                        Say yes to all prompts for confirmation
    -h, --help                       Show this message

So I am unable to delete this node.

Any suggestion?


Solution

  • With some kind of black magic and knife exec you can delete from command line like this:

    knife exec -E "nodes.search('name:*i') { |n| n.destroy if n.name == '-i' }"
    

    This will loop over all nodes with name ending with i, so it may take some time if you have a bunch of them, then it will destroy the node if it's name is exactly -i.

    If it's the result of a bootstrap you may have a client also, using clients instead of nodes should do.