/usr/share/ruby3.2/logger/log_device.rb:83:in `exist?':如果File.exist?(path),则不会隐式地将Array转换为String(TypeError)

alen0pnh  于 2023-04-05  发布在  Ruby
关注(0)|答案(2)|浏览(87)

我尝试在EC2上安装CodeDeploy agent,并遵循以下步骤:

sudo yum -y update
sudo yum -y install ruby
sudo yum -y install wget
cd /home/ec2-user
wget https://aws-codedeploy-us-east-1.s3.amazonaws.com/latest/install
sudo chmod +x ./install
sudo ./install auto

我可以看到一个名为install的文件被下载,ruby也被安装了ruby --version => ruby 3.2.1 (2023-02-08 revision 31819e82c8) [x86_64-linux],但是当我运行sudo ./install auto时,它在下面抛出了这个错误注意我已经在root user和ec2-user之间切换了,但是它不起作用!注意我没有Rudy代码要运行

/usr/share/ruby3.2/logger/log_device.rb:83:in `exist?': no implicit conversion of Array into String (TypeError)
          if File.exist?(path)
                         ^^^^
    from /usr/share/ruby3.2/logger/log_device.rb:83:in `set_dev'
    from /usr/share/ruby3.2/logger/log_device.rb:18:in `initialize'
    from /usr/share/ruby3.2/logger.rb:587:in `new'
    from /usr/share/ruby3.2/logger.rb:587:in `initialize'
    from ./install:43:in `new'
    from ./install:43:in `<main>'
qlfbtfca

qlfbtfca1#

我看到你在Udemy上学习Stephane的DevOps课程。我自己也遇到了一个问题,试图找出一个解决方案,将root级别的权限赋予ec2-user,并试图通过编辑logger_device.RB文件来遵循@anothermh的答案。
此问题是由于新的amazon 2023 AMI和Ruby Logger类之间的版本不兼容引起的。您需要做的是修复此问题,如下所示:

注意:请记住在创建新示例时重新分配IAM角色。
代码部署代理现在将成功安装并工作。希望这有帮助!

j7dteeu8

j7dteeu82#

这是install脚本的问题。请看第42-43行:

# if we are being run in a terminal, log to stdout and the log file.
@log = Logger.new(Proxy.new(File.open(log_file_path, 'a+'), $stdout))

这对Logger类不起作用:

if log.respond_to?(:path) and path = log.path
  if File.exist?(path)
    @filename = path
  end
end

因为传递给Logger.new的对象 * 确实 * 响应:path

def path
  @targets.map do |target|
    if target.respond_to?(:path)
      target.__send__(:path)
    else
      # default to to_s since it's just used as a label for log statements.
      target.__send__(:to_s)
    end
  end
end

我不知道为什么这个脚本是这样写的。也许它在Ruby的早期版本中是有效的。Logger类是一种垃圾,所以谁知道呢。
只需更改第43行,使其不使用Proxy类,选择记录到文件或记录到stdout:

@log = Logger.new($stdout)
# or
@log = Logger.new(File.open(log_file_path, 'a+'))

如果你真的关心,你可以把它设置为log to multiple destinations,但考虑到你只是想运行脚本,我认为你不关心这个。

相关问题