无法从厨师工作站创建 EC2 实例
unable to create an EC2 instance from chef-workstation
到目前为止,我已经成功安装了 Chef-server,chef--manage(UI 位),knife ssl check
正常工作。
现在,我是运行下面的命令
knife ec2 server create -r 'role[webserver]' -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2
我已将访问密钥和密钥保存在 knife.rb 文件中,如下所示:
# See https://docs.getchef.com/config_rb_knife.html for more information on knife configuration options
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name "tuser"
client_key "#{current_dir}/tuser.pem"
chef_server_url "https://3.227.234.41/organizations/testdemo"
cookbook_path ["#{current_dir}/../cookbooks"]
knife[:aws_access_key_id] = "XXXXXXXXXXXXXX"
knife[:aws_secret_access_key] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
不幸的是,我收到以下错误:
INFO: Using configuration from C:/Users/hp/.chef/knife.rb
DEBUG: Checking if we need to accept Chef license to bootstrap node
DEBUG: Reading products and relationships...
DEBUG: Successfully read products and relationships
DEBUG: License acceptance required for chef version: 15
DEBUG: Searching for the following licenses: ["infra-client", "inspec"]
DEBUG: Found license chef_infra_client at C:/Users/hp/.chef/accepted_licenses/chef_infra_client
DEBUG: Found license inspec at C:/Users/hp/.chef/accepted_licenses/inspec
DEBUG: Missing licenses remaining: []
DEBUG: All licenses present
DEBUG: Using AWS region ap-southeast-2
DEBUG: Setting up AWS connection using aws_access_key_id: AKIAXXXXXXXXXXXXXXXX aws_secret_access_key: cW0YXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX aws_session_token:
Traceback (most recent call last):
10: from C:/opscode/chef-workstation/bin/knife:383:in `<main>'
9: from C:/opscode/chef-workstation/bin/knife:383:in `load'
8: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/bin/knife:24:in `<top (required)>'
7: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/application/knife.rb:163:in `run'
6: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:229:in `run'
5: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:485:in `run_with_pretty_exceptions'
4: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/local_mode.rb:42:in `with_server_connectivity'
3: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:486:in `block in run_with_pretty_exceptions'
2: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife/bootstrap.rb:566:in `run'
1: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:594:in `plugin_validate_options!'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:1185:in `create_key_pair': undefined method `delete' for nil:NilClass (NoMethodError)
下面的命令也会产生错误
PS C:\Users\hp\chef-repo> knife ec2 server create -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2 -VVV
错误输出:
INFO: Using configuration from C:/Users/hp/.chef/knife.rb
DEBUG: Checking if we need to accept Chef license to bootstrap node
DEBUG: Reading products and relationships...
DEBUG: Successfully read products and relationships
DEBUG: License acceptance required for chef version: 15
DEBUG: Searching for the following licenses: ["infra-client", "inspec"]
DEBUG: Found license chef_infra_client at C:/Users/hp/.chef/accepted_licenses/chef_infra_client
DEBUG: Found license inspec at C:/Users/hp/.chef/accepted_licenses/inspec
DEBUG: Missing licenses remaining: []
DEBUG: All licenses present
DEBUG: Using AWS region ap-southeast-2
DEBUG: Setting up AWS connection using aws_access_key_id: AKIAXXXXXXXXXXXXXXXX aws_secret_access_key: cW0YXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX aws_session_token:
Traceback (most recent call last):
10: from C:/opscode/chef-workstation/bin/knife:383:in `<main>'
9: from C:/opscode/chef-workstation/bin/knife:383:in `load'
8: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/bin/knife:24:in `<top (required)>'
7: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/application/knife.rb:163:in `run'
6: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:229:in `run'
5: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:485:in `run_with_pretty_exceptions'
4: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/local_mode.rb:42:in `with_server_connectivity'
3: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:486:in `block in run_with_pretty_exceptions'
2: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife/bootstrap.rb:566:in `run'
1: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:594:in `plugin_validate_options!'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:1185:in `create_key_pair': undefined method `delete' for nil:NilClass (NoMethodError)
-- 根据 HumayunM 的建议,我尝试使用 --ss-key 选项,但似乎效果不佳。
命令:
PS C:\Users\hp\chef-repo> knife ec2 server create -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2 -S Test2AWS.pem -VVV
输出:
INFO: Using configuration from C:/Users/hp/.chef/knife.rb
DEBUG: Checking if we need to accept Chef license to bootstrap node
DEBUG: Reading products and relationships...
DEBUG: Successfully read products and relationships
DEBUG: License acceptance required for chef version: 15
DEBUG: Searching for the following licenses: ["infra-client", "inspec"]
DEBUG: Found license chef_infra_client at C:/Users/hp/.chef/accepted_licenses/chef_infra_client
DEBUG: Found license inspec at C:/Users/hp/.chef/accepted_licenses/inspec
DEBUG: Missing licenses remaining: []
DEBUG: All licenses present
DEBUG: Using AWS region ap-southeast-2
DEBUG: Setting up AWS connection using aws_access_key_id: AKIAXXXXXXXXXXXXXXXX aws_secret_access_key: cW0YXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX aws_session_token:
ERROR: The key pair 'Test2AWS.pem' does not exist
DEBUG: C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:20:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/idempotency_token.rb:17:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/param_converter.rb:24:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/response_paging.rb:10:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/seahorse/client/plugins/response_target.rb:23:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/seahorse/client/request.rb:70:in `send_request'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-ec2-1.156.0/lib/aws-sdk-ec2/client.rb:35503:in `run_instances'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:995:in `create_ec2_instance'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:321:in `plugin_create_instance!'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife/bootstrap.rb:571:in `run'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:486:in `block in run_with_pretty_exceptions'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/local_mode.rb:42:in `with_server_connectivity'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:485:in `run_with_pretty_exceptions'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:229:in `run'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/application/knife.rb:163:in `run'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/bin/knife:24:in `<top (required)>'
C:/opscode/chef-workstation/bin/knife:383:in `load'
C:/opscode/chef-workstation/bin/knife:383:in `<main>'
还有文件,也确实存在:
PS C:\Users\hp\chef-repo> ls .\Test2AWS.pem
Directory: C:\Users\hp\chef-repo
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 21-May-20 6:43 PM 1692 Test2AWS.pem
迭代 3:使用命令
命令:
PS>knife ec2 server create -r 'role[webserver]' -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2 -S Test2AWS -i Test2AWS.pem --connection-user ec2-user -VVV
输出:
INFO: Using configuration from C:/Users/hp/.chef/knife.rb
DEBUG: Checking if we need to accept Chef license to bootstrap node
DEBUG: Reading products and relationships...
DEBUG: Successfully read products and relationships
DEBUG: License acceptance required for chef version: 15
DEBUG: Searching for the following licenses: ["infra-client", "inspec"]
DEBUG: Found license chef_infra_client at C:/Users/hp/.chef/accepted_licenses/chef_infra_client
DEBUG: Found license inspec at C:/Users/hp/.chef/accepted_licenses/inspec
DEBUG: Missing licenses remaining: []
DEBUG: All licenses present
DEBUG: Using AWS region ap-southeast-2
DEBUG: Setting up AWS connection using aws_access_key_id: AKIAXXXXXXXXXXXXXXXX aws_secret_access_key: cW0YXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX aws_session_token:
Waiting for EC2 to create the instance
Instance ID: i-05d0c4bda0435e609
Flavor: t2.micro
Image: ami-0970010f37c4f9c8d
Region: ap-southeast-2
Availability Zone: ap-southeast-2b
AWS Tags: Name: i-05d0c4bda0435e609
SSH Key: Test2AWS
T2/T3 Unlimited: Disabled
Public DNS Name: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
Public IP Address: 13.211.81.106
Private DNS Name: ip-172-31-12-62.ap-southeast-2.compute.internal
Private IP Address: 172.31.12.62
Waiting for sshd access to become available
SSH Target Address: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com(public_dns_name)
DEBUG: No ssh gateway found, making a direct connection
DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
注意:我没有任何角色,我只是在命令行上使用一个命令。我是 Chef 的新手。
知道问题出在哪里吗?另外,我们可以像在 Ansible 中一样使用 yaml 文件代替命令行吗?
这里报错:
ec2_server_create.rb:1185:在`create_key_pair':
您还应该指定一个密钥对以通过 ssh 连接到 EC2,如下所示:
knife ec2 server create -r 'role[webserver]' -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2 -S <name you gave when you created the key pair at aws console> -i <path to pem file> --ssh-user <ubuntu/ec2-user>
到目前为止,我已经成功安装了 Chef-server,chef--manage(UI 位),knife ssl check
正常工作。
现在,我是运行下面的命令
knife ec2 server create -r 'role[webserver]' -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2
我已将访问密钥和密钥保存在 knife.rb 文件中,如下所示:
# See https://docs.getchef.com/config_rb_knife.html for more information on knife configuration options
current_dir = File.dirname(__FILE__)
log_level :info
log_location STDOUT
node_name "tuser"
client_key "#{current_dir}/tuser.pem"
chef_server_url "https://3.227.234.41/organizations/testdemo"
cookbook_path ["#{current_dir}/../cookbooks"]
knife[:aws_access_key_id] = "XXXXXXXXXXXXXX"
knife[:aws_secret_access_key] = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
不幸的是,我收到以下错误:
INFO: Using configuration from C:/Users/hp/.chef/knife.rb
DEBUG: Checking if we need to accept Chef license to bootstrap node
DEBUG: Reading products and relationships...
DEBUG: Successfully read products and relationships
DEBUG: License acceptance required for chef version: 15
DEBUG: Searching for the following licenses: ["infra-client", "inspec"]
DEBUG: Found license chef_infra_client at C:/Users/hp/.chef/accepted_licenses/chef_infra_client
DEBUG: Found license inspec at C:/Users/hp/.chef/accepted_licenses/inspec
DEBUG: Missing licenses remaining: []
DEBUG: All licenses present
DEBUG: Using AWS region ap-southeast-2
DEBUG: Setting up AWS connection using aws_access_key_id: AKIAXXXXXXXXXXXXXXXX aws_secret_access_key: cW0YXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX aws_session_token:
Traceback (most recent call last):
10: from C:/opscode/chef-workstation/bin/knife:383:in `<main>'
9: from C:/opscode/chef-workstation/bin/knife:383:in `load'
8: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/bin/knife:24:in `<top (required)>'
7: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/application/knife.rb:163:in `run'
6: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:229:in `run'
5: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:485:in `run_with_pretty_exceptions'
4: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/local_mode.rb:42:in `with_server_connectivity'
3: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:486:in `block in run_with_pretty_exceptions'
2: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife/bootstrap.rb:566:in `run'
1: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:594:in `plugin_validate_options!'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:1185:in `create_key_pair': undefined method `delete' for nil:NilClass (NoMethodError)
下面的命令也会产生错误
PS C:\Users\hp\chef-repo> knife ec2 server create -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2 -VVV
错误输出:
INFO: Using configuration from C:/Users/hp/.chef/knife.rb
DEBUG: Checking if we need to accept Chef license to bootstrap node
DEBUG: Reading products and relationships...
DEBUG: Successfully read products and relationships
DEBUG: License acceptance required for chef version: 15
DEBUG: Searching for the following licenses: ["infra-client", "inspec"]
DEBUG: Found license chef_infra_client at C:/Users/hp/.chef/accepted_licenses/chef_infra_client
DEBUG: Found license inspec at C:/Users/hp/.chef/accepted_licenses/inspec
DEBUG: Missing licenses remaining: []
DEBUG: All licenses present
DEBUG: Using AWS region ap-southeast-2
DEBUG: Setting up AWS connection using aws_access_key_id: AKIAXXXXXXXXXXXXXXXX aws_secret_access_key: cW0YXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX aws_session_token:
Traceback (most recent call last):
10: from C:/opscode/chef-workstation/bin/knife:383:in `<main>'
9: from C:/opscode/chef-workstation/bin/knife:383:in `load'
8: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/bin/knife:24:in `<top (required)>'
7: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/application/knife.rb:163:in `run'
6: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:229:in `run'
5: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:485:in `run_with_pretty_exceptions'
4: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/local_mode.rb:42:in `with_server_connectivity'
3: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:486:in `block in run_with_pretty_exceptions'
2: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife/bootstrap.rb:566:in `run'
1: from C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:594:in `plugin_validate_options!'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:1185:in `create_key_pair': undefined method `delete' for nil:NilClass (NoMethodError)
-- 根据 HumayunM 的建议,我尝试使用 --ss-key 选项,但似乎效果不佳。
命令:
PS C:\Users\hp\chef-repo> knife ec2 server create -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2 -S Test2AWS.pem -VVV
输出:
INFO: Using configuration from C:/Users/hp/.chef/knife.rb
DEBUG: Checking if we need to accept Chef license to bootstrap node
DEBUG: Reading products and relationships...
DEBUG: Successfully read products and relationships
DEBUG: License acceptance required for chef version: 15
DEBUG: Searching for the following licenses: ["infra-client", "inspec"]
DEBUG: Found license chef_infra_client at C:/Users/hp/.chef/accepted_licenses/chef_infra_client
DEBUG: Found license inspec at C:/Users/hp/.chef/accepted_licenses/inspec
DEBUG: Missing licenses remaining: []
DEBUG: All licenses present
DEBUG: Using AWS region ap-southeast-2
DEBUG: Setting up AWS connection using aws_access_key_id: AKIAXXXXXXXXXXXXXXXX aws_secret_access_key: cW0YXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX aws_session_token:
ERROR: The key pair 'Test2AWS.pem' does not exist
DEBUG: C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/seahorse/client/plugins/raise_response_errors.rb:15:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/jsonvalue_converter.rb:20:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/idempotency_token.rb:17:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/param_converter.rb:24:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/aws-sdk-core/plugins/response_paging.rb:10:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/seahorse/client/plugins/response_target.rb:23:in `call'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-core-3.94.1/lib/seahorse/client/request.rb:70:in `send_request'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/aws-sdk-ec2-1.156.0/lib/aws-sdk-ec2/client.rb:35503:in `run_instances'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:995:in `create_ec2_instance'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/knife-ec2-1.0.36/lib/chef/knife/ec2_server_create.rb:321:in `plugin_create_instance!'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife/bootstrap.rb:571:in `run'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:486:in `block in run_with_pretty_exceptions'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/local_mode.rb:42:in `with_server_connectivity'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:485:in `run_with_pretty_exceptions'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/knife.rb:229:in `run'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/lib/chef/application/knife.rb:163:in `run'
C:/opscode/chef-workstation/embedded/lib/ruby/gems/2.6.0/gems/chef-15.10.12-universal-mingw32/bin/knife:24:in `<top (required)>'
C:/opscode/chef-workstation/bin/knife:383:in `load'
C:/opscode/chef-workstation/bin/knife:383:in `<main>'
还有文件,也确实存在:
PS C:\Users\hp\chef-repo> ls .\Test2AWS.pem
Directory: C:\Users\hp\chef-repo
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 21-May-20 6:43 PM 1692 Test2AWS.pem
迭代 3:使用命令
命令:
PS>knife ec2 server create -r 'role[webserver]' -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2 -S Test2AWS -i Test2AWS.pem --connection-user ec2-user -VVV
输出:
INFO: Using configuration from C:/Users/hp/.chef/knife.rb
DEBUG: Checking if we need to accept Chef license to bootstrap node
DEBUG: Reading products and relationships...
DEBUG: Successfully read products and relationships
DEBUG: License acceptance required for chef version: 15
DEBUG: Searching for the following licenses: ["infra-client", "inspec"]
DEBUG: Found license chef_infra_client at C:/Users/hp/.chef/accepted_licenses/chef_infra_client
DEBUG: Found license inspec at C:/Users/hp/.chef/accepted_licenses/inspec
DEBUG: Missing licenses remaining: []
DEBUG: All licenses present
DEBUG: Using AWS region ap-southeast-2
DEBUG: Setting up AWS connection using aws_access_key_id: AKIAXXXXXXXXXXXXXXXX aws_secret_access_key: cW0YXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX aws_session_token:
Waiting for EC2 to create the instance
Instance ID: i-05d0c4bda0435e609
Flavor: t2.micro
Image: ami-0970010f37c4f9c8d
Region: ap-southeast-2
Availability Zone: ap-southeast-2b
AWS Tags: Name: i-05d0c4bda0435e609
SSH Key: Test2AWS
T2/T3 Unlimited: Disabled
Public DNS Name: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
Public IP Address: 13.211.81.106
Private DNS Name: ip-172-31-12-62.ap-southeast-2.compute.internal
Private IP Address: 172.31.12.62
Waiting for sshd access to become available
SSH Target Address: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com(public_dns_name)
DEBUG: No ssh gateway found, making a direct connection
DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
.DEBUG: ssh timed out: ec2-13-211-81-106.ap-southeast-2.compute.amazonaws.com
注意:我没有任何角色,我只是在命令行上使用一个命令。我是 Chef 的新手。
知道问题出在哪里吗?另外,我们可以像在 Ansible 中一样使用 yaml 文件代替命令行吗?
这里报错:
ec2_server_create.rb:1185:在`create_key_pair':
您还应该指定一个密钥对以通过 ssh 连接到 EC2,如下所示:
knife ec2 server create -r 'role[webserver]' -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2 -S <name you gave when you created the key pair at aws console> -i <path to pem file> --ssh-user <ubuntu/ec2-user>