Chef repo environment variable?

Hello,

I have been wondering, but couldn’t find anything on the interwebs… Is there a way to point knife to the correct chef-repo path via an environment variable, say CHEF_HOME, or CHEF_REPO?

The reason I ask is that I have several contexts in my workstation (work, private project 1, private project 2, …). I use shell aliases to set several environment variables for each context (AWS keys and paths, other stuff), and when I open a new shell I just call the alias to set the context.

Any pointers?

Thanks!

Cassiano Leal

Simplest thing would likely be to add the following to your knife.rb:

cookbook_path ENV[‘CHEF_REPO’]

Thhis would set your cookbook path to the value of the CHEF_REPO variable in your environment.

You could also set a default in case you don’t have it set:

cb_path = ENV[‘CHEF_REPO’] || ~/cookbooks
cookbook_path cb_path

From: Cassiano Leal [mailto:cassianoleal@gmail.com]
Sent: 26 July 2012 13:17
To: chef@lists.opscode.com
Subject: [chef] Chef repo environment variable?

Hello,

I have been wondering, but couldn’t find anything on the interwebs… Is there a way to point knife to the correct chef-repo path via an environment variable, say CHEF_HOME, or CHEF_REPO?

The reason I ask is that I have several contexts in my workstation (work, private project 1, private project 2, …). I use shell aliases to set several environment variables for each context (AWS keys and paths, other stuff), and when I open a new shell I just call the alias to set the context.

Any pointers?

Thanks!

Cassiano Leal

Thanks,
Jon-Paul Sullivan :slight_smile: Cloud Services - @hpcloud

Postal Address: Hewlett-Packard Galway Limited, Ballybrit Business Park, Galway.
Registered Office: Hewlett-Packard Galway Limited, 63-74 Sir John Rogerson’s Quay, Dublin 2.
Registered Number: 361933

The contents of this message and any attachments to it are confidential and may be legally privileged. If you have received this message in error you should delete it from your system immediately and advise the sender.

To any recipient of this message within HP, unless otherwise stated, you should consider this message and attachments as “HP CONFIDENTIAL”.

Interesting. I would have liked for knife to know where knife.rb is located based on that environment variable, though.

Any way to tell knife where to find knife.rb? I have different knife.rb's for each context. :slight_smile:

On Thursday, 26 July 2012 at 09:32, Sullivan, Jon Paul wrote:

Simplest thing would likely be to add the following to your knife.rb:

cookbook_path ENV[‘CHEF_REPO’]

Thhis would set your cookbook path to the value of the CHEF_REPO variable in your environment.

You could also set a default in case you don’t have it set:

cb_path = ENV[‘CHEF_REPO’] || ~/cookbooks

cookbook_path cb_path

From: Cassiano Leal [mailto:cassianoleal@gmail.com]
Sent: 26 July 2012 13:17
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Subject: [chef] Chef repo environment variable?

Hello,

I have been wondering, but couldn't find anything on the interwebs… Is there a way to point knife to the correct chef-repo path via an environment variable, say CHEF_HOME, or CHEF_REPO?

The reason I ask is that I have several contexts in my workstation (work, private project 1, private project 2, …). I use shell aliases to set several environment variables for each context (AWS keys and paths, other stuff), and when I open a new shell I just call the alias to set the context.

Any pointers?

Thanks!

--

Cassiano Leal

Thanks,
Jon-Paul Sullivan J Cloud Services - @hpcloud

Postal Address: Hewlett-Packard Galway Limited, Ballybrit Business Park, Galway.

Registered Office: Hewlett-Packard Galway Limited, 63-74 Sir John Rogerson's Quay, Dublin 2.

Registered Number: 361933

The contents of this message and any attachments to it are confidential and may be legally privileged. If you have received this message in error you should delete it from your system immediately and advise the sender.

To any recipient of this message within HP, unless otherwise stated, you should consider this message and attachments as "HP CONFIDENTIAL".

If I'm understanding correctly, this should do it:

knife -c $CHEF_HOME/knife.rb
(Or depending on CHEF_HOME, .chef/knife.rb)

Sent from my mobile device

-----Original Message-----
From: Cassiano Leal cassianoleal@gmail.com
Date: Thu, 26 Jul 2012 10:16:11
To: chef@lists.opscode.com
Reply-To: chef@lists.opscode.com
Subject: [chef] Re: RE: Chef repo environment variable?

Interesting. I would have liked for knife to know where knife.rb is located based on that environment variable, though.

Any way to tell knife where to find knife.rb? I have different knife.rb's for each context. :slight_smile:

On Thursday, 26 July 2012 at 09:32, Sullivan, Jon Paul wrote:

Simplest thing would likely be to add the following to your knife.rb:

cookbook_path ENV[‘CHEF_REPO’]

Thhis would set your cookbook path to the value of the CHEF_REPO variable in your environment.

You could also set a default in case you don’t have it set:

cb_path = ENV[‘CHEF_REPO’] || ~/cookbooks

cookbook_path cb_path

From: Cassiano Leal [mailto:cassianoleal@gmail.com]
Sent: 26 July 2012 13:17
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Subject: [chef] Chef repo environment variable?

Hello,

I have been wondering, but couldn't find anything on the interwebs… Is there a way to point knife to the correct chef-repo path via an environment variable, say CHEF_HOME, or CHEF_REPO?

The reason I ask is that I have several contexts in my workstation (work, private project 1, private project 2, …). I use shell aliases to set several environment variables for each context (AWS keys and paths, other stuff), and when I open a new shell I just call the alias to set the context.

Any pointers?

Thanks!

--

Cassiano Leal

Thanks,
Jon-Paul Sullivan J Cloud Services - @hpcloud

Postal Address: Hewlett-Packard Galway Limited, Ballybrit Business Park, Galway.

Registered Office: Hewlett-Packard Galway Limited, 63-74 Sir John Rogerson's Quay, Dublin 2.

Registered Number: 361933

The contents of this message and any attachments to it are confidential and may be legally privileged. If you have received this message in error you should delete it from your system immediately and advise the sender.

To any recipient of this message within HP, unless otherwise stated, you should consider this message and attachments as "HP CONFIDENTIAL".

Bingo. It's so obvious it went right past me. :slight_smile:

Thanks for that, I'll alias knife to that command!

--
Cassiano Leal

On Thursday, 26 July 2012 at 10:23, Marc A Paradise wrote:

If I'm understanding correctly, this should do it:

knife -c $CHEF_HOME/knife.rb
(Or depending on CHEF_HOME, .chef/knife.rb)

Sent from my mobile device
From: Cassiano Leal <cassianoleal@gmail.com (mailto:cassianoleal@gmail.com)>
Date: Thu, 26 Jul 2012 10:16:11 -0300
To: <chef@lists.opscode.com (mailto:chef@lists.opscode.com)>
ReplyTo: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Subject: [chef] Re: RE: Chef repo environment variable?

Interesting. I would have liked for knife to know where knife.rb is located based on that environment variable, though.

Any way to tell knife where to find knife.rb? I have different knife.rb's for each context. :slight_smile:

On Thursday, 26 July 2012 at 09:32, Sullivan, Jon Paul wrote:

Simplest thing would likely be to add the following to your knife.rb:

cookbook_path ENV[‘CHEF_REPO’]

Thhis would set your cookbook path to the value of the CHEF_REPO variable in your environment.

You could also set a default in case you don’t have it set:

cb_path = ENV[‘CHEF_REPO’] || ~/cookbooks

cookbook_path cb_path

From: Cassiano Leal [mailto:cassianoleal@gmail.com]
Sent: 26 July 2012 13:17
To: chef@lists.opscode.com (mailto:chef@lists.opscode.com)
Subject: [chef] Chef repo environment variable?

Hello,

I have been wondering, but couldn't find anything on the interwebs… Is there a way to point knife to the correct chef-repo path via an environment variable, say CHEF_HOME, or CHEF_REPO?

The reason I ask is that I have several contexts in my workstation (work, private project 1, private project 2, …). I use shell aliases to set several environment variables for each context (AWS keys and paths, other stuff), and when I open a new shell I just call the alias to set the context.

Any pointers?

Thanks!

--

Cassiano Leal

Thanks,
Jon-Paul Sullivan J Cloud Services - @hpcloud

Postal Address: Hewlett-Packard Galway Limited, Ballybrit Business Park, Galway.

Registered Office: Hewlett-Packard Galway Limited, 63-74 Sir John Rogerson's Quay, Dublin 2.

Registered Number: 361933

The contents of this message and any attachments to it are confidential and may be legally privileged. If you have received this message in error you should delete it from your system immediately and advise the sender.

To any recipient of this message within HP, unless otherwise stated, you should consider this message and attachments as "HP CONFIDENTIAL".

.chef works like a standard unix dotfile, so my preference is to have a knife directory in each project, and symlink .chef => knife in each project.

When you use knife it will look first in your current working directory for a .chef folder, and then the parent directory recursively until it finds one.

Cheerio,

Michael Johnston
lastobelus@mac.com

On 2012-07-26, at 5:32 AM, Sullivan, Jon Paul wrote:

Simplest thing would likely be to add the following to your knife.rb:

cookbook_path ENV[‘CHEF_REPO’]

Thhis would set your cookbook path to the value of the CHEF_REPO variable in your environment.

You could also set a default in case you don’t have it set:

cb_path = ENV[‘CHEF_REPO’] || ~/cookbooks
cookbook_path cb_path

From: Cassiano Leal [mailto:cassianoleal@gmail.com]
Sent: 26 July 2012 13:17
To: chef@lists.opscode.com
Subject: [chef] Chef repo environment variable?

Hello,

I have been wondering, but couldn't find anything on the interwebs… Is there a way to point knife to the correct chef-repo path via an environment variable, say CHEF_HOME, or CHEF_REPO?

The reason I ask is that I have several contexts in my workstation (work, private project 1, private project 2, …). I use shell aliases to set several environment variables for each context (AWS keys and paths, other stuff), and when I open a new shell I just call the alias to set the context.

Any pointers?

Thanks!

Cassiano Leal

Thanks,
Jon-Paul Sullivan J Cloud Services - @hpcloud

Postal Address: Hewlett-Packard Galway Limited, Ballybrit Business Park, Galway.
Registered Office: Hewlett-Packard Galway Limited, 63-74 Sir John Rogerson's Quay, Dublin 2.
Registered Number: 361933

The contents of this message and any attachments to it are confidential and may be legally privileged. If you have received this message in error you should delete it from your system immediately and advise the sender.

To any recipient of this message within HP, unless otherwise stated, you should consider this message and attachments as "HP CONFIDENTIAL".

I wrote this shell script and threw it on my PATH to swap knife configs
between servers:

I create directories in this format: ~/.chef-SERVERNAME

I run knife-config SERVERNAME to swap to the server I want and it creates
the correct symlink.

Josiah

On Thu, Jul 26, 2012 at 2:43 PM, Michael Johnston lastobelus@mac.comwrote:

.chef works like a standard unix dotfile, so my preference is to have a
knife directory in each project, and symlink .chef => knife in each project.

When you use knife it will look first in your current working directory
for a .chef folder, and then the parent directory recursively until it
finds one.

Cheerio,

Michael Johnston
lastobelus@mac.com

On 2012-07-26, at 5:32 AM, Sullivan, Jon Paul wrote:

Simplest thing would likely be to add the following to your knife.rb:****


cookbook_path ENV[‘CHEF_REPO’]****


Thhis would set your cookbook path to the value of the CHEF_REPO variable
in your environment.****


You could also set a default in case you don’t have it set:****


cb_path = ENV[‘CHEF_REPO’] || ~/cookbooks****
cookbook_path cb_path****


From: Cassiano Leal [mailto:cassianoleal@gmail.com]
Sent: 26 July 2012 13:17
To: chef@lists.opscode.com
Subject: [chef] Chef repo environment variable?****


Hello,****


I have been wondering, but couldn't find anything on the interwebs… Is
there a way to point knife to the correct chef-repo path via an environment
variable, say CHEF_HOME, or CHEF_REPO?****


The reason I ask is that I have several contexts in my workstation (work,
private project 1, private project 2, …). I use shell aliases to set
several environment variables for each context (AWS keys and paths, other
stuff), and when I open a new shell I just call the alias to set the
context. ****


Any pointers?****


Thanks!****
-- ****
Cassiano Leal****


Thanks,
Jon-Paul Sullivan J Cloud Services - @hpcloud****
****
Postal Address: Hewlett-Packard Galway Limited, Ballybrit Business Park,
Galway.****
Registered Office: Hewlett-Packard Galway Limited, 63-74 Sir John
Rogerson's Quay, Dublin 2.****
Registered Number: 361933****


The contents of this message and any attachments to it are confidential
and may be legally privileged. If you have received this message in error
you should delete it from your system immediately and advise the sender.**
**


To any recipient of this message within HP, unless otherwise stated, you
should consider this message and attachments as "HP CONFIDENTIAL".****

Check out knife-block, that is what I use and like it a lot.

-- Jay

On Jul 26, 2012, at 6:35 PM, Josiah Kiehl bluepojo@gmail.com wrote:

I wrote this shell script and threw it on my PATH to swap knife configs between servers:

Shell script to swap knife configs · GitHub

I create directories in this format: ~/.chef-SERVERNAME

I run knife-config SERVERNAME to swap to the server I want and it creates the correct symlink.

Josiah

On Thu, Jul 26, 2012 at 2:43 PM, Michael Johnston lastobelus@mac.com wrote:
.chef works like a standard unix dotfile, so my preference is to have a knife directory in each project, and symlink .chef => knife in each project.

When you use knife it will look first in your current working directory for a .chef folder, and then the parent directory recursively until it finds one.

Cheerio,

Michael Johnston
lastobelus@mac.com

On 2012-07-26, at 5:32 AM, Sullivan, Jon Paul wrote:

Simplest thing would likely be to add the following to your knife.rb:

cookbook_path ENV[‘CHEF_REPO’]

Thhis would set your cookbook path to the value of the CHEF_REPO variable in your environment.

You could also set a default in case you don’t have it set:

cb_path = ENV[‘CHEF_REPO’] || ~/cookbooks
cookbook_path cb_path

From: Cassiano Leal [mailto:cassianoleal@gmail.com]
Sent: 26 July 2012 13:17
To: chef@lists.opscode.com
Subject: [chef] Chef repo environment variable?

Hello,

I have been wondering, but couldn't find anything on the interwebs… Is there a way to point knife to the correct chef-repo path via an environment variable, say CHEF_HOME, or CHEF_REPO?

The reason I ask is that I have several contexts in my workstation (work, private project 1, private project 2, …). I use shell aliases to set several environment variables for each context (AWS keys and paths, other stuff), and when I open a new shell I just call the alias to set the context.

Any pointers?

Thanks!

Cassiano Leal

Thanks,
Jon-Paul Sullivan J Cloud Services - @hpcloud

Postal Address: Hewlett-Packard Galway Limited, Ballybrit Business Park, Galway.
Registered Office: Hewlett-Packard Galway Limited, 63-74 Sir John Rogerson's Quay, Dublin 2.
Registered Number: 361933

The contents of this message and any attachments to it are confidential and may be legally privileged. If you have received this message in error you should delete it from your system immediately and advise the sender.

To any recipient of this message within HP, unless otherwise stated, you should consider this message and attachments as "HP CONFIDENTIAL".

Also you might find this gist [0] form Eric Wolfe useful.

[0] multi-knife-howto · GitHub

--
Jorge Espada

On Thu, Jul 26, 2012 at 7:39 PM, Jason Perry bosoxjay@gmail.com wrote:

Check out knife-block, that is what I use and like it a lot.

-- Jay

On Jul 26, 2012, at 6:35 PM, Josiah Kiehl bluepojo@gmail.com wrote:

I wrote this shell script and threw it on my PATH to swap knife configs
between servers:

Shell script to swap knife configs · GitHub

I create directories in this format: ~/.chef-SERVERNAME

I run knife-config SERVERNAME to swap to the server I want and it creates
the correct symlink.

Josiah

On Thu, Jul 26, 2012 at 2:43 PM, Michael Johnston lastobelus@mac.com
wrote:

.chef works like a standard unix dotfile, so my preference is to have a
knife directory in each project, and symlink .chef => knife in each project.

When you use knife it will look first in your current working directory
for a .chef folder, and then the parent directory recursively until it finds
one.

Cheerio,

Michael Johnston
lastobelus@mac.com

On 2012-07-26, at 5:32 AM, Sullivan, Jon Paul wrote:

Simplest thing would likely be to add the following to your knife.rb:

cookbook_path ENV[‘CHEF_REPO’]

Thhis would set your cookbook path to the value of the CHEF_REPO variable
in your environment.

You could also set a default in case you don’t have it set:

cb_path = ENV[‘CHEF_REPO’] || ~/cookbooks
cookbook_path cb_path

From: Cassiano Leal [mailto:cassianoleal@gmail.com]
Sent: 26 July 2012 13:17
To: chef@lists.opscode.com
Subject: [chef] Chef repo environment variable?

Hello,

I have been wondering, but couldn't find anything on the interwebs… Is
there a way to point knife to the correct chef-repo path via an environment
variable, say CHEF_HOME, or CHEF_REPO?

The reason I ask is that I have several contexts in my workstation (work,
private project 1, private project 2, …). I use shell aliases to set several
environment variables for each context (AWS keys and paths, other stuff),
and when I open a new shell I just call the alias to set the context.

Any pointers?

Thanks!

Cassiano Leal

Thanks,
Jon-Paul Sullivan J Cloud Services - @hpcloud

Postal Address: Hewlett-Packard Galway Limited, Ballybrit Business Park,
Galway.
Registered Office: Hewlett-Packard Galway Limited, 63-74 Sir John
Rogerson's Quay, Dublin 2.
Registered Number: 361933

The contents of this message and any attachments to it are confidential
and may be legally privileged. If you have received this message in error
you should delete it from your system immediately and advise the sender.

To any recipient of this message within HP, unless otherwise stated, you
should consider this message and attachments as "HP CONFIDENTIAL".

I've just used a simple alias and function in my profile to swap chef
servers by managing ~/.chef as a link. This was what I've been using
since the early days of knife(before environments), and its worked
quite well for me.

On Thu, Jul 26, 2012 at 4:14 PM, Jorge Espada espada.jorge@gmail.com wrote:

Also you might find this gist [0] form Eric Wolfe useful.

[0] multi-knife-howto · GitHub

--
Jorge Espada

On Thu, Jul 26, 2012 at 7:39 PM, Jason Perry bosoxjay@gmail.com wrote:

Check out knife-block, that is what I use and like it a lot.

-- Jay

On Jul 26, 2012, at 6:35 PM, Josiah Kiehl bluepojo@gmail.com wrote:

I wrote this shell script and threw it on my PATH to swap knife configs
between servers:

Shell script to swap knife configs · GitHub

I create directories in this format: ~/.chef-SERVERNAME

I run knife-config SERVERNAME to swap to the server I want and it creates
the correct symlink.

Josiah

On Thu, Jul 26, 2012 at 2:43 PM, Michael Johnston lastobelus@mac.com
wrote:

.chef works like a standard unix dotfile, so my preference is to have a
knife directory in each project, and symlink .chef => knife in each project.

When you use knife it will look first in your current working directory
for a .chef folder, and then the parent directory recursively until it finds
one.

Cheerio,

Michael Johnston
lastobelus@mac.com

On 2012-07-26, at 5:32 AM, Sullivan, Jon Paul wrote:

Simplest thing would likely be to add the following to your knife.rb:

cookbook_path ENV[‘CHEF_REPO’]

Thhis would set your cookbook path to the value of the CHEF_REPO variable
in your environment.

You could also set a default in case you don’t have it set:

cb_path = ENV[‘CHEF_REPO’] || ~/cookbooks
cookbook_path cb_path

From: Cassiano Leal [mailto:cassianoleal@gmail.com]
Sent: 26 July 2012 13:17
To: chef@lists.opscode.com
Subject: [chef] Chef repo environment variable?

Hello,

I have been wondering, but couldn't find anything on the interwebs… Is
there a way to point knife to the correct chef-repo path via an environment
variable, say CHEF_HOME, or CHEF_REPO?

The reason I ask is that I have several contexts in my workstation (work,
private project 1, private project 2, …). I use shell aliases to set several
environment variables for each context (AWS keys and paths, other stuff),
and when I open a new shell I just call the alias to set the context.

Any pointers?

Thanks!

Cassiano Leal

Thanks,
Jon-Paul Sullivan J Cloud Services - @hpcloud

Postal Address: Hewlett-Packard Galway Limited, Ballybrit Business Park,
Galway.
Registered Office: Hewlett-Packard Galway Limited, 63-74 Sir John
Rogerson's Quay, Dublin 2.
Registered Number: 361933

The contents of this message and any attachments to it are confidential
and may be legally privileged. If you have received this message in error
you should delete it from your system immediately and advise the sender.

To any recipient of this message within HP, unless otherwise stated, you
should consider this message and attachments as "HP CONFIDENTIAL".