Skip to content

Instantly share code, notes, and snippets.

@mohanpedala
Last active June 6, 2017 18:48
Show Gist options
  • Save mohanpedala/fdc9df9f055faf98392f19911dc695cc to your computer and use it in GitHub Desktop.
Save mohanpedala/fdc9df9f055faf98392f19911dc695cc to your computer and use it in GitHub Desktop.
chef-bootstrap-node-rhel-7-aws

Boot Strapping a node reference doc

  1. Spin an instance in aws (rhel-7) tag it as chef-node.
  2. Spin up the chef-workstation and test the ssh connectivity between chef-workstation and chef-node
ssh -i ~/path/to/key.pem username@<ip/domainname>
  1. Exit the test session once connected.
  2. Start the bootstrap process using key-based authentication.
knife bootstrap ADDRESS --ssh-user USER --sudo --identity-file IDENTITY_FILE --node-name chef-node
  1. Verify the node the creation
knife node list
  1. To view the data about the node
knife node show chef-node
  1. Check the result by accessing the public ip of the chef-node in a webbrowser or run
$curl <ipaddress/fqdn> 

How did the above steps worked: node did an initial check-in with the Chef server and ran the learn_chef_httpd cookbook. That's because you specifed learn_chef_httpd as the --run-list argument.

  1. Updating cookbook to test on node.
update index.html >><h1> hello from <%= node[fqdn] %><h1>

update cookbook version metadata to 0.2.0 in metadata.rb in under learn_chef_httpd cookbook

Sematic versioning reference

MAJOR specifies a change that's incompatible with previous versions. MINOR specifies new functionality that's backwards-compatible with previous versions. PATCH specifies backwards-compatible bug fixes.

push the updated cookbook to the chef-server

knife cookbook upload learn_chef_httpd
  1. Updating node using key-based authentication, for other platforms
knife ssh 'name:node-name' 'sudo chef-client' --ssh-user USER --identity-file IDENTITY_FILE --attribute ipaddress

Desc : The 'name:node1-centos' part is the search query. It returns all nodes that have the name "node-name". In practice, you would have only one node with a given name. Recall that a search query supports multiple patterns. If you were to specify 'name:node1-*', which uses a wildcard pattern, knife ssh would run sudo chef-client on all nodes whose name begins with "node1-".

The --attribute part tells knife which node attribute to use when opening an SSH connection. The default is to use the node's FQDN. For learning purposes, here we specify ipaddress to use the node's IP address because your node may not have a resolvable FQDN. In practice, you might omit this argument if your node does have a resolvable FQDN.

Assigning ownership to the home page.

  1. Modify template by assigning owner, group and mode to the homepage.
  mode '0644'
  owner 'web_admin'
  group 'web_admin'
  1. Save the tempalte, update metadata.rb file to 0.3.0 and push it to the chef-server
knife cookbook upload learn_chef_httpd
  1. Run chef client using knife ssh to update changes in node
knife ssh 'name: chef-node' 'sudo chef-client' --ssh-user USER --identify-file IDENTITY_FILE --attribute ipaddress/fqdn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment