-
Create new cookbook example
knife cookbook create example
-
Create file name foo.py, Open Editor for examples/files/default/foo.py
#!/usr/bin/python # Author: Sanjay Lokhande <[email protected]> import os print "I am %s, running a python script" % os.getlogin()
-
Open file example/recipes/default.rb
# # Cookbook Name:: example # Recipe:: default # # Copyright 2014, OpexSoftware # # All rights reserved - Do Not Redistribute # # filename = "foo.py" cmdline = "import os; print "I am %s, running on cmd " % os.getlogin()" # Copy foo.py cookbook_file "/tmp/foo.py" do source "foo.py" mode "0755" end # Execute sample python one liner # cmd: python -c "import os; print "I am %s, running on cmd " % os.getlogin()" execute 'who_am_i' do cwd '/tmp' command "python -c #{cmdline}" end # Execute python script execute 'run_my_python_script' do cwd '/tmp' command "python #{filename}" end
-
Now upload it to chef server
knife cookbook upload example
-
Add run list to node1
knife node run_list add node1 "recipe[example]"
-
Run chef-client
-
Open file example/recipes/default.rb again and update with following...
python "#{filename}" do cwd "/tmp" # can be list from https://docs.getchef.com/resource_python.html#Attributes action :run # see actions section below end
-
upload your cookbook again
knife cookbook upload example
-
Run chef-client again
-
Every good!
Last active
August 29, 2015 14:06
-
-
Save ravibhure/189c07843afc15b9ca75 to your computer and use it in GitHub Desktop.
Just an example
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment