hashicorp / packer

Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
http://www.packer.io
Other
15.09k stars 3.33k forks source link

aws --version fails inspec provisioner test in packer #9016

Closed colliwhopper closed 4 years ago

colliwhopper commented 4 years ago

Overview of the Issue

I've tried to test the aws-cli natively and via the packer inspec provisioner. All other inspec tests pass. But if I try and test the aws-cli installation in the provisioning AMI instance via the test "aws --version" I get an error. I've tried all sorts with $PATH settings, sourcing file afterwards etc, tried all the different ways to install the aws cli, but no joy.

Reproduction Steps

OS is CIS redhat 7 benchmark 2.2.0.13 level 1 (ami-0d52c8b892fe642d9)

packer provisioner section json extract:

    {
      "type": "inspec",
      "pause_before": "5s",
      "user": "root",
      "profile": "inspec/",
      "inspec_env_vars": [ "CHEF_LICENSE=accept"],
      "extra_arguments": [ "--shell", "--show-progress" ]
    }

tried above provisioner with different extra_arguments as well.

Packer Version

packer version 1.5.5 (March 25,2020)

Inspec Tests

# encoding: utf-8

control 'ami-jenkins-agent-tests' do
  title 'ami-jenkins-agent-tests'
  desc 'Verifies that all the ami-jenkins-agent AMI binaries respond as expected.'

  describe bash('aws --version') do
    its('exit_status') { should eq 0 }
  end

  describe bash('packer --version') do
    its('exit_status') { should eq 0 }
  end

  describe bash('terraform --version') do
    its('exit_status') { should eq 0 }
  end

  describe bash('vault --version') do
    its('exit_status') { should eq 0 }
  end

  describe bash('java -version') do
    its('exit_status') { should eq 0 }
  end

end

Log Fragments and crash.log files

(I switched real user for userremoved in the extract)

==> amazon-ebs: + echo /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/app/java/jdk1.8.0_241/bin
==> amazon-ebs: + aws --version
    amazon-ebs: aws-cli/1.18.37 Python/3.6.8 Linux/3.10.0-1062.12.1.el7.x86_64 botocore/1.15.37
==> amazon-ebs: Pausing 5s before the next provisioner...
==> amazon-ebs: Provisioning with Inspec...
==> amazon-ebs: Executing Inspec: inspec exec inspec/ --backend ssh --host 127.0.0.1 --key-files /var/folders/79/mbbd885571d4v2ls8gkkrv640000gq/T/packer-provisioner-inspec.255786504.key --user <userremoved> --port 53847 --input-file /var/folders/79/mbbd885571d4v2ls8gkkrv640000gq/T/packer-provisioner-inspec.475955655.yml --shell --show-progress
    amazon-ebs: F....
    amazon-ebs:
    amazon-ebs: Profile: validation checks (validation checks)
    amazon-ebs: Version: 1.0
    amazon-ebs: Target:  ssh://userremoved@127.0.0.1:53847
    amazon-ebs:
    amazon-ebs:   ×  ami-jenkins-agent-tests: ami-jenkins-agent-tests (1 failed)
    amazon-ebs:      ×  Bash command aws --version exit_status is expected to eq 0
    amazon-ebs:
    amazon-ebs:      expected: 0
    amazon-ebs:           got: 2
    amazon-ebs:
    amazon-ebs:      (compared using ==)
    amazon-ebs:
    amazon-ebs:      ✔  Bash command packer --version exit_status is expected to eq 0
    amazon-ebs:      ✔  Bash command terraform --version exit_status is expected to eq 0
    amazon-ebs:      ✔  Bash command vault --version exit_status is expected to eq 0
    amazon-ebs:      ✔  Bash command java -version exit_status is expected to eq 0
    amazon-ebs:
    amazon-ebs:
    amazon-ebs: Profile Summary: 0 successful controls, 1 control failure, 0 controls skipped
    amazon-ebs: Test Summary: 4 successful, 1 failure, 0 skipped
==> amazon-ebs: Provisioning step had errors: Running the cleanup provisioner, if present...
==> amazon-ebs: Terminating the source AWS instance...
==> amazon-ebs: Cleaning up any extra volumes...
==> amazon-ebs: No volumes to clean up, skipping
==> amazon-ebs: Deleting temporary security group...
==> amazon-ebs: Deleting temporary keypair...
Build 'amazon-ebs' errored: Error executing Inspec: Non-zero exit status: exit status 100

Any ideas? I'm either missing something horribly obvious or this is a bug?

ghost commented 4 years ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.