我根本不認識魯比。我只需要在 ruby?? 中運行 Vagrantfile writtne,我從組態檔中得到錯誤的值。
流浪檔案:
# -*- mode: ruby -*-
# vi: set ft=ruby :
# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
require 'yaml'
current_dir = File.dirname(File.expand_path(__FILE__))
settings = YAML.load_file("#{current_dir}/vars.yaml")
Vagrant.configure("2") do |config|
# The most common configuration options are documented and commented below.
# For a complete reference, please see the online documentation at
# https://docs.vagrantup.com.
# Every Vagrant development environment requires a box. You can search for
# boxes at https://vagrantcloud.com/search.
config.vm.define "testsbox" do |testsbox|
testsbox.vm.box = "generic/rhel8"
testsbox.vm.hostname = "testsbox"
testsbox.vm.provision "shell", privileged: true,
env: {
"LOGIN" => settings['login'],
"PASSWORD" => settings['password']
},
inline: <<-SHELL
echo ****************SUBSCRIPTION**************
echo --username=${LOGIN} --password=${PASSWORD}
echo ****************SUBSCRIPTION**************
在運行時,我得到:
--username=login --password=password
vars.yaml檔案如下所示:
---
login:myuser
password:mysecretpassword
我不知道有什么問題。歡迎任何點擊。在 Windows 10 上但在 git-bash 下執行的代碼。檔案 vars.yaml 在 Windows 下編輯,但格式從 Windnows (CR LF) 更改為 (Unix (LF)
uj5u.com熱心網友回復:
您的 YAML 檔案格式錯誤 - 冒號后缺少空格。正確的應該是:
---
login: myuser
password: mysecretpassword
修復它,您的代碼應該可以作業。
你的代碼會發生什么?類似于以下內容:
- YAML 決議器將錯誤的 yaml 檔案決議為非結構化字串,因此您的內容
settings類似于"login:myuser password:mysecretpassword"(只是一個字串) - 對于字串
[]在某種程度上表現為模式匹配 - 它只回傳匹配的子字串(如果有)。看:
s = "login:myuser password:mysecretpassword"
s["login"] #=> "login"
s[/login/] #=> "login" # Yes, this works too
s["foo"] #=> nil
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/426762.html
下一篇:TicTacToe重勝條件
