[RESOLVED] Advise on first chef invocation on a VM


#1

Hi,

we are creating chef nodes using xen-create-image. I am creating a
separate role, which is supposed to install chef via omnibus. There
are two approaches to that:

  1. run chef-client to fully install the system during xen-create-image
    phase (in chroot)
  2. install chef the way that after first reboot it would run
    chef-client and completely configure by itself.

I would prefer (2), because it is more “real” scenario, and would not
increase (quite long already) time of xen-create-image.

Is there a way to install chef with only chef-client recipe? Or is it
generally considered “ok” to do it the (1) way?

Thanks,
Motiejus Jakštys


#2

On Sat, Jun 2, 2012 at 4:48 PM, Motiejus Jakštys desired.mta@gmail.com wrote:

Hi,

we are creating chef nodes using xen-create-image. I am creating a
separate role, which is supposed to install chef via omnibus. There
are two approaches to that:

  1. run chef-client to fully install the system during xen-create-image
    phase (in chroot)
  2. install chef the way that after first reboot it would run
    chef-client and completely configure by itself.

I would prefer (2), because it is more “real” scenario, and would not
increase (quite long already) time of xen-create-image.

Is there a way to install chef with only chef-client recipe? Or is it
generally considered “ok” to do it the (1) way?

Found it! Here is the script :slight_smile:

chroot {prefix} http_proxy=http://wwwcache:8080 wget -O/tmp/install.sh http://www.opscode.com/chef/install.sh chroot {prefix} http_proxy=http://wwwcache:8080 bash /tmp/install.sh
chroot {prefix} knife configure client /etc/chef -s "http://chef.server:4000" cp /etc/chef/validation.pem {prefix}/etc/chef/
chroot {prefix} chef-client -o recipe[chef-client] chroot {prefix} /etc/init.d/chef-client stop

The whole secret is chef-client -o.


Motiejus Jakštys


#3

On Sat, Jun 2, 2012 at 5:32 PM, Motiejus Jakštys desired.mta@gmail.com wrote:

On Sat, Jun 2, 2012 at 4:48 PM, Motiejus Jakštys desired.mta@gmail.com wrote:

Hi,

we are creating chef nodes using xen-create-image. I am creating a
separate role, which is supposed to install chef via omnibus. There
are two approaches to that:

  1. run chef-client to fully install the system during xen-create-image
    phase (in chroot)
  2. install chef the way that after first reboot it would run
    chef-client and completely configure by itself.

I would prefer (2), because it is more “real” scenario, and would not
increase (quite long already) time of xen-create-image.

Is there a way to install chef with only chef-client recipe? Or is it
generally considered “ok” to do it the (1) way?

Found it! Here is the script :slight_smile:

chroot {prefix} http_proxy=http://wwwcache:8080 wget -O/tmp/install.sh http://www.opscode.com/chef/install.sh chroot {prefix} http_proxy=http://wwwcache:8080 bash /tmp/install.sh
chroot {prefix} knife configure client /etc/chef -s "http://chef.server:4000" cp /etc/chef/validation.pem {prefix}/etc/chef/
chroot {prefix} chef-client -o recipe[chef-client] chroot {prefix} /etc/init.d/chef-client stop

This has 2 problems:

  1. chef-client or its dependency does not stop (and xen-create-image
    fails while unmounting the image). Logs are unhelpful. After some
    digging I think I will be able to find and fix it.
  2. When running chef-client for the first time, chef-client sees its
    hostname same as the host hostname… Which is severe. And I could
    find no way to change hostname in chroot without affecting the host.

So I will try to make sure chef-client is started on its first
reboot… And configure itself properly.


Motiejus Jakštys


#4

Why do you not want to use knife bootstrap or vagrant? Installing chef
client in the template image seems like the wrong way around to me…
On Jun 2, 2012 12:07 PM, “Motiejus Jakštys” desired.mta@gmail.com wrote:

On Sat, Jun 2, 2012 at 5:32 PM, Motiejus Jakštys desired.mta@gmail.com
wrote:

On Sat, Jun 2, 2012 at 4:48 PM, Motiejus Jakštys desired.mta@gmail.com
wrote:

Hi,

we are creating chef nodes using xen-create-image. I am creating a
separate role, which is supposed to install chef via omnibus. There
are two approaches to that:

  1. run chef-client to fully install the system during xen-create-image
    phase (in chroot)
  2. install chef the way that after first reboot it would run
    chef-client and completely configure by itself.

I would prefer (2), because it is more “real” scenario, and would not
increase (quite long already) time of xen-create-image.

Is there a way to install chef with only chef-client recipe? Or is it
generally considered “ok” to do it the (1) way?

Found it! Here is the script :slight_smile:

chroot {prefix} http_proxy=http://wwwcache:8080 wget -O/tmp/install.sh http://www.opscode.com/chef/install.sh chroot {prefix} http_proxy=http://wwwcache:8080 bash /tmp/install.sh
chroot {prefix} knife configure client /etc/chef -s " http://chef.server:4000" cp /etc/chef/validation.pem {prefix}/etc/chef/
chroot {prefix} chef-client -o recipe[chef-client] chroot {prefix} /etc/init.d/chef-client stop

This has 2 problems:

  1. chef-client or its dependency does not stop (and xen-create-image
    fails while unmounting the image). Logs are unhelpful. After some
    digging I think I will be able to find and fix it.
  2. When running chef-client for the first time, chef-client sees its
    hostname same as the host hostname… Which is severe. And I could
    find no way to change hostname in chroot without affecting the host.

So I will try to make sure chef-client is started on its first
reboot… And configure itself properly.


Motiejus Jakštys


#5

On Sun, Jun 3, 2012 at 5:39 PM, Jesse Campbell hikeit@gmail.com wrote:

Why do you not want to use knife bootstrap or vagrant? Installing chef
client in the template image seems like the wrong way around to me…

It’s not in template, it’s installed during VM bootstrapping phase.
Just like you would install openssh to connect to server, you install
chef to autoconfigure itself.
This way additional “knife bootstrap” phase is unnecessary.

Actually, I copied and adjusted puppet role from xen-utils/role.d/ to
make it work with Chef.

Anyway, I solved the problem by creating an init script which
registers to chef on first boot, and removes itself when the
registration is successful.


Motiejus Jakštys


#6

This was a great sequence, thank you.

Is this still be best way to do this? If so, can you please share the init script?

Ray


#7

Hi,

sorry, it’s been too long ago, I cannot advise any more than the above.

Good luck.


#8

Thank you for letting me know so quickly.

Ray