ローカルマシンからGCPパッカーインスタンスでserverspec testを実行するのが苦労しています。 GCP上の画像を作成するために、次のように私は、パッカーのJSON設定ファイルを作成しました:GCPパッカーインスタンスでserverspec testを実行できません
{
"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]
パッカーで失敗しますリモートパッカーインスタンス上にあります。
任意の回答があります。どうもありがとう。
これはserverspec Rakefile/spec_helper相互作用のベストプラクティスから厄介偏差の一種であるが、しかし、その答えとして、これは純粋に 'net-ssh'宝石の使用に伴う問題であり、packer、serverspec、rspec、またはgcpとは無関係です。この問題を解決するには、sshキーまたはパスワードを使用してnet-ssh引数に追加します。 –
@MattSchuchard私は、serverpec Rakefile/spec_helperのやりとりから逸脱しているわけではありません。鍵のパスを有効な 'private_key_file'へのパスで〜/ .ssh/configファイルに設定していませんでした。とにかく、サーバ仕様ガイドライン –