I have thus far successfully installed Chef-server, chef--manage (UI bit), got knife ssl check
working.
Now, I am running the below command
knife ec2 server create -r 'role[webserver]' -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2
I have kept my access key and secret key in knife.rb file as like below:
# 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"
Unfortunately, I'm getting the error below:
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)
The below command also produces an error
PS C:\Users\hp\chef-repo> knife ec2 server create -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2 -VVV
Error Output:
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)
-- As suggested by HumayunM, I tried with --ss-key option, but that seems not to be working as well.
Command:
PS C:\Users\hp\chef-repo> knife ec2 server create -I ami-0970010f37c4f9c8d -f t2.micro --region ap-southeast-2 -S Test2AWS.pem -VVV
Output:
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>'
And file, also does exist:
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
Iteration 3: Used the command
Command:
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
Output:
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
Note: I do not have any role, I am just using a single command on command line. I'm very new to Chef.
Any idea what is the issue? Also, instead of command line can we yaml file as like in Ansible?
The error is reported here:
ec2_server_create.rb:1185:in `create_key_pair':
you are also supposed to specify a keypair to ssh into EC2, like that: