Linecook - A Chef Alternative

1,869 views

Published on

My talk at DeRailed in April, 2011

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,869
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
10
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Not dismissing Chef when I say that. The advantages over manually writing setup/maintenance script are not to be underestimated. But for the most part things you do with Chef are things you would otherwise do with shell scripts, and there are problems.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Just use the existing systems. Some ‘advanced’ techniques but all established, known systems\nPrior experience applies any learning will feed back into existing workflow\n\n
  • Able to bring an existing script to Linecook, then rework to make it more powerful or maintainable. You will work with scripts directly. Again all prior experience applies.\n\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Seems pointless, but here is where it gets cool.\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Linecook - A Chef Alternative

    1. 1. Linecook(A Chef Alternative) Simon Chiang
    2. 2. Chef
    3. 3. Ruby Chef
    4. 4. OpscodeRuby Chef
    5. 5. “Systems Integration Framework” Opscode Ruby Chef
    6. 6. “Systems Integration Framework” Opscode Ruby Open Source Chef
    7. 7. “Systems Integration Framework” Opscode Ruby Open Source Chef Automated
    8. 8. “Systems Integration Framework” Opscode Ruby Open Source Chef Scalable Automated
    9. 9. “Systems Integration Framework” Opscode Ruby Server Provisioning Open Source Chef Scalable Automated
    10. 10. “Systems Integration Framework” Opscode Ruby Server Provisioning Open Source Chef Scalable Automated Community
    11. 11. “Systems Integration Framework” Opscode Ruby Server Provisioning Open Source Chef Scalable Automated Community Hotness
    12. 12. An alternative to shell scripts
    13. 13. Never a quick Quickstart“Before installing Chef, you should take a moment tounderstand the various "flavors" of chef: client-server,chef-solo, and the Opscode Platform. Deciding whichone is right for you will impact your installationprocess. You may also want to take a quick look atChefs architecture to get an idea of what youreinstalling before you proceed.” http://wiki.opscode.com/display/chef/Installation
    14. 14. Not a script, but sort of...[lib/chef/provider/package/zypper.rb] @ 0.10.0.rc.0def install_package(name, version) if version run_command( :command => "zypper -n --no-gpg-checks install -l #{name}=#{version}" )
    15. 15. Not a script, but sort of...[lib/chef/provider/package/zypper.rb] @ 0.10.0.rc.0def install_package(name, version) if version run_command( :command => "zypper -n --no-gpg-checks install -l #{name}=#{version}" ) Fixed options :(
    16. 16. Not a script, but sort of...[lib/chef/provider/package/zypper.rb] @ 0.10.0.rc.0def install_package(name, version) if version run_command( :command => "zypper -n --no-gpg-checks install -l #{name}=#{version}" ) Fixed options :( Error for version="" https://github.com/opscode/chef/pull/27
    17. 17. Many moving parts http://wiki.opscode.com/display/chef/Architecture
    18. 18. Many moving partshttp://wiki.opscode.com/display/chef/Vagrant http://wiki.opscode.com/display/chef/Architecture
    19. 19. Many moving partshttp://wiki.opscode.com/display/chef/Vagrant http://community.opscode.com/cookbooks http://wiki.opscode.com/display/chef/Architecture
    20. 20. Alternative?
    21. 21. Shell Scripts!
    22. 22. LinecookA Shell Script Generator
    23. 23. Established Tools(bash, ssh, gems, VirtualBox)
    24. 24. Start with a Script End with a Script
    25. 25. Pretty quick QuickstartMake a serverMake a scriptRun script on server
    26. 26. Pretty quick QuickstartMake a server 1Make a scriptRun script on server
    27. 27. Pretty quick QuickstartMake a server 1Make a scriptRun script on server 2
    28. 28. Pretty quick QuickstartMake a server 1Make a script 3Run script on server 2
    29. 29. An ERB Trick...
    30. 30. How to Make a ServerVirtualBoxInstall OSSSH Key Exchange localhost
    31. 31. How to Make a ServerVirtualBox VirtualBoxInstall OSSSH Key Exchange localhost
    32. 32. How to Make a Server abox-ubuntuVirtualBox VirtualBoxInstall OSSSH Key Exchange localhost
    33. 33. How to Make a Server abox-ubuntuVirtualBox VirtualBoxInstall OSSSH Key Exchange localhost
    34. 34. Port Forwarding abox-ubuntuVBoxManage modifyvm abox --natpf1 abox-ssh,tcp,, 2220,,22 VirtualBox Access VM by ssh to localhost localhost ssh -p 2220 linecook@localhost
    35. 35. Lather, rinse abox-ubuntuVBoxManage modifyvm bbox --natpf1 bbox-ssh,tcp,, bbox-ubuntu 2221,,22 ... Repeat as needed localhost ssh -p 2221 linecook@localhost ssh -p 2220 linecook@localhost
    36. 36. AdvantagesNo special prerequisites on serversFast Access (fast enough for TDD)Cmdline controlMultiple VMsSnapshots
    37. 37. How to Run Scriptscat > script.sh <<"DOC"echo "# $(whoami)@$(hostname): helloworld!"DOCchmod +x script.shscp -P 2220 script.sh linecook@localhost:/tmp/script.shssh -p 2220 linecook@localhost -- /tmp/script.sh# linecook@abox-ubuntu: hello world!
    38. 38. Redundanycat > script.sh <<"DOC"echo "# $(whoami)@$(hostname): helloworld!"DOCchmod +x script.shscp -P 2220 script.sh linecook@localhost:/tmp/script.shssh -p 2220 linecook@localhost -- /tmp/script.sh# linecook@abox-ubuntu: hello world!
    39. 39. Use SSH Configmkdir configcat > config/ssh <<"DOC"Host aboxPort 2220User linecookHostname localhostDOCscp -F config/ssh script.sh abox:/tmp/script.shssh -F config/ssh abox -- /tmp/script.sh# linecook@abox-ubuntu: hello world!
    40. 40. Multiple Hostscat > config/ssh <<"DOC"Host aboxPort 2220Host bboxPort 2221Host *User linecookHostname localhostDOCscp -F config/ssh script.sh bbox:/tmp/script.shssh -F config/ssh bbox -- /tmp/script.sh# linecook@bbox-ubuntu: hello world!
    41. 41. Redundancycat > config/ssh <<"DOC"Host aboxPort 2220Host bboxPort 2221Host *User linecookHostname localhostDOCscp -F config/ssh script.sh bbox:/tmp/script.shssh -F config/ssh bbox -- /tmp/script.sh# linecook@bbox-ubuntu: hello world!
    42. 42. Redundancycat > config/ssh <<"DOC"Host aboxPort 2220Host bboxPort 2221Host *User linecookHostname localhostDOCscp -F config/ssh script.sh bbox:/tmp/script.shssh -F config/ssh bbox -- /tmp/script.sh# linecook@bbox-ubuntu: hello world!
    43. 43. Make a “Package” Run with Linecook[config/ssh] [packages/abox/script.sh]Host abox echo "# $(whoami)@$(hostname): helloPort 2220 world!" [packages/bbox/script.sh]Host bbox echo "# $(whoami)@$(hostname): HulloPort 2221 Wurld!"Host *User linecookHostname localhost linecook run --script script.sh --remote-dir /tmp abox bbox # linecook@abox-ubuntu: hello world! # linecook@bbox-ubuntu: Hullo Wurld!
    44. 44. Leverge Defaults[config/ssh] [packages/abox/run]Host abox echo "# $(whoami)@$(hostname): helloPort 2220 world!" [packages/bbox/run]Host bbox echo "# $(whoami)@$(hostname): HulloPort 2221 Wurld!"Host *User linecook script: runHostname localhost remote dir: ~/linecook hosts: * linecook run # linecook@abox-ubuntu: hello world! # linecook@bbox-ubuntu: Hullo Wurld!
    45. 45. Easy Way To Test![packages/abox/run]echo "hello world" > /tmp/message.txt[packages/abox/test]if [ $(cat /tmp/message.txt) == "hello world" ]then echo "# success"else echo "# fail"filinecook run --script test# faillinecook runlinecook run --script test# success
    46. 46. Cmdline Dev Cyclelinecook startlinecook runlinecook run --script testlinecook ssh aboxlinecook snapshot modifiedlinecook stoplinecook start --snapshot modified...
    47. 47. AdvantagesStandard use of SSHOne standard config fileOrdinary inputs (directories, scripts)Multiple VMsFlexible!
    48. 48. How to Make a Script
    49. 49. How to Make a Script (boring alert)
    50. 50. Start with a Script[packages/abox/run]echo "# I will not manually configure my server"linecook run# I will not manually configure my server
    51. 51. Convert to Recipe[packages/abox.yml]linecook: package: recipes: A package file run: abox[recipes/abox.rb]target <<"SCRIPT"echo "# I will not manually configure my server"SCRIPT
    52. 52. Convert to Recipe[packages/abox.yml]linecook: package: A tempfile recipes: (packages/abox/run) run: abox[recipes/abox.rb]target <<"SCRIPT"echo "# I will not manually configure my server"SCRIPT
    53. 53. Simplify[packages/abox.yml] If default, no{} manifest needed[recipes/abox.rb]target <<"SCRIPT"echo "# I will not manually configure my server"SCRIPT
    54. 54. Build and Run[packages/abox.yml]{}[recipes/abox.rb]target <<"SCRIPT"echo "# I will not manually configure my server"SCRIPTlinecook buildlinecook run# I will not manually configure my server
    55. 55. Ok... that was boring.
    56. 56. Use Recipe asContext for ERB
    57. 57. ERB Compiles to Rubyrequire erbcompiler = ERB::Compiler.new("<>")compiler.put_cmd = "target<<"compiler.insert_cmd = "target<<"compiler.compile "got <%= obj %>"# => "target<<"got "; target<<(( obj ).to_s)"
    58. 58. InstanceEval for Context class Recipe attr_accessor :target def initialize @target = "" end def obj "milk" end end code = "target<<"got "; target<<(( obj ).to_s)" recipe = Recipe.new recipe.instance_eval(code) recipe.target # => "got milk"
    59. 59. Make a Modulemodule Helper def get(obj) target<<"got "; target<<(( obj ).to_s) endendrecipe = Recipe.newrecipe.extend Helperrecipe.instance_eval %q{ get "milk" target << ", " get "cookies"}recipe.target# => "got milk, got cookies"
    60. 60. Make a Modulemodule Helper def get(obj) target<<"got "; target<<(( obj ).to_s) endendrecipe = Recipe.newrecipe.extend Helperrecipe.instance_eval %q{ get "milk" target << ", " get "cookies" This is a recipe!}recipe.target# => "got milk, got cookies"
    61. 61. Helpers[helpers/example/echo.erb]Write an echo statement(str)--echo "<%= str %>"[recipes/abox.rb]helpers "example"echo "# I will not manually configure my server"
    62. 62. Helpers[helpers/example/echo.erb] [lib/example.rb]Write an echo statement module Example(str) # Write an echo ...-- def echo(str)echo "<%= str %>" target<< "echo ";... end end[recipes/abox.rb]helpers "example"echo "# I will not manually configure my server"
    63. 63. Helpers[helpers/example/echo.erb] [lib/example.rb]Write an echo statement module Example(str) # Write an echo ...-- def echo(str)echo "<%= str %>" target<< "echo ";... end end[recipes/abox.rb]helpers "example"echo "# I will not manually configure my server"
    64. 64. Helpers[helpers/example/echo.erb] [lib/example.rb]Write an echo statement module Example(str) # Write an echo ...-- def echo(str)echo "<%= str %>" target<< "echo ";... end end[recipes/abox.rb]helpers "example"echo "# I will not manually configure my server"
    65. 65. Helpers[helpers/example/echo.erb] [lib/example.rb]Write an echo statement module Example(str) # Write an echo ...-- def echo(str)echo "<%= str %>" target<< "echo ";... end end[recipes/abox.rb]helpers "example"echo "# I will not manually configure my server"
    66. 66. Helpers[helpers/example/echo.erb] [lib/example.rb]Write an echo statement module Example(str) # Write an echo ...-- def echo(str)echo "<%= str %>" target<< "echo ";... end end[recipes/abox.rb]helpers "example"echo "# I will not manually configure my server"
    67. 67. Helpers[helpers/example/echo.erb] [lib/example.rb]Write an echo statement module Example(str) # Write an echo ...-- def echo(str)echo "<%= str %>" target<< "echo ";... end end[recipes/abox.rb]helpers "example"echo "# I will not manually configure my server"
    68. 68. Helpers[helpers/example/echo.erb]Write an echo statement(str)-- require "example"echo "<%= str %>" extend Example[recipes/abox.rb]helpers "example"echo "# I will not manually configure my server"
    69. 69. Helpers[helpers/example/echo.erb]Write an echo statement(str)--echo "<%= str %>"[recipes/abox.rb]helpers "example"echo "# I will not manually configure my server"linecook buildlinecook run# I will not manually configure my server
    70. 70. Capture (no write)[helpers/example/color.erb]Add color to a string(color, str) codes = Hash[*%W{red 0;31 white 1;37 blue 0;34}]--033[<%= codes[color.to_s] %>m<%= str %>033[0m[recipes/abox.rb]helpers "example"msg = "# I will not manually configure my server"echo _color("blue", msg)
    71. 71. Capture (no write)[helpers/example/color.erb]Add color to a string(color, str) codes = Hash[*%W{red 0;31 white 1;37 blue 0;34}]--033[<%= codes[color.to_s] %>m<%= str %>033[0m[recipes/abox.rb]helpers "example"msg = "# I will not manually configure my server"echo _color("blue", msg) Prefix with underscore String output used as input
    72. 72. Capture (no write)[helpers/example/color.erb]Add color to a string(color, str) codes = Hash[*%W{red 0;31 white 1;37 blue 0;34}]--033[<%= codes[color.to_s] %>m<%= str %>033[0m[recipes/abox.rb]helpers "example"msg = "# I will not manually configure my server"echo _color("blue", msg)linecook buildlinecook run# I will not manually configure my server
    73. 73. Recipes are Ruby[recipes/abox.rb]helpers "example"msg = "# I will not manually configure my server"3.times do echo _color("blue", msg)endlinecook buildlinecook run# I will not manually configure my server# I will not manually configure my server# I will not manually configure my server
    74. 74. AdvantagesEasily extensible DSLProduces ordinary modules Test as any other Ruby Distribute as Gems (versions, bundler)Reprocessing of outputAlso, kind of cool...
    75. 75. Linebook(Standard Library for Linecook)
    76. 76. Logic + Pipelines[recipes/demo.rb]helpers linebook/shellunless_ _file?(/tmp/message) do cat.to(/tmp/message).heredoc do writeln hello world! endendcat(/tmp/message)
    77. 77. Logic + Pipelines[packages/demo/run]if ! [ -f "/tmp/message" ]then cat > /tmp/message << HEREDOC_0hello world!HEREDOC_0ficat "/tmp/message"
    78. 78. Under ConstructionExit status checks, ‘stack trace’Helpers for login/suUser and File ManagementServer-side testing (assert_script)Installs, config, deployments, etc.
    79. 79. No need to wait!
    80. 80. LinecookAttributesHelpers Recipes PackagesFilesTemplates Server
    81. 81. Learn MoreGitHub: pinnacol/linecook.git pinnacol/linebook.gitMe: github.com/thinkerbot @thinkerbot
    82. 82. Thanks Pinnacol!
    83. 83. Thanks Derailed!
    84. 84. Questions?

    ×