2017-11-14 17 views
0

로컬 시스템의 GCP 패커 인스턴스에서 serverspec 테스트를 실행하는 데 어려움을 겪고 있습니다. GCP에 이미지를 생성하기 위해 다음과 같이 나는 포장의 JSON 구성 파일을 만들었습니다GCP 패커 인스턴스에서 서버 스펙 테스트를 실행할 수 없습니다.

{ 
"variables": { 
    "project": "gcp-project", 
    "image_family": "centos-7", 
    "username": "centos", 
    "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-local", 
     "command": "rake spec TARGET_HOST=remotehost" 
    } 
] 

}

그리고 난 SSH로 구성되어 로컬 컴퓨터와 spec_helper.rb에서 serverspec 테스트를 실행 rake spec TARGET_HOST=(ip of packer instance)을 실행하고

host = ENV['TARGET_HOST'] 
options = Net::SSH::Config.for(host) 
options[:user] = 'centos' 
set :host,  options[:host_name] || host 
set :ssh_options, options 

및 Rakefile은 특정 폴더에서 테스트를 실행하도록 구성되어 있습니다.

포장 빌드 명령을 실행 한 후 packer build -var-file=variables.json sftp.json| tee build.log

그것 때문에 내가 SSH를 사용하여 로컬 컴퓨터에서 serverspec 테스트를 실행할 수 없습니다 나는이 오류에

==> 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: Executing local command: rake spec TARGET_HOST=1.2.3.4 
    googlecompute: An error occurred while loading ./spec/1.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 [email protected] 

를 기록 빌드

Net::SSH::AuthenticationFailed: 
Authentication failed for user [email protected] 

패커와 함께 실패 리모트 팩커 인스턴스.

어떤 대답이라도 이해 될 것입니다. 매우 감사합니다.

+0

이 serverspec Rakefile/spec_helper 상호 작용의 모범 사례에서 어색한 편차의 종류이지만, 답변으로 아래에서 의미하는 바는 이것이'net-ssh' gem을 사용할 때의 문제이며 packer, serverspec, rspec 또는 gcp와는 관련이 없습니다. ssh 키나 암호를 사용하여 net-ssh 인수에 추가하여이 문제를 해결하십시오. –

+0

@MattSchuchard 나는 serverpec Rakefile/spec_helper 상호 작용에서 벗어난 것이 아니므로, 유효한'private_key_file'에 대한 경로로 ~/.ssh/config 파일에 키 경로를 설정하지 않았다. 어쨌든 serverspec 가이드 라인에 따라 서버 스펙을 구현하려고 시도합니다. –

답변

0

centos 사용자의 비밀번호가 누락되었습니다.

spec_helper.rb이 추가 :

options[:password] = ENV['LOGIN_PASSWORD'] 

을 그리고 ajust 당신의 shell-local에 :

{ 
    "type": "shell-local", 
    "command": "LOGIN_PASSWORD='{{ user `sftp_password` }}' rake spec TARGET_HOST=remotehost" 
} 
+0

CentOS 및 최신 데비안 이미지의 루트 ssh 액세스가 기본적으로 비활성화되어 있기 때문에'centos' 사용자는'ssh_username'으로 생성 될 때 비밀번호가 없습니다. packer documentation에서 ssh_username을 packoo가 sudo 액세스로 생성하는 모든 사용자로 설정하십시오. https://www.packer.io/docs/builders/googlecompute.html –

+1

그리고 어떻게 서버 스펙이 인증 될 것이라고 기대 했습니까? 그런 다음 알려진 'ssh_private_key_file'을 사용해야합니다. https://www.packer.io/docs/templates/communicator.html#ssh_private_key_file 및 https://devops.stackexchange.com/a/1349 –

+0

감사합니다. , 당신 말이 맞았습니다.'ssh_private_key_file'이 누락되었습니다.'~/.ssh/config' 파일에 유효한'private_key_file' 경로가있는 항목을 만들었습니다. –