Skip to content

Commit 1cffae4

Browse files
committed
Merge pull request #45 from lrytz/usernames
Allow varying usernames
2 parents 8b39db3 + 747f3a4 commit 1cffae4

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

.chef/knife.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
current_dir = File.dirname(__FILE__)
44
log_level :info
55
log_location STDOUT
6-
node_name "#{ENV['USER']}"
7-
client_key "#{current_dir}/config/#{ENV['USER']}.pem"
6+
node_name "#{ENV.fetch('CHEF_USER', ENV['USER'])}"
7+
client_key "#{current_dir}/config/#{ENV.fetch('CHEF_USER', ENV['USER'])}.pem"
88
validation_client_name "#{ENV['CHEF_ORG']}-validator"
99
validation_key "#{current_dir}/config/#{ENV['CHEF_ORG']}-validator.pem"
1010
chef_server_url "https://api.opscode.com/organizations/#{ENV['CHEF_ORG']}"
@@ -13,5 +13,5 @@
1313
cookbook_path ["#{current_dir}/cookbooks"]
1414

1515
knife[:aws_credential_file] = "#{ENV['HOME']}/.aws/credentials"
16-
knife[:aws_ssh_key_id] = 'chef' # the pem file name without the .pem extension and it has to be located in: ~/.ssh/
16+
knife[:aws_ssh_key_id] = "typesafe-scala-aws-#{ENV.fetch('AWS_USER', ENV['USER'])}" # the pem file name without the .pem extension and it has to be located in: ~/.ssh/
1717
knife[:vault_mode] = 'client'

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,14 @@ For the CLI to work, you need:
152152
export CHEF_ORG="typesafe-scala"
153153
```
154154

155-
You can then generate and download your private key on https://www.chef.io/account/password. Put it to `.chef/config/$USER.pem`, then you can use knife without further config. See `.chef/knife.rb` for key locations.
155+
If your username on chef.io does not match the local username on your machine, you also need
156+
```
157+
export CHEF_USER="[username]"
158+
```
159+
160+
You can then generate and download your private key on https://www.chef.io/account/password. Put it to `.chef/config/$CHEF_USER.pem`, then you can use knife without further config. See `.chef/knife.rb` for key locations.
161+
162+
Test if knife works correctly by running `knife cookbook list`.
156163

157164
Obtain the organization validation key from Adriaan and put it to `.chef/config/$CHEF_ORG-validator.pem`. (Q: When is this key used exactly? https://docs.chef.io/chef_private_keys.html says it's when a new node runs `chef-client` for the first time.)
158165

@@ -322,12 +329,18 @@ Host jenkins-worker-windows-publish
322329

323330
# Launch instance on EC2
324331
## Create (ssh) key pair
332+
333+
If your username on AWS does not match the local username on your machine, define
334+
```
335+
export AWS_USER="[username]"
336+
```
337+
325338
```
326-
echo $(aws ec2 create-key-pair --key-name <YOUR_NAME> | jq .KeyMaterial) | perl -pe 's/"//g' > ~/.ssh/typesafe-scala-aws-$USER.pem
327-
chmod 0600 ~/.ssh/typesafe-scala-aws-$USER.pem
339+
echo $(aws ec2 create-key-pair --key-name $AWS_USER | jq .KeyMaterial) | perl -pe 's/"//g' > ~/.ssh/typesafe-scala-aws-$AWS_USER.pem
340+
chmod 0600 ~/.ssh/typesafe-scala-aws-$AWS_USER.pem
328341
```
329342

330-
In `knife.rb`, make sure `knife[:aws_ssh_key_id]` the pem file.
343+
In `knife.rb`, make sure `knife[:aws_ssh_key_id]` points to the pem file.
331344

332345

333346
## Selected AMIs

0 commit comments

Comments
 (0)