Advertisement
Guest User

Untitled

a guest
Jun 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. # Lab 10: Assigning Roles
  2. In this lab we are going to start assigning roles to all nodes to categorize them by the role that they play in our infrastructure
  3. and to start managing the run lists for each category/class collectively.
  4.  
  5. ## Creating Roles
  6.  
  7.  
  8.  
  9.  
  10. # Roles
  11.  
  12. - To create a roles in chef DSL we need to create a folder named `roles` inside the repo directory `(myapp/roles)`.
  13. - A sample role file consist of the following,
  14. - Name
  15. - Description
  16. - Run_list
  17. - Attributes
  18.  
  19. - A sample role file is as follows `roles/sample.rb`
  20.  
  21. ```ruby
  22. name "starter"
  23. description "An example Chef role"
  24. run_list "recipe[starter]"
  25. override_attributes({
  26. "starter_name" => "starter",
  27. })
  28. ```
  29.  
  30. ## Defining Roles
  31.  
  32. - Now create a roles for application and load_balancer.
  33. - sysfoo/roles/app.rb
  34. - sysfoo/roles/lb.rb
  35.  
  36. - Add the following content to app.rb
  37.  
  38. File: sysfoo/roles/app.rb
  39.  
  40. ```console
  41. name "app"
  42. description "Tomcat Application Servers"
  43. run_list "recipe[base]", "recipe[tomcat]", "recipe[chef-client]", "recipe[sysfoo::deploy]"
  44. default_attributes({
  45. "chef_client" => { "interval" => 120,
  46. "splay" => 30
  47. }
  48. })
  49. ```
  50.  
  51. - Add the following content to lb.rb
  52.  
  53. ```ruby
  54. name "lb"
  55. description "HAProxy Load Balancers"
  56. run_list "recipe[base]", "recipe[myhaproxy]", "recipe[chef-client]"
  57. default_attributes({
  58. "chef_client" => { "interval" => 60,
  59. "splay" => 20
  60. }
  61. })
  62.  
  63. ```
  64.  
  65. ## Uploading Roles to the Server
  66.  
  67. - From the `myapp` directory using knife command upload the roles from file **app.rb** and **lb.rb**
  68.  
  69. ```console
  70. knife role from file app.rb lb.rb
  71. ```
  72.  
  73. ## Applying Roles to the Nodes (run_list)
  74.  
  75. - Now replace the existing run_list of nodes with roles.
  76. - Add run_list to node1
  77.  
  78. ```console
  79. knife node run_list set app1 "role[app]"
  80. ```
  81.  
  82. - Add run_list to node2
  83.  
  84. ```console
  85. knife node run_list set app2 "role[app]"
  86. ```
  87.  
  88. - Add run_list to node4
  89.  
  90. ```console
  91. knife node run_list set lb "role[lb]"
  92. ```
  93.  
  94. ## Run chef-client on all nodes
  95.  
  96. - Now we need to run `chef-client` on all nodes.
  97. - We can do this by passing a `sudo chef-client` command to all nodes using knife as follows
  98.  
  99. ```console
  100. knife ssh "*:*" -x devops -a ipaddress "sudo chef-client"
  101. ```
  102.  
  103. - Verify the changes using `ps aux | grep chef-client` on all nodes to find the time interval.
  104.  
  105. ```console
  106. knife ssh "*:*" -x devops -a ipaddress "ps aux | grep chef-client"
  107. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement