Unable to run serverspec test on GCP packer instance

96 views
Skip to first unread message

noisy noisyBits

unread,
Nov 14, 2017, 6:02:58 PM11/14/17
to Packer
Hi all,
 
I am struggling to run serverspec test on GCP packer instance from local machine.
I have created a packer json config file as follows to create an image on GCP (provisioners run shell script to create an user account for sftp on packer instance):
{
    "variables": {
        "project": "gcp-project",
        "image_family": "centos-7",
        "username": "centos",
        "sftp_username": "",
        "sftp_password":"",
        "zone": "us-central1-c",
        "version": "latest"
    },

    "builders": [
        {
            "type": "googlecompute",
            "account_file": "account.json",
            "project_id": "{{user `project`}}",
            "zone": "{{user `zone`}}",
            "source_image":"centos-7-v20171025",
            "image_name": "sftp-{{user `image_family`}}-{{user `version`}}-{{timestamp}}",
            "image_family": "{{user `image_family`}}",
            "image_description": "sftp - from packer",
            "ssh_username": "{{user `username`}}",
            "machine_type": "g1-small"
        }
    ],

    "provisioners": [
        {
            "type"  : "shell",
            "inline": [
                "sudo adduser {{user `sftp_username`}}",
                "sudo echo -e '{{user `sftp_password`}}\n{{user `sftp_password`}}\n' | sudo passwd {{user `sftp_username`}}",
                "sudo mkdir -p /var/sftp/upload",
                "sudo chown root:root /var/sftp",
                "sudo chmod 755 /var/sftp",
                "sudo chown {{user `sftp_username`}}:{{user `sftp_username`}} /var/sftp/upload"
            ]
        },
        {
            "type": "shell-local",
            "command": "rake spec TARGET_HOST=remotehost"
        }
    ]
}

and i am executing rake spec TARGET_HOST=(ip of packer instance) to run serverspec test from local machine and spec_helper.rb is configured with ssh login as follows:

host = ENV['TARGET_HOST']

options = Net::SSH::Config.for(host)

options[:user] = 'centos'

set :host, options[:host_name] || host
set :ssh_options, options

and Rakefile is configured to run test from specific folder.

after running packer build command "packer build -var-file=variables.json sftp.json| tee build.log"

it fails with 
Net::SSH::AuthenticationFailed:
Authentication failed for user cen...@35.193.23.13

Details packer build log
==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Using image: centos-7-v20171025
==> googlecompute: Creating instance...
    googlecompute: Loading zone: us-central1-c
    googlecompute: Loading machine type: g1-small
    googlecompute: Loading network: default
    googlecompute: Requesting instance creation...
    googlecompute: Waiting for creation operation to complete...
    googlecompute: Instance has been created!
==> googlecompute: Waiting for the instance to become running...
    googlecompute: IP: 1.2.3.4
==> googlecompute: Waiting for SSH to become available...
==> googlecompute: Connected to SSH!
==> googlecompute: Provisioning with shell script: /var/folders/vh/03_qyfy91r757mypx3qcgjfh0000gn/T/packer-shell043898698
    googlecompute: New password: BAD PASSWORD: The password contains the user name in some form
    googlecompute: Changing password for user nifi.
    googlecompute: passwd: all authentication tokens updated successfully.
    googlecompute: Retype new password:
==> googlecompute: Executing local command: rake spec TARGET_HOST=host
    googlecompute:
    googlecompute: An error occurred while loading ./spec/31.2.3.4/sftp_spec.rb.
    googlecompute: On host `1.2.3.4'
    googlecompute: Failure/Error:
    googlecompute:   describe service('sshd'), :if => os[:family] == 'redhat' do
    googlecompute:     it { should be_enabled }
    googlecompute:     it { should be_running }
    googlecompute:   end
    googlecompute: Net::SSH::AuthenticationFailed:
    googlecompute:   Authentication failed for user cen...@35.193.23.13


I am not able to ssh to this temporary packer instance and serverspec test fail to run.

any answer will be appreciated. thanks very much.

Regards
Nirmal

Rickard von Essen

unread,
Nov 15, 2017, 2:30:02 AM11/15/17
to packe...@googlegroups.com

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/mitchellh/packer/issues
IRC: #packer-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Packer" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/837f40a5-1759-4d39-a2b0-dd61940a78bc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

noisy noisyBits

unread,
Nov 15, 2017, 10:46:49 AM11/15/17
to Packer
Rickard von Essen

Thanks you so much for your help.
To unsubscribe from this group and stop receiving emails from it, send an email to packer-tool...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages