|
| 1 | +[](https://codeclimate.com/github/Stromweld/autopatch_ii) |
| 2 | +[](https://codeclimate.com/github/Stromweld/autopatch_ii) |
| 3 | + |
1 | 4 | # autopatch_ii |
2 | 5 |
|
3 | | -TODO: Enter the cookbook description here. |
| 6 | +## Description |
| 7 | + |
| 8 | +Chef Cookbook for automatically patching nodes on a specific schedule (weekday, hour, and minute). Handles weekly or monthly patching routines with or without node splay for large environments. |
| 9 | + |
| 10 | +Much of this code was copied from chef cookbook auto-patch written by Brian Flad. I've modified it to work with windows and use windows more flexible task scheduling with some magic to get it to also work with linux cron. |
| 11 | + |
| 12 | +## Requirements |
| 13 | + |
| 14 | +### Platforms |
| 15 | + |
| 16 | +* RHEL based platforms |
| 17 | +* Windows |
| 18 | + |
| 19 | +### Cookbooks |
| 20 | + |
| 21 | +* cron |
| 22 | +* logrotate |
| 23 | + |
| 24 | +## Attributes |
| 25 | + |
| 26 | +| Attribute | Default | Comment | |
| 27 | +| ------------- | ------------- | ------------- | |
| 28 | +| ['autopatch_ii']['disable'] | false | Boolean, enable or disable patches | |
| 29 | +| ['autopatch_ii']['domain'] | 'example.com' | String, Domain server resides in | |
| 30 | +| ['autopatch_ii']['task_username'] | 'SYSTEM' | String, Used only for winows task scheduling | |
| 31 | +| ['autopatch_ii']['task_frequency'] | :monthly | Symbol, one of either :monthly or :weekly | |
| 32 | +| ['autopatch_ii']['task_frequency_modifier'] | 'THIRD' | String, used to denote which week of the month you want to run the task | |
| 33 | +| ['autopatch_ii']['task_months'] | 'JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV' | String, CSV list of short names for months you want the task to run in, * is used for all months | |
| 34 | +| ['autopatch_ii']['task_days'] | 'TUE' | String, which days of the week in short form you want the task to run on | |
| 35 | +| ['autopatch_ii']['task_start_time'] | '04:00' | String, Military time setting for when to run patches | |
| 36 | +| ['autopatch_ii']['working_dir'] | node['os'] == 'windows' ? 'C:\chef_autopatch' : '/var/log/chef_autopatch' | String, Directory for log file and temp files | |
| 37 | +| ['autopatch_ii']['download_install_splay_max_seconds'] | 3600 | Integer, Max allowed random time to wait before downloading and installing patches, this way we don't overwhelm on premise patch repo | |
| 38 | +| ['autopatch_ii']['email_notification_mode'] | 'Always' | String, whether to send email after patches and before reboot with status of patch install | |
| 39 | +| ['autopatch_ii' ]['email_to_addresses'] | '" [email protected]"' | String, email address for nodes to send the email to | |
| 40 | +| ['autopatch_ii']['email_from_address'] | "#{node['hostname']}@example.com" | String, email address the email came from | |
| 41 | +| ['autopatch_ii']['email_smtp_server'] | 'smtp.example.com' | String, email server to forward the email to, relay with no authentication is recommended | |
| 42 | +| ['autopatch_ii']['auto_reboot_enabled'] | true | Boolean, to reboot the server automatically after patches have been installed or to leave it for manual reboot | |
| 43 | +| ['autopatch_ii']['updates_to_skip'] | [] | Array of Strings, package names to skip during patches on linux | |
| 44 | +| ['autopatch_ii']['update_command_options'] | '' | String, any additional options to be passed to the yum command on linux | |
| 45 | +| ['autopatch_ii']['private_lin_autopatch_disabled_programmatically'] | false | Boolean, DO NOT MODIFY THIS, this is modified programatically based on if cron job should skip this month or not | |
| 46 | + |
| 47 | +## Recipes |
| 48 | + |
| 49 | +* `recipe[autopatch_ii]` configures automatic patching and patches server on first chef-client run |
| 50 | +* `recipe[autopatch_ii::firstrun_patches]` creates a lock file and runs patches for the first time, afterwards doesn't run as long as lock file exists on the filesystem. |
| 51 | +* `recipe[autopatch_ii::linux]` creates cron job and sets up autopatch scripts |
| 52 | +* `recipe[autopatch_ii::windows]` creates windows task and sets up autopatch scripts |
| 53 | + |
| 54 | +## Usage |
| 55 | + |
| 56 | +* Change any attributes to fit your patching cycle |
| 57 | +* Add `recipe[autopatch_ii]` to your node's run list |
| 58 | + |
| 59 | +### Weekly automatic patching |
| 60 | + |
| 61 | +Just use the `node["autopatch_ii"]['task_frequency'] = :weekly` attribute to override the monthly setting. |
| 62 | + |
| 63 | +### Automatic patching of large numbers of nodes |
| 64 | + |
| 65 | +If you're auto patching many nodes at once, you can optionally modify the splay to prevent denial of service against your network, update server(s), and resources: |
| 66 | + |
| 67 | +* Adding `node["autopatch_ii"]["splay"]` |
| 68 | + |
| 69 | +### Using roles to specify auto patching groups |
| 70 | + |
| 71 | +If you'd like to specify groups of nodes for auto patching, you can setup roles. |
| 72 | + |
| 73 | +Say you want to auto patch some nodes at 8am and some at 10pm on your monthly |
| 74 | +"patch day" of the fourth Wednesday every month. |
| 75 | + |
| 76 | +If you have a base role (you do, right?), you can save duplicating attributes |
| 77 | +and specify some base information first: |
| 78 | + |
| 79 | + "autopatch_ii" => { |
| 80 | + "task_frequency" => :weekly, |
| 81 | + "task_days" => 'TUE' |
| 82 | + } |
| 83 | + |
| 84 | +Example role that then could be added to 8am nodes: |
| 85 | + |
| 86 | + name "autopatch-0800" |
| 87 | + description "Role for automatically patching nodes at 8am on patch day." |
| 88 | + default_attributes( |
| 89 | + "autopatch_ii" => { |
| 90 | + "task_start_time" => '08:00' |
| 91 | + } |
| 92 | + ) |
| 93 | + run_list( |
| 94 | + "recipe[autopatch_ii]" |
| 95 | + ) |
| 96 | + |
| 97 | +Example role that then could be added to 10pm nodes: |
| 98 | + |
| 99 | + name "autopatch-2200" |
| 100 | + description "Role for automatically patching nodes at 10pm on patch day." |
| 101 | + default_attributes( |
| 102 | + "autopatch_ii" => { |
| 103 | + "task_start_time" => '22:00' |
| 104 | + } |
| 105 | + ) |
| 106 | + run_list( |
| 107 | + "recipe[autopatch_ii]" |
| 108 | + ) |
| 109 | + |
| 110 | +### Disabling automatic patching |
| 111 | + |
| 112 | +* Specify `node["autopatch_ii"]["disable"]` to true |
| 113 | +* Run chef-client on your node |
| 114 | + |
| 115 | +## License and Author |
| 116 | + |
| 117 | +Author:: Brian Flad ( <[email protected]>) |
| 118 | + |
| 119 | +Author:: Corey Hemminger ( <[email protected]>) |
| 120 | + |
| 121 | +Copyright:: 2017 |
| 122 | + |
| 123 | +Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at |
| 124 | + |
| 125 | +<http://www.apache.org/licenses/LICENSE-2.0> |
4 | 126 |
|
| 127 | +Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. |
0 commit comments