hw-cookbooks / lxc Goto Github PK
View Code? Open in Web Editor NEWLinux Containers via Chef
Linux Containers via Chef
undefined method `exists?' for Chef::Provider::File:Class
/tmp/vagrant-chef-1/chef-solo-1/cookbooks/lxc/providers/container.rb:219:in `class_from_file'
211:
212: ruby_block "lxc install_chef[#{new_resource.name}]" do
213: block do
214: new_resource._lxc.container_command(
215: "bash /opt/chef-install.sh"
216: )
217: end
218: not_if do
219: File.exists?(new_resource._lxc.rootfs, 'usr', 'bin', 'chef-client')
220: end
221: end
222: end
Containers installing chef via install.sh script require curl or wget to be installed. A non-platform specific strategy needs to be applied.
create
on resource 'cookbook_file[/usr/lib/lxc/templates/lxc-ubuntu-hw]'Parent directory /usr/lib/lxc/templates does not exist.
5: cookbook_file "/usr/lib/lxc/templates/lxc-ubuntu-hw" do
6: source 'lxc-ubuntu-hw'
7: mode 0755
8: end
9:
cookbook_file("/usr/lib/lxc/templates/lxc-ubuntu-hw") do
provider Chef::Provider::CookbookFile
action "create"
retries 0
retry_delay 2
path "/usr/lib/lxc/templates/lxc-ubuntu-hw"
backup 5
source "lxc-ubuntu-hw"
cookbook_name "lxc"
recipe_name "default"
mode 493
end
Found a small bug in setting up a new container: it's always being started and stopped despite having no work to do, eg: no chef support or container/initialize commands to run.
[2014-06-12T07:02:16+00:00] INFO: template[/var/lib/lxc/test/rootfs/root/.ssh/authorized_keys] mode changed to 600
[2014-06-12T07:02:16+00:00] INFO: ruby_block[lxc lock_default_users] called
[2014-06-12T07:02:17+00:00] INFO: ruby_block[lxc start[test]] called
[2014-06-12T07:02:23+00:00] INFO: ruby_block[lxc shutdown[test]] called
[2014-06-12T07:02:23+00:00] WARN: Cloning resource attributes for directory[/opt/hw-lxc-config] from prior resource (CHEF-3694)
Pull request follows.
Running the following default cookbook, with chefdk 1.5.0 results in an exception in provider/config.rb
When a network interface is specified as dynamic, the auto variable is not properly set up for the if branch of the condition, hence the /etc/network/interfaces generated by the template is as follow:
# Auto config dropped off by chef!
# Always setup loopback
auto lo
iface lo inet loopback
iface eth0 inet dhcp
The variable should by set before the if conditional so it is set for every kind of interface (dynamic or static).
A will open a PR with the aforementioned change, I would like to know about merging the PR? I may need some help if tests are required for merging.
This cookbook always installs the latest available chef-client version from chef repo. I would like to configure this version myself.
I've submitted a PR that addresses this issue and other: #63
Thanks.
metadata.rb should have a name otherwise the cookbook can't be upload to chef server
On Ubuntu 12.04 (at least) lxc-shutdown command don't stop Fedora container. So :create action hangs till CommandTimeout exception is raised.
I'm having problems with containers defined using the cookbook under Chef 11.8 and Ubuntu 12.04. When I try to define really minimal containers, like this:
include_recipe 'lxc'
node.default[:lxc][:user_locks] = %w()
lxc_container "test" do
template "ubuntu"
end
The containers don't include the arch, devttydir, tty, or pts options in the lxc config file. And without the devttydir and tty settings SSH isn't really functional into the containers.
The resource defines them with default values, but because of the way load_current_resource sets up the config, and then ::Lxc::FileConfig.generate_config takes that object and runs through it, those values are never getting picked up.
I poked around a bit and it looks like the new_resource that load_current_resource works with doesn't actually have the defaulted attributes directly set. They seem to be lazy loaded (I haven't dug into Chef internals too deeply yet, so sorry if I'm mistaken and something else completely is going on). If I add this to the load_current_resource method I get my config coming out correctly, and I can login to the container via SSH like I expect:
new_resource.arch new_resource.arch
new_resource.devttydir new_resource.devttydir
new_resource.tty new_resource.tty
new_resource.pts new_resource.pts
But that seems to be a very wrong way to fix the problem. Is there something else that other folks are doing to get those options into their configs?
Receiving this error using default recipe on Ubuntu 13.10:
...
[2014-01-02T05:27:14+00:00] INFO: template[/etc/default/lxc] updated file contents /etc/default/lxc
[2014-01-02T05:27:14+00:00] DEBUG: found current_mode == nil, so we are creating a new file, updating mode
[2014-01-02T05:27:14+00:00] DEBUG: found current_mode == nil, so we are creating a new file, updating mode
[2014-01-02T05:27:14+00:00] DEBUG: found target_uid == nil, so no owner was specified on resource, not managing owner
[2014-01-02T05:27:14+00:00] DEBUG: found target_gid == nil, so no group was specified on resource, not managing group
================================================================================
Error executing action `install` on resource 'package[lxc]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '100'
---- Begin output of apt-get -q -y -o Dpkg::Options::="--force-confold" install lxc=1.0.0~alpha1-0ubuntu14 ----
STDOUT: Reading package lists...
Building dependency tree...
Reading state information...
The following extra packages will be installed:
bridge-utils cgroup-lite cloud-image-utils debootstrap distro-info
distro-info-data dnsmasq-base euca2ools genisoimage libaio1
libboost-system1.53.0 libboost-thread1.53.0 libcap2-bin liblxc0 libmnl0
libnetfilter-conntrack3 libpam-cap librados2 librbd1 libseccomp1
lxc-templates python-boto python-distro-info python-m2crypto python3-lxc
qemu-utils sharutils
Suggested packages:
shunit2 wodim cdrkit-doc libcap-dev btrfs-tools lxctl qemu-user-static
bsd-mailx mailx
The following NEW packages will be installed:
bridge-utils cgroup-lite cloud-image-utils debootstrap distro-info
distro-info-data dnsmasq-base euca2ools genisoimage libaio1
libboost-system1.53.0 libboost-thread1.53.0 libcap2-bin liblxc0 libmnl0
libnetfilter-conntrack3 libpam-cap librados2 librbd1 libseccomp1 lxc
lxc-templates python-boto python-distro-info python-m2crypto python3-lxc
qemu-utils sharutils
0 upgraded, 28 newly installed, 0 to remove and 44 not upgraded.
Need to get 0 B/5,151 kB of archives.
After this operation, 18.6 MB of additional disk space will be used.
Selecting previously unselected package libaio1:amd64.
(Reading database ... 72775 files and directories currently installed.)
Unpacking libaio1:amd64 (from .../libaio1_0.3.109-4_amd64.deb) ...
Selecting previously unselected package libboost-system1.53.0:amd64.
Unpacking libboost-system1.53.0:amd64 (from .../libboost-system1.53.0_1.53.0-6+exp3ubuntu8_amd64.deb) ...
Selecting previously unselected package libboost-thread1.53.0:amd64.
Unpacking libboost-thread1.53.0:amd64 (from .../libboost-thread1.53.0_1.53.0-6+exp3ubuntu8_amd64.deb) ...
Selecting previously unselected package libseccomp1:amd64.
Unpacking libseccomp1:amd64 (from .../libseccomp1_1.0.1-2_amd64.deb) ...
Selecting previously unselected package liblxc0.
Unpacking liblxc0 (from .../liblxc0_1.0.0~alpha1-0ubuntu14_amd64.deb) ...
Selecting previously unselected package python-m2crypto.
Unpacking python-m2crypto (from .../python-m2crypto_0.21.1-3ubuntu3_amd64.deb) ...
Selecting previously unselected package libmnl0:amd64.
Unpacking libmnl0:amd64 (from .../libmnl0_1.0.3-3_amd64.deb) ...
Selecting previously unselected package libnetfilter-conntrack3:amd64.
Unpacking libnetfilter-conntrack3:amd64 (from .../libnetfilter-conntrack3_1.0.3-1_amd64.deb) ...
Selecting previously unselected package bridge-utils.
Unpacking bridge-utils (from .../bridge-utils_1.5-6ubuntu1_amd64.deb) ...
Selecting previously unselected package distro-info-data.
Unpacking distro-info-data (from .../distro-info-data_0.16ubuntu0.1_all.deb) ...
Selecting previously unselected package distro-info.
Unpacking distro-info (from .../distro-info_0.11_amd64.deb) ...
Selecting previously unselected package dnsmasq-base.
Unpacking dnsmasq-base (from .../dnsmasq-base_2.66-4ubuntu1_amd64.deb) ...
Selecting previously unselected package python-boto.
Unpacking python-boto (from .../python-boto_2.9.6-1_all.deb) ...
Selecting previously unselected package euca2ools.
Unpacking euca2ools (from .../euca2ools_2.1.3-1ubuntu1_all.deb) ...
Selecting previously unselected package genisoimage.
Unpacking genisoimage (from .../genisoimage_9%3a1.1.11-2ubuntu3_amd64.deb) ...
Selecting previously unselected package libcap2-bin.
Unpacking libcap2-bin (from .../libcap2-bin_1%3a2.22-1.2ubuntu2_amd64.deb) ...
Selecting previously unselected package libpam-cap:amd64.
Unpacking libpam-cap:amd64 (from .../libpam-cap_1%3a2.22-1.2ubuntu2_amd64.deb) ...
Selecting previously unselected package librados2.
Unpacking librados2 (from .../librados2_0.67.4-0ubuntu2_amd64.deb) ...
Selecting previously unselected package librbd1.
Unpacking librbd1 (from .../librbd1_0.67.4-0ubuntu2_amd64.deb) ...
Selecting previously unselected package python3-lxc.
Unpacking python3-lxc (from .../python3-lxc_1.0.0~alpha1-0ubuntu14_amd64.deb) ...
Selecting previously unselected package lxc.
Unpacking lxc (from .../lxc_1.0.0~alpha1-0ubuntu14_amd64.deb) ...
Selecting previously unselected package lxc-templates.
Unpacking lxc-templates (from .../lxc-templates_1.0.0~alpha1-0ubuntu14_all.deb) ...
Selecting previously unselected package python-distro-info.
Unpacking python-distro-info (from .../python-distro-info_0.11_all.deb) ...
Selecting previously unselected package qemu-utils.
Unpacking qemu-utils (from .../qemu-utils_1.5.0+dfsg-3ubuntu5.1_amd64.deb) ...
Selecting previously unselected package sharutils.
Unpacking sharutils (from .../sharutils_1%3a4.11.1-1ubuntu2_amd64.deb) ...
Selecting previously unselected package cgroup-lite.
Unpacking cgroup-lite (from .../cgroup-lite_1.8_all.deb) ...
Selecting previously unselected package cloud-image-utils.
Unpacking cloud-image-utils (from .../cloud-image-utils_0.27-0ubuntu4_all.deb) ...
Selecting previously unselected package debootstrap.
Unpacking debootstrap (from .../debootstrap_1.0.53ubuntu0.1_all.deb) ...
Processing triggers for man-db ...
Processing triggers for ureadahead ...
ureadahead will be reprofiled on next reboot
Processing triggers for install-info ...
Setting up libaio1:amd64 (0.3.109-4) ...
Setting up libboost-system1.53.0:amd64 (1.53.0-6+exp3ubuntu8) ...
Setting up libboost-thread1.53.0:amd64 (1.53.0-6+exp3ubuntu8) ...
Setting up libseccomp1:amd64 (1.0.1-2) ...
Setting up liblxc0 (1.0.0~alpha1-0ubuntu14) ...
Setting up python-m2crypto (0.21.1-3ubuntu3) ...
Setting up libmnl0:amd64 (1.0.3-3) ...
Setting up libnetfilter-conntrack3:amd64 (1.0.3-1) ...
Setting up bridge-utils (1.5-6ubuntu1) ...
Setting up distro-info-data (0.16ubuntu0.1) ...
Setting up distro-info (0.11) ...
Setting up dnsmasq-base (2.66-4ubuntu1) ...
Setting up python-boto (2.9.6-1) ...
Setting up euca2ools (2.1.3-1ubuntu1) ...
Setting up genisoimage (9:1.1.11-2ubuntu3) ...
Setting up libcap2-bin (1:2.22-1.2ubuntu2) ...
Setting up libpam-cap:amd64 (1:2.22-1.2ubuntu2) ...
Setting up librados2 (0.67.4-0ubuntu2) ...
Setting up librbd1 (0.67.4-0ubuntu2) ...
Setting up python3-lxc (1.0.0~alpha1-0ubuntu14) ...
Setting up lxc (1.0.0~alpha1-0ubuntu14) ...
Setting up python-distro-info (0.11) ...
Setting up qemu-utils (1.5.0+dfsg-3ubuntu5.1) ...
Setting up sharutils (1:4.11.1-1ubuntu2) ...
Setting up cgroup-lite (1.8) ...
cgroup-lite start/running
Setting up cloud-image-utils (0.27-0ubuntu4) ...
Setting up debootstrap (1.0.53ubuntu0.1) ...
Processing triggers for libc-bin ...
Processing triggers for ureadahead ...
STDERR: Configuration file `/etc/default/lxc'
==> File on system created by you or by a script.
==> File also in package provided by package maintainer.
==> Using current old file as you requested.
invoke-rc.d: policy-rc.d returned error status 100
dpkg: error processing lxc (--configure):
subprocess installed post-installation script returned error exit status 100
dpkg: dependency problems prevent configuration of lxc-templates:
lxc-templates depends on lxc (>= 0.8.0~rc1-4ubuntu43); however:
Package lxc is not configured yet.
dpkg: error processing lxc-templates (--configure):
dependency problems - leaving unconfigured
Errors were encountered while processing:
lxc
lxc-templates
E: Sub-process /usr/bin/dpkg returned an error code (1)
---- End output of apt-get -q -y -o Dpkg::Options::="--force-confold" install lxc=1.0.0~alpha1-0ubuntu14 ----
Ran apt-get -q -y -o Dpkg::Options::="--force-confold" install lxc=1.0.0~alpha1-0ubuntu14 returned 100
Resource Declaration:
---------------------
# In /tmp/vagrant-chef-1/chef-solo-1/cookbooks/lxc/recipes/default.rb
80: package lxcpkg do
81: options '-o Dpkg::Options::="--force-confold"'
82: end
83: end
Compiled Resource:
------------------
# Declared in /tmp/vagrant-chef-1/chef-solo-1/cookbooks/lxc/recipes/default.rb:80:in `block in from_file'
package("lxc") do
action :install
retries 0
retry_delay 2
options "-o Dpkg::Options::=\"--force-confold\""
package_name "lxc"
version "1.0.0~alpha1-0ubuntu14"
cookbook_name :lxc
recipe_name "default"
end
Any ideas?
https://github.com/hw-cookbooks/lxc/blob/master/recipes/default.rb#L35-L36
Just curious what's the reason behind that.
Chef calls the load_current_resource
method in the config
provider to determine the current state of the node. This method throws an exception if the resource is malformed (see: https://github.com/chrisroberts/elecksee/blob/master/lib/elecksee/lxc_file_config.rb#L129). In other words, the code exits before chef is able to repair the malformed resource to the correct state. Then a single misconfiguration or a bad file create would mean any recipe using this LWRP might never work again. This could be potentially problematic.
The log_location parameter should be configurable via the LWRP, now is hardcoded see:
https://github.com/hw-cookbooks/lxc/blob/master/templates/default/client.rb.erb#L2
My goal is to build a workstation that will run test-kitchen and be able to launch LXCs inside it. I'm doing this with vagrant, and the vagrant image is getting provisioned properly with the chef_client provisioner.
From there, the "lxc" and "lxc::containers" recipes are added (in the Vagrantfile), along with a custom wrapper cookbook in which I'm using an lxc_container lwrp, as described in the lxc cookbook readme.
My vagrant image launches, downloads chef, and starts converging. It appears to hang after:
[2013-09-23T20:01:54+00:00] INFO: template[/var/lib/lxc/ubuntu_1204/rootfs/root/.ssh/authorized_keys] created file /var/lib/lxc/ubuntu_1204/rootfs/root/.ssh/authorized_keys
[2013-09-23T20:01:54+00:00] INFO: template[/var/lib/lxc/ubuntu_1204/rootfs/root/.ssh/authorized_keys] updated file contents /var/lib/lxc/ubuntu_1204/rootfs/root/.ssh/authorized_keys
[2013-09-23T20:01:54+00:00] INFO: template[/var/lib/lxc/ubuntu_1204/rootfs/root/.ssh/authorized_keys] mode changed to 600
[2013-09-23T20:01:54+00:00] INFO: ruby_block[lxc lock_default_users] called
And that's it. Here is the full chef run output: https://gist.github.com/jtzl/6678363
Is the apparent hanging related to my usage of the cookbook? Has anyone experienced and/or resolved this issue in their own environment?
Thanks!
Edit:
with VAGRANT_LOG=debug, it finishes lxc-create successfully and then goes to:
DEBUG ssh: Sending SSH keep-alive...
DEBUG ssh: Sending SSH keep-alive...
DEBUG ssh: Sending SSH keep-alive...
DEBUG ssh: Sending SSH keep-alive...
DEBUG ssh: Sending SSH keep-alive...
Over and over. It also did this while waiting on lxc-create, but it will go for over an hour without intervention.
I want to be able to set lxc.aa_profile
for a container. Currently there's not way to do that.
Maybe you could expose a way to add arbitrary config lines?
Some instructions on how to configure autostart for node would be very nice!
If i use this:
include_recipe "lxc::default"
lxc_container 'precise1' do
action :create
chef_enabled false
initialize_commands ['apt-get update', 'apt-get install openssh-server']
static_ip '10.0.3.6'
static_netmask '255.255.255.0'
static_gateway '10.0.3.1'
end
lxc_service 'precise1' do
action :start
end
I can't seem to fire up an LXC guest with this cookbook. I get the following errors:
- execute the ruby block lxc start[precise1]
* ruby_block[lxc initialize_commands[precise1]] action run[2014-12-09T08:52:18+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:21+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:25+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:28+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:31+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:35+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:38+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:39+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:42+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:46+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:49+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:52+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:56+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:52:59+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:00+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:04+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:07+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:10+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:13+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:17+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:20+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:21+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:25+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:28+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:31+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:34+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:38+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:41+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:42+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:46+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:49+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:52+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:56+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:53:59+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:54:02+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:54:03+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:54:07+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:54:10+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:54:13+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:54:17+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:54:20+00:00] WARN: LXC IP discovery: Failed to detect live IP
[2014-12-09T08:54:23+00:00] WARN: LXC IP discovery: Failed to detect live IP
================================================================================
Error executing action `run` on resource 'ruby_block[lxc initialize_commands[precise1]]'
================================================================================
Lxc::CommandFailed
------------------
Expected process to exit with [0], but received '255'
---- Begin output of ssh root@ -i /opt/hw-lxc-config/id_rsa -oStrictHostKeyChecking=no 'apt-get update' ----
STDOUT:
STDERR: ssh: Could not resolve hostname : Name or service not known
---- End output of ssh root@ -i /opt/hw-lxc-config/id_rsa -oStrictHostKeyChecking=no 'apt-get update' ----
Ran ssh root@ -i /opt/hw-lxc-config/id_rsa -oStrictHostKeyChecking=no 'apt-get update' returned 255
Cookbook Trace:
---------------
/home/ubuntu/.chef/local-mode-cache/cache/cookbooks/lxc/providers/container.rb:228:in `block (4 levels) in class_from_file'
/home/ubuntu/.chef/local-mode-cache/cache/cookbooks/lxc/providers/container.rb:226:in `each'
/home/ubuntu/.chef/local-mode-cache/cache/cookbooks/lxc/providers/container.rb:226:in `block (3 levels) in class_from_file'
Resource Declaration:
---------------------
# In /home/ubuntu/.chef/local-mode-cache/cache/cookbooks/lxc/providers/container.rb
224: ruby_block "lxc initialize_commands[#{new_resource.name}]" do
225: block do
226: new_resource.initialize_commands.each do |cmd|
227: Chef::Log.info "Running command on #{new_resource.name}: #{cmd}"
228: _lxc.container_command(cmd, 5)
229: end
230: end
231: only_if do
232: node.run_state[:lxc][:meta][new_resource.name][:new_container] &&
233: !new_resource.initialize_commands.empty?
234: end
235: end
236:
Compiled Resource:
------------------
# Declared in /home/ubuntu/.chef/local-mode-cache/cache/cookbooks/lxc/providers/container.rb:224:in `block in class_from_file'
ruby_block("lxc initialize_commands[precise1]") do
action "run"
retries 0
retry_delay 2
guard_interpreter :default
block_name "lxc initialize_commands[precise1]"
cookbook_name "myapp"
block #<Proc:0x00000003c1cef8@/home/ubuntu/.chef/local-mode-cache/cache/cookbooks/lxc/providers/container.rb:225>
only_if { #code block }
end
Running handlers:
[2014-12-09T08:54:23+00:00] ERROR: Running exception handlers
Running handlers complete
[2014-12-09T08:54:23+00:00] ERROR: Exception handlers complete
[2014-12-09T08:54:23+00:00] FATAL: Stacktrace dumped to /home/ubuntu/.chef/local-mode-cache/cache/chef-stacktrace.out
Chef Client failed. 8 resources updated in 133.547317597 seconds
[2014-12-09T08:54:23+00:00] ERROR: ruby_block[lxc initialize_commands[precise1]] (/home/ubuntu/.chef/local-mode-cache/cache/cookbooks/lxc/providers/container.rb line 224) had an error: Lxc::CommandFailed: Expected process to exit with [0], but received '255'
---- Begin output of ssh root@ -i /opt/hw-lxc-config/id_rsa -oStrictHostKeyChecking=no 'apt-get update' ----
STDOUT:
STDERR: ssh: Could not resolve hostname : Name or service not known
---- End output of ssh root@ -i /opt/hw-lxc-config/id_rsa -oStrictHostKeyChecking=no 'apt-get update' ----
Ran ssh root@ -i /opt/hw-lxc-config/id_rsa -oStrictHostKeyChecking=no 'apt-get update' returned 255
[2014-12-09T08:54:23+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
I've tried to see if it's something I'm doing wrong, but I can't figure that out.
otherwise, dnsmasq won't put the hostname in the leases file
this causes the kitchen-lxc driver to fail
Hi Gentlemen,
Thanks for providing this cookbook. I keep running into an issue, regardless of which version of Ubuntu I'm running. Please see below. This happens whether I add containers to default[:lxc][:containers] or I call lxc_container explicitly.
[2013-11-20T05:53:21+00:00] FATAL: NoMethodError: lxc_config[selenium_gax](/tmp/vagrant-chef-1/chef-solo-1/cookbooks/lxc/providers/container.rb line 54) had an error: NoMethodError: undefined method `each' for Chef::Resource::LxcConfig
I can't tell whether it is user error or a bug in the code.
Those options are not supported yet as part of a container config LWRP, they provide vital support for lxc and cookbook debbuging.
It seems changing this attribute doesn't affect the password on the container.
Line 21 in afef81d
It's a pretty decent security vulnerability I suppose.
I'm getting the following exception when trying to create a container with lxc cookbook. I'm using Ubuntu 14.04 and the 2.0 version of the lxc cookbook.
* execute[lxc copy_chef_full[mycontainer]] action run
================================================================================
Error executing action `run` on resource 'execute[lxc copy_chef_full[mycontainer]]'
================================================================================
Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of cp ["/opt/chef_11.12.8-2_amd64.deb"] /var/lib/lxc/mycontainer/rootfs/opt ----
STDOUT:
STDERR: cp: cannot stat '[/opt/chef_11.12.8-2_amd64.deb]': No such file or directory
---- End output of cp ["/opt/chef_11.12.8-2_amd64.deb"] /var/lib/lxc/mycontainer/rootfs/opt ----
Ran cp ["/opt/chef_11.12.8-2_amd64.deb"] /var/lib/lxc/mycontainer/rootfs/opt returned 1
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/lxc/libraries/monkey.rb:20:in `monkey_shell_out!'
Resource Declaration:
---------------------
# In /var/chef/cache/cookbooks/lxc/providers/container.rb
148: execute "lxc copy_chef_full[#{new_resource.name}]" do
149: command "cp #{file_path} #{_lxc.rootfs.join('opt')}"
150: not_if do
151: file_path.nil? || !new_resource.chef_enabled || _lxc.rootfs.join(file_path).exist?
152: end
153: end
154:
Compiled Resource:
------------------
# Declared in /var/chef/cache/cookbooks/lxc/providers/container.rb:148:in `block in class_from_file'
execute("lxc copy_chef_full[mycontainer]") do
action "run"
retries 0
retry_delay 2
guard_interpreter :default
command "cp [\"/opt/chef_11.12.8-2_amd64.deb\"] /var/lib/lxc/mycontainer/rootfs/opt"
backup 5
returns 0
cookbook_name "dnsimple-lxc"
not_if { #code block }
end
After I remove /opt/chef_11.12.8-2_amd64.deb
from its location the exception disappears and chef completes successfully.
I have this in one of my cookbooks:
lxc 'worker' do
template 'ubuntu'
end
I can see the container being created using the ubuntu
template. Chef finishes, but when looking at the server, I noticed that it's actually pretty hard to find out the internal IP of the new container.
This is what I see after connecting:
$ lxc-list
STOPPED
worker
$ lxc-start -n worker -d
$ lxc-list
RUNNING
worker
$ cat /var/lib/misc/dnsmasq.leases
# empty
$ lxc-console -n worker
# I can correctly log in
$ cat /etc/dnsmasq.d/lxc
# Tell any system-wide dnsmasq instance to make sure to bind to interfaces
# instead of listening on 0.0.0.0
# WARNING: changes to this file will get lost if lxc is removed.
bind-interfaces
except-interface=lxcbr0
$ cat /etc/default/lxc
LXC_AUTO=true
USE_LXC_BRIDGE=true
LXC_BRIDGE="lxcbr0"
LXC_ADDR="10.0.3.1"
LXC_NETMASK="255.255.255.0"
LXC_NETWORK="10.0.3.0/24"
LXC_DHCP_RANGE="10.0.3.2,10.0.3.254"
LXC_DHCP_MAX="253"
LXC_SHUTDOWN_TIMEOUT=120
MIRROR="http://archive.ubuntu.com/ubuntu"
$ ssh [email protected]
Permission denied (publickey).
# I can connect (but denied due to ssh restrictions)
$ ssh [email protected]
ssh: connect to host 10.0.3.2 port 22: No route to host
# I'm not sure about this last one. The DHCP range starts at *.2,
# but the NETWORK range also includes *.1, but this could possibly be the DCHP router or something.
The problem with this is that I need to find out how to get the IP of the container, so I can pass it along to our Jenkins CI server to work with. Any thoughts?
Here's my run_list
:
run_list *%w[
role[base] # build-essentials, git, etc…
recipe[jenkins::node_ssh] # jenkins-slave
recipe[lxc] # this cookbook, default action
recipe[jenkins-slave] # lxc 'worker' with template 'ubuntu'
]
And this is the only (relevant) overridden attribute:
override_attributes(lxc: { allowed_types: %w[ubuntu] })
NOTE: I am using the new-develop branch
After adding lxc
to my run list, the following error occurred:
NameError
---------
constant Chef::Resource::Lxc not defined
Upgrading from 11.4.2 to Chef 11.6.0 solved this issue (did not test 11.4.4).
I'm not sure, if you want to make the cookbook compatible with older versions of Chef - I just wanted to report this in order to help people who run into the same issue (thus feel free to reject it immediately)
Details:
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/lxc/resources/default.rb
================================================================================
NameError
---------
constant Chef::Resource::Lxc not defined
Cookbook Trace:
---------------
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/resource/lwrp_base.rb:43:in `remove_const'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/resource/lwrp_base.rb:43:in `build_from_file'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/run_context/cookbook_compiler.rb:208:in `load_lwrp_resource'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/run_context/cookbook_compiler.rb:193:in `block in load_lwrps_from_cookbook'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/run_context/cookbook_compiler.rb:192:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/run_context/cookbook_compiler.rb:192:in `load_lwrps_from_cookbook'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/run_context/cookbook_compiler.rb:120:in `block in compile_lwrps'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/run_context/cookbook_compiler.rb:119:in `each'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/run_context/cookbook_compiler.rb:119:in `compile_lwrps'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/run_context/cookbook_compiler.rb:72:in `compile'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/run_context.rb:86:in `load'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/client.rb:224:in `setup_run_context'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/client.rb:467:in `do_run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/client.rb:200:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/application.rb:190:in `run_chef_client'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/application/client.rb:297:in `block in run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/application/client.rb:290:in `loop'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/application/client.rb:290:in `run_application'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/application.rb:73:in `run'
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/bin/chef-client:26:in `<top (required)>'
/usr/bin/chef-client:23:in `load'
/usr/bin/chef-client:23:in `<main>'
Relevant File Content:
----------------------
/opt/chef/embedded/lib/ruby/gems/1.9.1/gems/chef-11.4.2/lib/chef/resource/lwrp_base.rb:
36: # Evaluates the LWRP resource file and instantiates a new Resource class.
37: def self.build_from_file(cookbook_name, filename, run_context)
38: rname = filename_to_qualified_string(cookbook_name, filename)
39:
40: # Add log entry if we override an existing light-weight resource.
41: class_name = convert_to_class_name(rname)
42: if Resource.const_defined?(class_name)
43>> old_class = Resource.send(:remove_const, class_name)
44: # CHEF-3432 -- Chef::Resource keeps a list of subclasses; need to
45: # remove old ones from the list when replacing.
46: resource_classes.delete(old_class)
47: Chef::Log.info("#{class_name} light-weight resource already initialized -- overriding!")
48: end
49:
50: resource_class = Class.new(self)
51:
52: resource_class.resource_name = rname
This line gets run before the cacher is installed and as a result the config is never placed into the default lxc config in /etc/default/lxc
.
Example:
include_recipe 'apt::cacher-ng'
include_recipe 'apt::cacher-client'
include_recipe 'apt'
include_recipe 'lxc'
lxc_container 'my_container' do
action :create
end
# lxc-awesome-ephemeral -o playground
Setting up ephemeral container...
readlink: missing operand
Try `readlink --help' for more information.
/usr/local/bin/lxc-awesome-ephemeral: line 268: [: ==: unary operator expected
Starting up the container...
playground-temp-zfjzJ4D is running
You connect with the command:
sudo lxc-console -n playground-temp-zfjzJ4D
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.