March 22, 2017

Why doesn’t `knife upload roles` upload any roles?

Josh Gagnon’s Question:

I followed the OpsCode quickstart guide and things went fairly smoothly, but now I’m running into issues experimenting with roles. I have a “starter” role in my repo that was provided by OpsCode. When I follow the first official documentation I could find and run the following from the top of my chef repo:

knife upload roles

it simply returns and nothing happens. I get no role (new or updated) on my chef server. The following line does work for creation and updating:

knife role from file .rolesstarter.rb

but I find it overly cumbersome and I would prefer something that just pushes my entire repo up to the server (or at least all of the roles) to make me more confident that everything is up to date.

Yeah, in this case Chef is a little bit inconsistent. I use the next 3 lines to push by whole repo to chef-server (of course after the tests have passed):

knife cookbook upload --all
knife role from file roles/*.rb
knife data bag from file --all

Suggested solution from Draco, didn’t work for me to upload the data_bags. Here is what I did.

knife cookbook upload --all
knife role from file roles/*.rb
knife upload data_bags/

March 4, 2017

MAX in PHP returning wrong value

Krish’s Question:

I have an array with key and value pair. I’m building this array dynamically and below is the code.

$x[] = array('type_name' => $value->name,
            'percentage'=> intval($percentage));

My intention is to get the maximum value and for that I do

max($x);

However it is returning the wrong value actually the lowest value. Following is my array. Any help would be awesome.

Thanks is advance.

You need to read how the max compares against different types of data. In your case, you are trying to compare against one of the array item i.e. percentage inside one of the item so the function max does not know to do this.

There is an example by Revo in the manual which shows you how to do this.

...

Please fill the form - I will response as fast as I can!