小编use*_*045的帖子

Terraform 组合变量和字符串

我试图在 Terraform 中做一个相当简单的任务,但它不起作用:

变量:

hosted_zone       = "example.com"
domain            = "my.${var.hosted_zone}"
Run Code Online (Sandbox Code Playgroud)

route_53_record:

resource "aws_route53_record" "regional" {
  zone_id = "${data.aws_route53_zone.selected.zone_id}"
  name    = "${var.domain}"
  type    = "A"
  ttl     = "300"
  records = ["4.4.4.4"]
}
Run Code Online (Sandbox Code Playgroud)

当我跑步时,terraform plan我得到了这个:

+ aws_route53_record.regional
      id:                 <computed>
      allow_overwrite:    "true"
      fqdn:               <computed>
      name:               "my.${var.hosted_zone}"
      records.#:          "1"
      records.3178571330: "4.4.4.4"
      ttl:                "300"
      type:               "A"
      zone_id:            "REDACTED"
Run Code Online (Sandbox Code Playgroud)

域应该是my.example.com. 如何加入变量 hosts_zoned 和一个字符串以形成域?

terraform

15
推荐指数
1
解决办法
3万
查看次数

Vagrant 构建 Gem 原生扩展失败

我在 OSX 10.11.3 上运行 Vagrant 1.8.1,我正在尝试安装一个插件。在尝试安装时,我收到以下错误:

vagrant plugin install vagrant-libvirt
............

An error occurred while installing ruby-libvirt (0.6.0), and Bundler cannot continue.
Make sure that `gem install ruby-libvirt -v '0.6.0'` succeeds before bundling.

.........
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
Run Code Online (Sandbox Code Playgroud)

ruby-livirt 0.6.0 已经安装:

# gem list | grep ruby-libvirt
# ruby-libvirt (0.6.0)
Run Code Online (Sandbox Code Playgroud)

由于 gem 已经安装,我可以绕过这个错误吗?

ruby vagrant osx-elcapitan

5
推荐指数
1
解决办法
1330
查看次数

Bash 读取输入 - 按 Tab 键切换提示符

我有一个正在读取用户输入的脚本。这是我的代码:

if [ -z $volreadexists ]; then
        echo -e "\tThis will overwrite the entire volume (/dev/vg01/$myhost)...are you sure?"
        read REPLY
        echo
        if [[ $REPLY =~ ^[Yy]$ ]]; then
            echo -e "\t\tContinuing"
            syncvolume
        else
            echo "Fine...skipping"
        fi
    fi
Run Code Online (Sandbox Code Playgroud)

我必须使用,read REPLY因为read它本身不插入选项卡。我正在寻找类似的东西:

read -p "\tDoes this look OK? (n for No)" -n 1 -r
Run Code Online (Sandbox Code Playgroud)

\t在阅读提示上按 Tab 键。

如何向阅读提示添加选项卡?

更新:感谢@gniourf 的精彩回答!:

read -p $'\tDoes this look OK? (n for No)' -n 1 -r
Run Code Online (Sandbox Code Playgroud)

然而,我发现了一个问题。当我尝试在那里使用变量时,它不会翻译它:

read -p $'\tThis will overwrite …
Run Code Online (Sandbox Code Playgroud)

bash

5
推荐指数
1
解决办法
1480
查看次数

Rails 5 ActiveRecord删除重复项

我有一个Rails 5应用程序.我有一个表格,里面填写了从各种来源提取的URL数据:

id     url
1      http://google.com
2      http://yahoo.com
3      http://msn.com
4      http://google.com
5      http://yahoo.com
6      http://askjeeves.com
Run Code Online (Sandbox Code Playgroud)

如何从此表中删除重复项?

activerecord ruby-on-rails

5
推荐指数
3
解决办法
1927
查看次数

用于与 Localstack 一起使用的 Terraform Override Provider

我有一个包含 Terraform 代码的 Git 存储库,该代码正在部署到 AWS 中。我将 Localstack 添加到此存储库,以便我可以在计划之前进行更高级别的验证测试并将其应用到我的真实 AWS 账户中。为了使用 Localstack,我必须使用自定义端点创建一个新的提供程序:

provider "aws" {
  alias  = "real"
  region = "${local.aws_region}"
}

provider "aws" {
  alias                       = "fake"
  region                      = "${local.aws_region}"
  access_key                  = "fake"
  secret_key                  = "fake"
  skip_credentials_validation = true
  skip_metadata_api_check     = true
  skip_requesting_account_id  = true

  endpoints {
    dynamodb = "http://localhost:4566"
    lambda   = "http://localhost:4566"
    kinesis  = "http://localhost:4566"
  }
}
Run Code Online (Sandbox Code Playgroud)

如何在不重复代码的情况下使用 Localstack 的一个提供商和 AWS 的一个提供商?

terraform localstack

5
推荐指数
1
解决办法
1870
查看次数

Webdriver Watir Ruby Chrome 版本

我想用不同版本的 Chrome 进行测试。如何使用 Watir 和 Ruby 指向特定的 Chrome 可执行文件/版本?

ruby watir

4
推荐指数
1
解决办法
713
查看次数

Ruby将字符串转换为哈希

我将配置数据存储在以平面文件编写的哈希中.我想将哈希值导入我的类中,以便我可以调用相应的方法.

example.rb

{ 
  :test1 => { :url => 'http://www.google.com' }, 
  :test2 => {
    { :title => 'This' } => {:failure => 'sendemal'}
  }
}
Run Code Online (Sandbox Code Playgroud)

simpleclass.rb

class Simple
  def initialize(file_name)
    # Parse the hash
    file = File.open(file_name, "r")
    @data = file.read
    file.close
  end

  def print
    @data
  end

a = Simple.new("simpleexample.rb")
b = a.print
puts b.class   # => String
Run Code Online (Sandbox Code Playgroud)

如何将任何"Hashified"字符串转换为实际的哈希?

ruby hash

3
推荐指数
1
解决办法
9919
查看次数

如何从哈希中的字符串中删除空格

这是我的例子:

hash = {"buy"=>"Buy ", "quantity"=>"3 ", "get"=>"Get ", "reward"=>"1 ", "free"=>"Free"}

def stripit(value)
  #value.gsub!('B', 'C')
  value.gsub!('/\s+/', '')
  value
end

newhash = hash.update(hash){|key,value| stripit(value)}
puts newhash.inspect
Run Code Online (Sandbox Code Playgroud)

gsub 在价值上工作 - 第一个评论的替换工作 - 但由于某种原因,它不是删除空格.

如何从哈希值中删除空格?

ruby hash

3
推荐指数
2
解决办法
2220
查看次数

PHP将关联数组的键值存储到Simple Array中

我无法绕过这头,任何帮助都会很棒 ......

我有一个数组$ stores,其结构如下:

Array
(
[0] => Array
    (
        [id] => 123
        [name] => 'Store A'
    )

[1] => Array
    (
        [id] => 345
        [name] => 'Store B'
    )

[2] => Array
    (
        [id] => 567
        [name] => 'Store C'
    )

[3] => Array
    (
        [id] => 789
        [name] => 'Store D'
    )
)
Run Code Online (Sandbox Code Playgroud)

我想从这个数组中提取'id'值到一个看起来像这样的简单数组:

$simple = array(123,345,567,789);
Run Code Online (Sandbox Code Playgroud)

php arrays associative-array

2
推荐指数
1
解决办法
2368
查看次数

Umask jsvc日志文件

我在Centos 6上有一个由jsvc托管的应用程序。与之一起创建了许多日志。我的问题是jsvc正在使用077权限创建那些日志,除了root以外其他任何人都无法访问。日志应该对任何人都是可读的。

jsvc.exec -server -Xms1024M -Xmx2048M -cp myapp.jar -errfile /var/log/myapp/error.log -wait 60 com.myawesomecompany.mysuite.myapp

-rw------- 1 root root   370 Feb 26 16:03 error.log
Run Code Online (Sandbox Code Playgroud)

如何覆盖默认权限,以便生成的任何新日志都具有022权限?

java umask jsvc

2
推荐指数
1
解决办法
796
查看次数