在终止具有非零退出状态的源后Packer失败:2

时间:2016-02-09 18:59:07

标签: amazon-ec2 ansible ami packer

我正在尝试使用packer和ansible创建一个新的ami。我承认这两者都很新。 (我过去曾经使用过面料和木偶。)我注意到我使用的是亚马逊linux base ami,并决定改为使用centos图像。这带来了一些我克服的障碍。但是,我现在收到以下错误。它似乎很奇怪,它发生在"终止源AWS实例......"

之后
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: No AMIs to cleanup
==> amazon-ebs: Deleting temporary security group...
==> amazon-ebs: Deleting temporary keypair...
Build 'amazon-ebs' errored: Script exited with non-zero exit status: 2

==> Some builds didn't complete successfully and had errors:
--> amazon-ebs: Script exited with non-zero exit status: 2

==> Builds finished but no artifacts were created.

包装工json是:

{
    "variables": {
        "ansible_staging_directory": "/tmp/packer-provisioner-ansible-local",
        "role": "",
        "aws_base_ami": "",
        "aws_base_instance_type": "",
        "aws_region": "",
        "aws_vpc_id": "",
        "aws_subnet": "",
        "aws_ssh_user": "",
        "company_version": "",
        "additional_aws_users": "{{env `AWS_PROD_ID`}}",        
        "aws_access_key": "<redacted>",
        "aws_secret_key": "<redacted>"
    },
    "builders": [{
        "type": "amazon-ebs",
        "region": "{{user `aws_region`}}",
        "vpc_id": "{{user `aws_vpc_id`}}",
        "subnet_id": "{{user `aws_subnet`}}",
        "source_ami": "{{user `aws_base_ami`}}",
        "instance_type": "{{user `aws_base_instance_type`}}",
        "ssh_username": "{{user `aws_ssh_user`}}",
        "ssh_pty": true,
        "associate_public_ip_address": true,
        "ami_users": "{{user `additional_aws_users`}}",
        "ami_name": "company-{{user `role`}}-{{user `company_version`}} {{timestamp}}",
        "tags": {
            "Role": "company-{{user `role`}}",
            "Version": "{{user `company_version`}}",
            "Timestamp": "{{timestamp}}"
        }
    }],
    "provisioners": [
        {
            "type": "shell",
            "inline": "mkdir -p {{user `ansible_staging_directory`}}"
        },
        {
            "type": "file",
            "source": "../roles",
            "destination": "{{user `ansible_staging_directory`}}"
        },
        {
            "type": "file",
            "source": "../files",
            "destination": "{{user `ansible_staging_directory`}}"
        },
        {
            "type": "shell",
            "inline": [
                "sudo yum -y update",
                "sudo update-alternatives --set python /usr/bin/python2.7",
                "sudo yum -y install emacs",
                "sudo yum -y install telnet",
                "sudo yum -y install epel-release",
                "sudo yum -y install python-pip",
                "sudo yum -y install gcc libffi-devel python-devel openssl-devel",              
                "sudo pip install ansible"
            ]
        },
        {
            "type": "ansible-local",
            "playbook_file": "packer-playbook.yml",
            "group_vars": "../group_vars",
            "extra_arguments": [
                "-t {{user `role`}}",
                "--extra-vars 'aws_access_key={{user `aws_access_key`}} aws_secret_key={{user `aws_secret_key`}}'"
            ]
        }
    ]
}

我使用的基本影像是ami-d440a6e7。

非常感谢任何指导。我还没有能够找到退出代码2或任何类似的东西。

更新

我已经确定删除该行:

"sudo update-alternatives --set python /usr/bin/python2.7",

从上一个shell配置程序中,它似乎完成了该步骤并转移到ansible。但是,ansible失败了,因为它取决于python2.7

2 个答案:

答案 0 :(得分:0)

好的,所以看来删除

"sudo update-alternatives --set python /usr/bin/python2.7",

我能够克服上述错误,发现由于我的ansible playbook检查的几个python依赖项在centos yum repo中的命名方式与amazon-linux repo中的命名方式不同,因此无法使用。例如,python27-setuptools只是python-setuptools而python27-Cython只是Cython。

感谢大家的帮助和指导!

答案 1 :(得分:0)

感谢您的这篇文章。 这指导我在尝试运行某些脚本时解决几乎相似的问题(vmware工具安装)。

问题是我在vmtools脚本朗姆酒之前运行我的清理脚本,这意味着一些必需的文件已经丢失。

vmware-iso: tar: /tmp/VMwareTools-*.tar: Cannot open: No such file or directory
vmware-iso: tar: Error is not recoverable: exiting now

==&GT; vmware-iso:停止虚拟机... ==&GT; vmware-iso:删除输出目录... 构建&#39; vmware-iso&#39;错误:脚本以非零退出状态退出:2

这是我的配置脚本:

provisioners": [
  "execute_command": "echo 'rhel' | {{.Vars}} sudo -S -E sh -eux '{{.Path}}'",
  "scripts": [
    "scripts/common/metadata.sh",
    "scripts/centos/networking.sh",
    "scripts/common/sshd.sh",
    "scripts/rhel-ec/rhel-user.sh",
    "scripts/rhel-ec/vmtools.sh",
    "scripts/rhel-ec/cleanup.sh",
    "scripts/centos/cleanup.sh",
    "scripts/common/minimize.sh"
  ],
  "type": "shell"
}

],

解决方案是安排我的脚本。这意味着在cleanup.sh运行之前首先运行vmtools.sh脚本。