我们的开发环境包括运行对云中更大的共享资源的查询的本地虚拟机。
它的设置方式是本地用户的登录将作为属性传递给 Chef 角色,该属性用于定义 SSH 和 DB 连接。
我们目前在 Vagrantfile 中使用 Ruby 提取登录名,并使用 vm.provision 在来宾 VM 的文件系统上创建 /tmp 文件。我们本地 VM 的 Chef 角色读取该文件的内容并将值传递给属性。
流浪文件:
# -*- mode: ruby -*-
# vi: set ft=ruby :
(snip)
require 'etc'
user = Etc.getlogin
(snip)
analytics.vm.provision :shell, inline: "echo #{user} > /tmp/remote_user"
在 Chef 运行期间,/tmp/remote_user 的内容由以下内容读取:
remote_user = File.open("/tmp/remote_user", "r").read.strip
sandbox = "_#{remote_user}"
default_attributes "remote_user" => remote_user,
"sandbox" => sandbox,
有没有更好的方法将当前用户的登录作为属性添加到本地 Chef 运行?
如果没有,我如何在 .kitchen.yml 中复制旧 Vagrantfile 中的功能?