How do I set a path for roles, environments, and data bags in my knife.rb?

The knife.rb lets you specify a cookbook_path.

I want to get the same effect for roles, environments, and data bags.

I have the following in my knife.rb file

current_dir = File.dirname(FILE)
cookbook_path ["#{current_dir}/…/cookbooks"]

the following don’t seem to work. :frowning:

role_path ["#{current_dir}/…/roles"]
environment_path ["#{current_dir}/…/environments"]
data_bag_path ["#{current_dir}/…/data_bags"]

I remember seeing how to do this somewhere along time ago, but I can’t find the original reference. I have been looking, and I see several references that strongly imply these should work, or something similar like making the object name plural (roles_path)

I have tried several permutations, including statements like knife[:role_path] = …, but nothing seems to work.

Is it possible What is the correct format?

Thanks in advance.


Stephen Corbesero, DevOps Engineer
Synchronoss - Mobile Innovation for a Connected World
stephen.corbesero@synchronoss.commailto:stephen.corbesero@synchronoss.com | www.synchronoss.comhttp://www.synchronoss.com

On Thu, Jan 8, 2015 at 9:13 AM, Stephen Corbesero
Stephen.Corbesero@synchronoss.com wrote:

The knife.rb lets you specify a cookbook_path.

I want to get the same effect for roles, environments, and data bags.

I have the following in my knife.rb file

current_dir = File.dirname(FILE)

cookbook_path ["#{current_dir}/../cookbooks"]

the following don't seem to work. :frowning:

role_path ["#{current_dir}/../roles"]

environment_path ["#{current_dir}/../environments"]

data_bag_path ["#{current_dir}/../data_bags"]

I remember seeing how to do this somewhere along time ago, but I can’t find
the original reference. I have been looking, and I see several references
that strongly imply these should work, or something similar like making the
object name plural (roles_path)

I have tried several permutations, including statements like
knife[:role_path] = …, but nothing seems to work.

Is it possible What is the correct format?

Thanks in advance.

--

Stephen Corbesero, DevOps Engineer

Synchronoss - Mobile Innovation for a Connected World

stephen.corbesero@synchronoss.com | www.synchronoss.com

Thanks for the link.. I am looking at it now.

According to my understanding of that code, it looks like it should be trying to set the default "top" to be the directory above the cookbooks path. I have two issues with that.

  1. The cookbook path is usually an array, not a simple string. I even made my cookbook path just a string, and it still failed.

  2. When I try to depend on a path for the other objects, I get an error message like the following:

      % knife environment from file dev.json 
      ERROR: Could not find or open file 'dev.json' in current directory or in 'environments/dev.json'
    

Which is implying that path it is using for the lookup is just "environments/" and not anything that I have set, or anything that knows about the top of the chef-repo

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:23 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How do I set a path for roles, environments, and data bags in my knife.rb?

On Thu, Jan 8, 2015 at 9:13 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

The knife.rb lets you specify a cookbook_path.

I want to get the same effect for roles, environments, and data bags.

I have the following in my knife.rb file

current_dir = File.dirname(FILE)

cookbook_path ["#{current_dir}/../cookbooks"]

the following don't seem to work. :frowning:

role_path ["#{current_dir}/../roles"]

environment_path ["#{current_dir}/../environments"]

data_bag_path ["#{current_dir}/../data_bags"]

I remember seeing how to do this somewhere along time ago, but I can’t
find the original reference. I have been looking, and I see several
references that strongly imply these should work, or something similar
like making the object name plural (roles_path)

I have tried several permutations, including statements like
knife[:role_path] = …, but nothing seems to work.

Is it possible What is the correct format?

Thanks in advance.

--

Stephen Corbesero, DevOps Engineer

Synchronoss - Mobile Innovation for a Connected World

stephen.corbesero@synchronoss.com | www.synchronoss.com

cookbook_path is indeed an array of strings or a string. when
chef_repo_path is set, it is inferred to be
chef_repo_path/cookbooks. otherwise it defaults to
[chef_repo_path/cookbooks, chef_repo_path/site-cookbooks]

$ knife upload environments/dev.json

'environment from file' takes a path to a file to upload. I used to
use it with shell loops:

$ for i in environments/*.json ; do knife environment from file $i ; done

I think chef_repo_path is what you are after. With that set correctly,
environments inferred default will be correct, e.g.
CHEF_REPO_PATH/environments.

hope this helps~

cheers,

--aj

On Thu, Jan 8, 2015 at 9:39 AM, Stephen Corbesero
Stephen.Corbesero@synchronoss.com wrote:

Thanks for the link.. I am looking at it now.

According to my understanding of that code, it looks like it should be trying to set the default "top" to be the directory above the cookbooks path. I have two issues with that.

  1. The cookbook path is usually an array, not a simple string. I even made my cookbook path just a string, and it still failed.

  2. When I try to depend on a path for the other objects, I get an error message like the following:

      % knife environment from file dev.json
      ERROR: Could not find or open file 'dev.json' in current directory or in 'environments/dev.json'
    

Which is implying that path it is using for the lookup is just "environments/" and not anything that I have set, or anything that knows about the top of the chef-repo

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:23 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How do I set a path for roles, environments, and data bags in my knife.rb?

https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L111-L128

On Thu, Jan 8, 2015 at 9:13 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

The knife.rb lets you specify a cookbook_path.

I want to get the same effect for roles, environments, and data bags.

I have the following in my knife.rb file

current_dir = File.dirname(FILE)

cookbook_path ["#{current_dir}/../cookbooks"]

the following don't seem to work. :frowning:

role_path ["#{current_dir}/../roles"]

environment_path ["#{current_dir}/../environments"]

data_bag_path ["#{current_dir}/../data_bags"]

I remember seeing how to do this somewhere along time ago, but I can’t
find the original reference. I have been looking, and I see several
references that strongly imply these should work, or something similar
like making the object name plural (roles_path)

I have tried several permutations, including statements like
knife[:role_path] = …, but nothing seems to work.

Is it possible What is the correct format?

Thanks in advance.

--

Stephen Corbesero, DevOps Engineer

Synchronoss - Mobile Innovation for a Connected World

stephen.corbesero@synchronoss.com | www.synchronoss.com

Being able to set chef_repo_path does look like the cleanest way. And it makes sense to know the top of the tree.

How do I set it in my knife config.

I just tried both of the following

chef_repo_path "#{current_dir}/.."
knife[:chef_repo_path] = "#{current_dir}/.."

where current_dir is expected to be the directory of my knife.rb, which is in .chef under the chef-repo.

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:48 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: How do I set a path for roles, environments, and data bags in my knife.rb?

cookbook_path is indeed an array of strings or a string. when
chef_repo_path is set, it is inferred to be
chef_repo_path/cookbooks. otherwise it defaults to
[chef_repo_path/cookbooks, chef_repo_path/site-cookbooks]

$ knife upload environments/dev.json

'environment from file' takes a path to a file to upload. I used to
use it with shell loops:

$ for i in environments/*.json ; do knife environment from file $i ; done

I think chef_repo_path is what you are after. With that set correctly,
environments inferred default will be correct, e.g.
CHEF_REPO_PATH/environments.

hope this helps~

cheers,

--aj

On Thu, Jan 8, 2015 at 9:39 AM, Stephen Corbesero
Stephen.Corbesero@synchronoss.com wrote:

Thanks for the link.. I am looking at it now.

According to my understanding of that code, it looks like it should be trying to set the default "top" to be the directory above the cookbooks path. I have two issues with that.

  1. The cookbook path is usually an array, not a simple string. I even made my cookbook path just a string, and it still failed.

  2. When I try to depend on a path for the other objects, I get an error message like the following:

      % knife environment from file dev.json
      ERROR: Could not find or open file 'dev.json' in current directory or in 'environments/dev.json'
    

Which is implying that path it is using for the lookup is just "environments/" and not anything that I have set, or anything that knows about the top of the chef-repo

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:23 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How do I set a path for roles, environments, and data bags in my knife.rb?

https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L111-L128

On Thu, Jan 8, 2015 at 9:13 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

The knife.rb lets you specify a cookbook_path.

I want to get the same effect for roles, environments, and data bags.

I have the following in my knife.rb file

current_dir = File.dirname(FILE)

cookbook_path ["#{current_dir}/../cookbooks"]

the following don't seem to work. :frowning:

role_path ["#{current_dir}/../roles"]

environment_path ["#{current_dir}/../environments"]

data_bag_path ["#{current_dir}/../data_bags"]

I remember seeing how to do this somewhere along time ago, but I can’t
find the original reference. I have been looking, and I see several
references that strongly imply these should work, or something similar
like making the object name plural (roles_path)

I have tried several permutations, including statements like
knife[:role_path] = …, but nothing seems to work.

Is it possible What is the correct format?

Thanks in advance.

--

Stephen Corbesero, DevOps Engineer

Synchronoss - Mobile Innovation for a Connected World

stephen.corbesero@synchronoss.com | www.synchronoss.com

Use Ruby's File#expand_path or similar to build the chef_repo_path by
expanding it. I doubt it understands the '..'.

You can use something like File.dirname(__FILE__) inside of knife.rb
to get the directory enclosing it, then join/expand from there.

cheers,

--aj

On Thu, Jan 8, 2015 at 10:03 AM, Stephen Corbesero
Stephen.Corbesero@synchronoss.com wrote:

Being able to set chef_repo_path does look like the cleanest way. And it makes sense to know the top of the tree.

How do I set it in my knife config.

I just tried both of the following

chef_repo_path "#{current_dir}/.."
knife[:chef_repo_path] = "#{current_dir}/.."

where current_dir is expected to be the directory of my knife.rb, which is in .chef under the chef-repo.

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:48 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: How do I set a path for roles, environments, and data bags in my knife.rb?

cookbook_path is indeed an array of strings or a string. when
chef_repo_path is set, it is inferred to be
chef_repo_path/cookbooks. otherwise it defaults to
[chef_repo_path/cookbooks, chef_repo_path/site-cookbooks]

$ knife upload environments/dev.json

'environment from file' takes a path to a file to upload. I used to
use it with shell loops:

$ for i in environments/*.json ; do knife environment from file $i ; done

I think chef_repo_path is what you are after. With that set correctly,
environments inferred default will be correct, e.g.
CHEF_REPO_PATH/environments.
https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L186

hope this helps~

cheers,

--aj

On Thu, Jan 8, 2015 at 9:39 AM, Stephen Corbesero
Stephen.Corbesero@synchronoss.com wrote:

Thanks for the link.. I am looking at it now.

According to my understanding of that code, it looks like it should be trying to set the default "top" to be the directory above the cookbooks path. I have two issues with that.

  1. The cookbook path is usually an array, not a simple string. I even made my cookbook path just a string, and it still failed.

  2. When I try to depend on a path for the other objects, I get an error message like the following:

      % knife environment from file dev.json
      ERROR: Could not find or open file 'dev.json' in current directory or in 'environments/dev.json'
    

Which is implying that path it is using for the lookup is just "environments/" and not anything that I have set, or anything that knows about the top of the chef-repo

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:23 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How do I set a path for roles, environments, and data bags in my knife.rb?

https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L111-L128

On Thu, Jan 8, 2015 at 9:13 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

The knife.rb lets you specify a cookbook_path.

I want to get the same effect for roles, environments, and data bags.

I have the following in my knife.rb file

current_dir = File.dirname(FILE)

cookbook_path ["#{current_dir}/../cookbooks"]

the following don't seem to work. :frowning:

role_path ["#{current_dir}/../roles"]

environment_path ["#{current_dir}/../environments"]

data_bag_path ["#{current_dir}/../data_bags"]

I remember seeing how to do this somewhere along time ago, but I can’t
find the original reference. I have been looking, and I see several
references that strongly imply these should work, or something similar
like making the object name plural (roles_path)

I have tried several permutations, including statements like
knife[:role_path] = …, but nothing seems to work.

Is it possible What is the correct format?

Thanks in advance.

--

Stephen Corbesero, DevOps Engineer

Synchronoss - Mobile Innovation for a Connected World

stephen.corbesero@synchronoss.com | www.synchronoss.com

I still not have any success....

I also found there is an optional knife[:repository ], but setting that ior knife[:chef_repo_path] had no effect.

I still find some references to a repo_path directive in the knife.rb file, even an implied mention to setting role paths by the esteemed Joshua Tiimberman at http://jtimberman.housepub.org/blog/2013/02/01/local-only-knife-configuration/

But nothing I have so far has worked.

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 4:08 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: RE: Re: How do I set a path for roles, environments, and data bags in my knife.rb?

Use Ruby's File#expand_path or similar to build the chef_repo_path by expanding it. I doubt it understands the '..'.

You can use something like File.dirname(__FILE__) inside of knife.rb to get the directory enclosing it, then join/expand from there.

cheers,

--aj

On Thu, Jan 8, 2015 at 10:03 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

Being able to set chef_repo_path does look like the cleanest way. And it makes sense to know the top of the tree.

How do I set it in my knife config.

I just tried both of the following

chef_repo_path "#{current_dir}/.."
knife[:chef_repo_path] = "#{current_dir}/.."

where current_dir is expected to be the directory of my knife.rb, which is in .chef under the chef-repo.

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:48 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: How do I set a path for roles, environments, and data bags in my knife.rb?

cookbook_path is indeed an array of strings or a string. when
chef_repo_path is set, it is inferred to be
chef_repo_path/cookbooks. otherwise it defaults to
[chef_repo_path/cookbooks, chef_repo_path/site-cookbooks]

$ knife upload environments/dev.json

'environment from file' takes a path to a file to upload. I used to
use it with shell loops:

$ for i in environments/*.json ; do knife environment from file $i ;
done

I think chef_repo_path is what you are after. With that set correctly,
environments inferred default will be correct, e.g.
CHEF_REPO_PATH/environments.
https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L186

hope this helps~

cheers,

--aj

On Thu, Jan 8, 2015 at 9:39 AM, Stephen Corbesero
Stephen.Corbesero@synchronoss.com wrote:

Thanks for the link.. I am looking at it now.

According to my understanding of that code, it looks like it should be trying to set the default "top" to be the directory above the cookbooks path. I have two issues with that.

  1. The cookbook path is usually an array, not a simple string. I even made my cookbook path just a string, and it still failed.

  2. When I try to depend on a path for the other objects, I get an error message like the following:

      % knife environment from file dev.json
      ERROR: Could not find or open file 'dev.json' in current directory or in 'environments/dev.json'
    

Which is implying that path it is using for the lookup is just
"environments/" and not anything that I have set, or anything that
knows about the top of the chef-repo

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:23 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How do I set a path for roles, environments, and data bags in my knife.rb?

https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L111-L
128

On Thu, Jan 8, 2015 at 9:13 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

The knife.rb lets you specify a cookbook_path.

I want to get the same effect for roles, environments, and data bags.

I have the following in my knife.rb file

current_dir = File.dirname(FILE)

cookbook_path ["#{current_dir}/../cookbooks"]

the following don't seem to work. :frowning:

role_path ["#{current_dir}/../roles"]

environment_path ["#{current_dir}/../environments"]

data_bag_path ["#{current_dir}/../data_bags"]

I remember seeing how to do this somewhere along time ago, but I
can’t find the original reference. I have been looking, and I see
several references that strongly imply these should work, or
something similar like making the object name plural (roles_path)

I have tried several permutations, including statements like
knife[:role_path] = …, but nothing seems to work.

Is it possible What is the correct format?

Thanks in advance.

--

Stephen Corbesero, DevOps Engineer

Synchronoss - Mobile Innovation for a Connected World

stephen.corbesero@synchronoss.com | www.synchronoss.com

What version of chef? gist your knife.rb

cheers,

--aj

On Sat, Jan 10, 2015 at 8:46 AM, Stephen Corbesero
Stephen.Corbesero@synchronoss.com wrote:

I still not have any success....

I also found there is an optional knife[:repository ], but setting that ior knife[:chef_repo_path] had no effect.

I still find some references to a repo_path directive in the knife.rb file, even an implied mention to setting role paths by the esteemed Joshua Tiimberman at http://jtimberman.housepub.org/blog/2013/02/01/local-only-knife-configuration/

But nothing I have so far has worked.

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 4:08 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: RE: Re: How do I set a path for roles, environments, and data bags in my knife.rb?

Use Ruby's File#expand_path or similar to build the chef_repo_path by expanding it. I doubt it understands the '..'.

You can use something like File.dirname(__FILE__) inside of knife.rb to get the directory enclosing it, then join/expand from there.

cheers,

--aj

On Thu, Jan 8, 2015 at 10:03 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

Being able to set chef_repo_path does look like the cleanest way. And it makes sense to know the top of the tree.

How do I set it in my knife config.

I just tried both of the following

chef_repo_path "#{current_dir}/.."
knife[:chef_repo_path] = "#{current_dir}/.."

where current_dir is expected to be the directory of my knife.rb, which is in .chef under the chef-repo.

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:48 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: How do I set a path for roles, environments, and data bags in my knife.rb?

cookbook_path is indeed an array of strings or a string. when
chef_repo_path is set, it is inferred to be
chef_repo_path/cookbooks. otherwise it defaults to
[chef_repo_path/cookbooks, chef_repo_path/site-cookbooks]

$ knife upload environments/dev.json

'environment from file' takes a path to a file to upload. I used to
use it with shell loops:

$ for i in environments/*.json ; do knife environment from file $i ;
done

I think chef_repo_path is what you are after. With that set correctly,
environments inferred default will be correct, e.g.
CHEF_REPO_PATH/environments.
https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L186

hope this helps~

cheers,

--aj

On Thu, Jan 8, 2015 at 9:39 AM, Stephen Corbesero
Stephen.Corbesero@synchronoss.com wrote:

Thanks for the link.. I am looking at it now.

According to my understanding of that code, it looks like it should be trying to set the default "top" to be the directory above the cookbooks path. I have two issues with that.

  1. The cookbook path is usually an array, not a simple string. I even made my cookbook path just a string, and it still failed.

  2. When I try to depend on a path for the other objects, I get an error message like the following:

      % knife environment from file dev.json
      ERROR: Could not find or open file 'dev.json' in current directory or in 'environments/dev.json'
    

Which is implying that path it is using for the lookup is just
"environments/" and not anything that I have set, or anything that
knows about the top of the chef-repo

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:23 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How do I set a path for roles, environments, and data bags in my knife.rb?

https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L111-L
128

On Thu, Jan 8, 2015 at 9:13 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

The knife.rb lets you specify a cookbook_path.

I want to get the same effect for roles, environments, and data bags.

I have the following in my knife.rb file

current_dir = File.dirname(FILE)

cookbook_path ["#{current_dir}/../cookbooks"]

the following don't seem to work. :frowning:

role_path ["#{current_dir}/../roles"]

environment_path ["#{current_dir}/../environments"]

data_bag_path ["#{current_dir}/../data_bags"]

I remember seeing how to do this somewhere along time ago, but I
can’t find the original reference. I have been looking, and I see
several references that strongly imply these should work, or
something similar like making the object name plural (roles_path)

I have tried several permutations, including statements like
knife[:role_path] = …, but nothing seems to work.

Is it possible What is the correct format?

Thanks in advance.

--

Stephen Corbesero, DevOps Engineer

Synchronoss - Mobile Innovation for a Connected World

stephen.corbesero@synchronoss.com | www.synchronoss.com

I have done a little more digging, and here is what I have concluded.

Short answer: knife can't do what I want.

Long answers..

The chef_repo_path seems to only be relevant to the upload and download subcommands

The role_path directive was only recognized by spork. It was not a standard knife feature.

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Friday, January 09, 2015 3:04 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: RE: Re: RE: Re: How do I set a path for roles, environments, and data bags in my knife.rb?

What version of chef? gist your knife.rb

cheers,

--aj

On Sat, Jan 10, 2015 at 8:46 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

I still not have any success....

I also found there is an optional knife[:repository ], but setting that ior knife[:chef_repo_path] had no effect.

I still find some references to a repo_path directive in the knife.rb file, even an implied mention to setting role paths by the esteemed Joshua Tiimberman at http://jtimberman.housepub.org/blog/2013/02/01/local-only-knife-configuration/

But nothing I have so far has worked.

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 4:08 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: RE: Re: How do I set a path for roles, environments, and data bags in my knife.rb?

Use Ruby's File#expand_path or similar to build the chef_repo_path by expanding it. I doubt it understands the '..'.

You can use something like File.dirname(__FILE__) inside of knife.rb to get the directory enclosing it, then join/expand from there.

cheers,

--aj

On Thu, Jan 8, 2015 at 10:03 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

Being able to set chef_repo_path does look like the cleanest way. And it makes sense to know the top of the tree.

How do I set it in my knife config.

I just tried both of the following

chef_repo_path "#{current_dir}/.."
knife[:chef_repo_path] = "#{current_dir}/.."

where current_dir is expected to be the directory of my knife.rb, which is in .chef under the chef-repo.

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:48 PM
To: chef@lists.opscode.com
Subject: [chef] Re: RE: Re: How do I set a path for roles, environments, and data bags in my knife.rb?

cookbook_path is indeed an array of strings or a string. when
chef_repo_path is set, it is inferred to be
chef_repo_path/cookbooks. otherwise it defaults to
[chef_repo_path/cookbooks, chef_repo_path/site-cookbooks]

$ knife upload environments/dev.json

'environment from file' takes a path to a file to upload. I used to
use it with shell loops:

$ for i in environments/*.json ; do knife environment from file $i ;
done

I think chef_repo_path is what you are after. With that set
correctly, environments inferred default will be correct, e.g.
CHEF_REPO_PATH/environments.
https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L186

hope this helps~

cheers,

--aj

On Thu, Jan 8, 2015 at 9:39 AM, Stephen Corbesero
Stephen.Corbesero@synchronoss.com wrote:

Thanks for the link.. I am looking at it now.

According to my understanding of that code, it looks like it should be trying to set the default "top" to be the directory above the cookbooks path. I have two issues with that.

  1. The cookbook path is usually an array, not a simple string. I even made my cookbook path just a string, and it still failed.

  2. When I try to depend on a path for the other objects, I get an error message like the following:

      % knife environment from file dev.json
      ERROR: Could not find or open file 'dev.json' in current directory or in 'environments/dev.json'
    

Which is implying that path it is using for the lookup is just
"environments/" and not anything that I have set, or anything that
knows about the top of the chef-repo

--
Stephen Corbesero, DevOps Engineer

-----Original Message-----
From: AJ Christensen [mailto:aj@junglistheavy.industries]
Sent: Wednesday, January 07, 2015 3:23 PM
To: chef@lists.opscode.com
Subject: [chef] Re: How do I set a path for roles, environments, and data bags in my knife.rb?

https://github.com/opscode/chef/blob/master/lib/chef/config.rb#L111-
L
128

On Thu, Jan 8, 2015 at 9:13 AM, Stephen Corbesero Stephen.Corbesero@synchronoss.com wrote:

The knife.rb lets you specify a cookbook_path.

I want to get the same effect for roles, environments, and data bags.

I have the following in my knife.rb file

current_dir = File.dirname(FILE)

cookbook_path ["#{current_dir}/../cookbooks"]

the following don't seem to work. :frowning:

role_path ["#{current_dir}/../roles"]

environment_path ["#{current_dir}/../environments"]

data_bag_path ["#{current_dir}/../data_bags"]

I remember seeing how to do this somewhere along time ago, but I
can’t find the original reference. I have been looking, and I see
several references that strongly imply these should work, or
something similar like making the object name plural (roles_path)

I have tried several permutations, including statements like
knife[:role_path] = …, but nothing seems to work.

Is it possible What is the correct format?

Thanks in advance.

--

Stephen Corbesero, DevOps Engineer

Synchronoss - Mobile Innovation for a Connected World

stephen.corbesero@synchronoss.com | www.synchronoss.com