0

i use chef-api for express js and i wanna get only the ip address of node " server 1 " from a chef-server

im sending a request like this

Code :


chef.partialSearch("node", "name:server1",{"ip":"ipaddress"} ,function(err, res){

  if (err){console.log(error);}

  else{console.log(res);}

});

Or

chef.partialSearch("node", { q: "name:server1"} ,{"ip":"ipaddress"} ,function(err, res){
....
});

=> Response :

received status code 400 invalid  value 'ipaddress' for no_key

function in code source :

partialSearch: function(index, qs, data, fn){
            http_methods.post([config.host_url, "search", index].join("/"), qs, data, function(err, response){
                return fn(err, response);
            });
        }

and i cant understand the correct syntax for the request (http) from the official website doc api_chef_server
Can you please give a valid syntax with example . Thanks

1
  • Are you always planning to access a single node at a time? Commented Sep 22, 2016 at 22:15

2 Answers 2

0

What you probably want is something like this:

chef.getNode('server1', function(err, node) {
    if(err) throw err;
    console.log(node.automatic.ipaddress);
});
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks you for your reply , and yes its a solution if you wanna request for only one server but if you wanna get all " ipaddress " for all servers belongs to a " role " isnt a good pratice for the performance of your chef-server and even the time reply of the application take a look dougireton.com/blog/2013/01/19/get-chef-clients-by-version and engineering.voxer.com/2013/03/22/chef-part-2-performance and i found the correct syntax , Thanks again for your reply :D
That is correct, which is why I asked if you understated your use case :)
0

Finaly i found the correct syntax for both request

Simple Search :

    chef.search("node", {q: "name:server1" }, function(err, res){

       if (err){console.log(error);}

       else{console.log(res);}

     });

Partial Search :

chef.partialSearch("node", "chef_environment:prod", { name: ['name'] , 'ipaddress': ['ipaddress'] }, function(err, res){

        if (err){console.log(error);}

        else{console.log(res);}


    });

Hope this can help someone else who is still looking .

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.