【问题标题】:Cannot pinpoint error in creating a packer Ubuntu Image在创建打包程序 Ubuntu 映像时无法查明错误
【发布时间】:2021-10-20 12:44:59
【问题描述】:

我正在尝试将 consul 构建到 ubuntu 打包程序映像中。 Packer 会构建映像,但它存在一些问题。

具体这个问题:

==> amazon-ebs: debconf: (Dialog frontend will not work on a dumb terminal, an emacs shell buffer, or without a controlling terminal.)
==> amazon-ebs: debconf: falling back to frontend: Readline
==> amazon-ebs: debconf: unable to initialize frontend: Readline
==> amazon-ebs: debconf: (This frontend requires a controlling tty.)
==> amazon-ebs: debconf: falling back to frontend: Teletype
==> amazon-ebs: dpkg-preconfigure: unable to re-open stdin:

这是我的 Json 代码:

{
    "variables": {
        "aws_access_key": "{{ env `ACCESS_KEY` }}",
        "aws_secret_key": "{{ env `SECRET_KEY` }}"
    },

    "builders": [{
        "type": "amazon-ebs",
        "ami_name": "consul-client",
        "access_key": "{{ user `aws_access_key` }}",
        "secret_key": "{{ user `aws_secret_key` }}",
        "region": "eu-west-2", 
        "source_ami_filter": {

            "filters": {
            
            "name": "ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*",
            
            "root-device-type": "ebs",
            
            "virtualization-type": "hvm"
            
            },
            
            "owners": ["099720109477"],
            
            "most_recent": true
            
            },
        "instance_type": "t2.micro",
        "ssh_username": "ubuntu"


    }],

    "provisioners": [{
        "type": "shell", 
        "script": "./scripts/consul_client.sh"
    }]
}

这是我正在运行的脚本:

#!/bin/bash

echo "Hello Consul Client!"

# Install Consul.  This creates...
# 1 - a default /etc/consul.d/consul.hcl
# 2 - a default systemd consul.service file

curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add -
sudo apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install -y consul

# Modify the default consul.hcl file
cat > /tmp/consul.hcl.tmp <<- EOF
data_dir = "/opt/consul"
client_addr = "0.0.0.0"
ui_config{
  enabled = true
}
server = true
bind_addr = "0.0.0.0"
advertise_addr = "$local_ip"
bootstrap_expect=1
retry_join = ["provider=aws tag_key=Name tag_value=ConsulClient"]
EOF

sudo cp /tmp/consul.hcl.tmp /etc/consul.d/consul.hcl
rm -f /tmp/consul.hcl.tmp

# Start Consul
sudo systemctl start consul

在 AMI 部分的 AWS 控制台上,当源 ami 是 ubuntu 映像时,平台显示为其他 Linux。出于某种原因,我觉得它没有正确制作,而且我也无法通过 SSH 连接到实例,我认为这可能是问题。

【问题讨论】:

    标签: amazon-web-services ubuntu consul


    【解决方案1】:

    您应该能够通过在调用 shell 配置程序时将 DEBIAN_FRONTEND 环境变量设置为 noninteractive 来解决此错误。

    {
      "provisioners": [
        {
          "type": "shell",
          "script": "./scripts/consul_client.sh",
          "environment_vars": [
            "DEBIAN_FRONTEND=noninteractive"
          ]
        }
      ]
    }
    

    有关此参数的详细信息,请参阅 https://help.ubuntu.com/lts/installation-guide/amd64/ch05s03.htmlhttps://www.cyberciti.biz/faq/explain-debian_frontend-apt-get-variable-for-ubuntu-debian/

    【讨论】:

      猜你喜欢
      • 2021-04-09
      • 2020-10-18
      • 2018-08-23
      • 2011-04-22
      • 2018-02-14
      • 1970-01-01
      • 2017-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多