chef knife tricks: Add a node in an environment

 

Sometime during automation of a large deployment process, we have to bootstrap a node , create environment and add the node in that particular environment on the fly.

 

  1. Bootstraping :

knife bootstrap  slcn09vmf0209.us.ora.com -x root -P welcome1 -N node2

2. Create environment dynamically from inside the programme:(python here)


## Create an envtemplate with required values in it

envtemplate = """

{
"name": \""""+envname+"""\",
"description": "The master development branch",
"cookbook_versions": {
},
"json_class": "Chef:Environment",
"chef_type": "environment",
"default_attributes": {
"revrec":
{
"required_version": \""""+appVersion+"""\"

}
},
"override_attributes": {
}
}

##write the envtemplate in a file

with open("/tmp/"+envname+".json","w") as f:
f.write(envtemplate)
f.close()

## Create env from the teplate json file

subprocess.call("knife environment from file /tmp/"+envname+".json", shell=True)

3. Add the node in the environment:


knife exec -E 'nodes.find("name:node2") {|n| n.chef_environment("env209");n.save }'

 

Advertisements

About Divyashree - The GNULINUX Guy

I am a Linux and Opensource enthusiast. I started working on Linux early in 2007 while I was doing my Masters in Computer Science and passed out in 2010. Currently working as a DevOps Developer in in Public/Private cloud domain. my @github : https://github.com/kumarprd my @nagiosexchange : https://exchange.nagios.org/directory/Owner/divyaimca/1 my @linkedin : https://www.linkedin.com/in/priyadarshee-kumar-☁-a9415615
This entry was posted in ARTICLES, Configurtion management, DevOps, HOWTO, Programming and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s