【发布时间】:2016-02-19 00:03:54
【问题描述】:
我有 docker provider 和 chef-solo 配置的 Vagrant 配置,在 vagrant up --provider=docker 命令之后,Vagrant 在 chef_solo 配置步骤失败:
CentOS 失败
==> node1: Machine booted and ready!
==> node1: Running provisioner: chef_solo...
==> node1: Detected Chef (latest) is already installed
The chef binary (either `chef-solo` or `chef-client`) was not found on
the VM and is required for chef provisioning. Please verify that chef
is installed and that the binary is available on the PATH.
和 Suse 失败
==> node2: Machine booted and ready!
==> node2: Running provisioner: chef_solo...
node2: Installing Chef (latest)...
Vagrant attempted to execute the capability 'chef_install'
on the detect guest OS 'suse', but the guest doesn't
support that capability. This capability is required for your
configuration of Vagrant. Please either reconfigure Vagrant to
avoid this capability or fix the issue by creating the capability.
流浪文件
Vagrant.configure("2") do |config|
config.vm.synced_folder "cnf/", "/home/vagrant/cnf_templates"
config.vm.network "private_network", type: "dhcp"
# node1 - CentOS 6.7
config.vm.define "node1" do |node1|
node1.vm.provider "docker" do |d|
d.build_dir = "centos/"
d.has_ssh = true
#d.ports = ["3306:3306"]
d.privileged = true
#d.remains_running = false
end
node1.vm.provision "chef_solo" do |chef|
chef.cookbooks_path = "../../../../recipes/cookbooks"
chef.roles_path = "."
chef.add_role "docker1"
end
end
# node2 - OpenSuSE 13
config.vm.define "node0" do |node2|
node2.vm.provider "docker" do |d|
d.build_dir = "sles/"
d.has_ssh = true
#d.ports = ["3306:3306"]
d.privileged = true
end
node2.vm.provision "chef_solo" do |chef|
chef.cookbooks_path = "../../../../recipes/cookbooks"
chef.roles_path = "."
chef.add_role "docker2"
end
end
end
CentOS 的 Dockerfile
FROM centos:6.7
#ENV SHELL /bin/bash
RUN yum update -y && \
yum clean all && \
yum --assumeyes install openssh-server openssh-clients sudo curl wget iptables
yum clean all
RUN /etc/init.d/sshd start
RUN sed -i 's/.*requiretty$/Defaults !requiretty/' /etc/sudoers
# Create and configure vagrant user
RUN groupadd vagrant && \
useradd -c "Vagrant" -g vagrant -d /home/vagrant -m -s /bin/bash vagrant &&
echo 'vagrant:vagrant' | chpasswd && \
mkdir -p /etc/sudoers.d && \
echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers.d/vagrant
chmod 0440 /etc/sudoers.d/vagrant
# Configure SSH access
RUN mkdir -pm 700 /home/vagrant/.ssh && \
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YV
chmod 0600 /home/vagrant/.ssh/authorized_keys && \
chown -R vagrant:vagrant /home/vagrant/.ssh
# Clean up when done.
#RUN yum clean all
# daemonize sshd
CMD ["/usr/sbin/sshd", "-D", "-e"]
EXPOSE 22
用于 Suse 的 Dockerfile
FROM opensuse:latest
RUN zypper -n --gpg-auto-import-keys ar http://download.opensuse.org/factory/repo/oss/ OSS
RUN zypper -n ref && \
zypper -n up --skip-interactive && \
zypper --non-interactive --gpg-auto-import-keys install -y openSSH sudo wget iptables SuSefirewall2
ENV SHELL /bin/bash
RUN sed -i 's/UsePAM no/UsePAM yes/' /etc/ssh/sshd_config
RUN sed -i 's/#PubkeyAuthentication no/PubkeyAuthentication yes/' /etc/ssh/sshd_config
#RUN sed -i 's/#ChallengeResponseAuthentication no/ChallengeREsponseAuthentication ...
RUN sed -i 's/#PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
#RUN echo 'root:13579Rh' | chpasswd
CMD ["/bin/bash", "-c", "rcsshd restart"]
RUN sed -i 's/.*requiretty$/Defaults !requiretty/' /etc/sudoers
# Create and configure vagrant user
RUN groupadd vagrant && \
useradd -m -g vagrant -d /home/vagrant -s /bin/bash vagrant && \
echo 'vagrant:vagrant' && \
echo 'vagrant ALL=(ALL) ALL' >> /etc/sudoers.d/vagrant && \
chmod 0440 /etc/sudoers.d/vagrant
# create ssh host keys for sshd
RUN ssh-keygen -A
# Configure SSH access
RUN mkdir -p /home/vagrant/.ssh && \
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YV$
chmod 0600 /home/vagrant/.ssh/authorized_keys && \
chown -R vagrant:vagrant /home/vagrant/.ssh && \
chmod 0700 /home/vagrant/.ssh
# Install chef
#RUN wget -O - https://www.opscode.com/chef/install.sh | /bin/bash
# Clean up APT when done.
#zypper clean
#RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
CMD ["/usr/sbin/sshd", "-D"]
EXPOSE 22
我的配置有什么问题?我尝试了几乎所有的主厨版本安装:综合插件、通过 bash 脚本 (wget chef.sh | bash) 手动安装主厨和基本主厨配置。
附: Chef-solo 仅在带有 vagrant docker 提供程序的 Ubuntu 14.04 上运行良好。
谢谢, 基里尔
【问题讨论】:
-
Chef 在 CentOS 配置中安装在哪里?
chef-solo或chef-client通常在 CentOS 上的什么位置?如果您手动查找它是否存在?$PATH包含什么? -
是的,CentOS 中安装了 chef-solo。如果我通过 ssh 进入容器,则其中已经存在 chef-solo。 $PATH 变量不包含主目录 (/opt/chef/bin) 和根目录下的此目录的路径。我尝试手动将厨师路径添加到 $PATH,但没有成功。
-
您是如何尝试添加到
$PATH的?似乎这就是配置和修复应该起作用的问题。或者,如果您可以指示 vagrant 到chef-solo的完整路径是什么,那可能值得一试。 -
我正在尝试在 Dockerfile 中通过以下行添加 $PATH: ENV PATH $PATH:/opt/chef/bin:/opt/chef/embedded/bin RUN export PATH 是的,我想是的,配置中的问题。我怎样才能做到这一点,通过 vagrant 添加到 chef-solo 的完整路径,或者它可以指向 Dockerfile?
-
在不知道 docker 的情况下,这肯定看起来应该有效(如果做得足够早的话)。我不知道。我什至不知道这是否可能。这只是一个建议。
标签: docker centos vagrant chef-solo suse