├── .editorconfig ├── .gitignore ├── .kitchen.yml ├── Berksfile ├── CHANGELOG.md ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── Thorfile ├── Vagrantfile ├── attributes └── default.rb ├── chefignore ├── files └── default │ └── tests │ └── minitest │ └── default_test.rb ├── metadata.rb ├── recipes ├── amazon.rb ├── debian.rb ├── default.rb ├── fedora.rb ├── linux-generic.rb ├── pld.rb ├── rhel.rb └── rhel7.rb ├── spec ├── attributes_spec.rb ├── recipes │ ├── amazon_spec.rb │ ├── debian_spec.rb │ ├── default_spec.rb │ ├── fedora_spec.rb │ ├── linux-generic_spec.rb │ ├── pld_spec.rb │ ├── rhel7_spec.rb │ └── rhel_spec.rb └── spec_helper.rb ├── templates ├── amazon │ └── clock.erb ├── centos │ └── clock.erb ├── default │ └── timezone.conf.erb ├── pld │ └── timezone.conf.erb └── redhat │ └── clock.erb └── test └── integration ├── default └── bats │ ├── date_output.bats │ ├── debian.bats │ └── etc_localtime.bats └── helpers └── bats └── helper.bash /.editorconfig: -------------------------------------------------------------------------------- 1 | # Text formatting specifications (see http://editorconfig.org/) 2 | 3 | # Stop looking for .editorconfig in any parent directories 4 | root = true 5 | 6 | [*] 7 | charset = utf-8 8 | end_of_line = lf 9 | insert_final_newline = true 10 | indent_style = space 11 | indent_size = 2 12 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | Berksfile.lock 3 | *~ 4 | *# 5 | .#* 6 | \#*# 7 | .*.sw[a-z] 8 | *.un~ 9 | /cookbooks 10 | 11 | # Bundler 12 | Gemfile.lock 13 | bin/* 14 | .bundle/* 15 | 16 | .kitchen/ 17 | .kitchen.local.yml 18 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver_plugin: vagrant 3 | driver_config: 4 | require_chef_omnibus: true 5 | 6 | platforms: 7 | - name: ubuntu-14.04 8 | - name: ubuntu-12.04 9 | - name: ubuntu-10.04 10 | - name: debian-7.8 11 | - name: centos-7.0 12 | - name: centos-6.6 13 | - name: centos-5.9 14 | - name: fedora-21 15 | - name: amazon-2014.09.1 16 | driver: 17 | name: ec2 18 | aws_access_key_id: <%= ENV['AWS_ACCESS_KEY'] || 'AWS_ACCESS_KEY' %> 19 | aws_secret_access_key: <%= ENV['AWS_SECRET_KEY'] || 'AWS_SECRET_KEY' %> 20 | aws_ssh_key_id: <%= ENV['AWS_SSH_KEY_ID'] || 'AWS_SSH_KEY_ID' %> 21 | region: us-east-1 22 | image_id: ami-b66ed3de 23 | flavor_id: m3.medium 24 | ebs_volume_size: 8 25 | ebs_delete_on_termination: true 26 | ebs_device_name: /dev/sda 27 | username: ec2-user 28 | 29 | suites: 30 | - name: default 31 | run_list: ["recipe[timezone-ii]"] 32 | attributes: 33 | tz: "Pacific/Tongatapu" # "TOT" 34 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | 5 | cookbook 'minitest-handler' 6 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # CHANGELOG for timezone-ii 2 | 3 | This file is used to list changes made in each version of timezone-ii. 4 | 5 | ## Work in progress: 6 | 7 | * Added experimental support for PLD (https://www.pld-linux.org; thanks to Elan 8 | Ruusamäe) 9 | * Added support for RHEL family (thanks to "fraD00r4") 10 | * Complete refresh of test-kitchen setup, including use of Berkshelf (thanks to 11 | Mike Conigliaro) 12 | * Added support for Amazon Linux as a special RHEL case 13 | * Debian recipe now logs a warning if dpkg-reconfigure is rewriting the value 14 | in /etc/timezone (for example, changing "UTC" to "Etc/UTC") 15 | * Because of the aforementioned behavior of dpkg-reconfigure, the default 16 | timezone for Debian-based platforms is now "Etc/UTC" 17 | 18 | ## 0.2.0: 19 | 20 | * Initial release of timezone-ii (as forked from timezone) 21 | * Added support for Fedora 22 | * Configurable paths for localtime data and tzdata tree (just in case someone 23 | wants them...) 24 | * For generic Linux timezone setting, a choice of copying or symlinking timezone 25 | data to localtime (copying is the default, to avoid surprises) 26 | 27 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'berkshelf' 4 | 5 | group :test, :integration do 6 | gem 'chefspec', '~> 4.1.1' 7 | end 8 | 9 | group :integration do 10 | gem 'test-kitchen', '~> 1.2' 11 | gem 'kitchen-vagrant' 12 | gem 'kitchen-ec2' 13 | end 14 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | CFPropertyList (2.2.8) 5 | addressable (2.3.6) 6 | berkshelf (3.2.2) 7 | addressable (~> 2.3.4) 8 | berkshelf-api-client (~> 1.2) 9 | buff-config (~> 1.0) 10 | buff-extensions (~> 1.0) 11 | buff-shell_out (~> 0.1) 12 | celluloid (~> 0.16.0) 13 | celluloid-io (~> 0.16.1) 14 | cleanroom (~> 1.0) 15 | faraday (~> 0.9.0) 16 | minitar (~> 0.5.4) 17 | octokit (~> 3.0) 18 | retryable (~> 1.3.3) 19 | ridley (~> 4.0) 20 | solve (~> 1.1) 21 | thor (~> 0.19) 22 | berkshelf-api-client (1.2.0) 23 | faraday (~> 0.9.0) 24 | buff-config (1.0.1) 25 | buff-extensions (~> 1.0) 26 | varia_model (~> 0.4) 27 | buff-extensions (1.0.0) 28 | buff-ignore (1.1.1) 29 | buff-ruby_engine (0.1.0) 30 | buff-shell_out (0.2.0) 31 | buff-ruby_engine (~> 0.1.0) 32 | builder (3.2.2) 33 | celluloid (0.16.0) 34 | timers (~> 4.0.0) 35 | celluloid-io (0.16.1) 36 | celluloid (>= 0.16.0) 37 | nio4r (>= 1.0.0) 38 | chef (11.16.4) 39 | chef-zero (~> 2.1, >= 2.1.4) 40 | diff-lcs (~> 1.2, >= 1.2.4) 41 | erubis (~> 2.7) 42 | ffi-yajl (~> 1.0) 43 | highline (~> 1.6, >= 1.6.9) 44 | mime-types (~> 1.16) 45 | mixlib-authentication (~> 1.3) 46 | mixlib-cli (~> 1.4) 47 | mixlib-config (~> 2.0) 48 | mixlib-log (~> 1.3) 49 | mixlib-shellout (~> 1.4) 50 | net-ssh (~> 2.6) 51 | net-ssh-multi (~> 1.1) 52 | ohai (~> 7.4) 53 | plist (~> 3.1.0) 54 | pry (~> 0.9) 55 | rest-client (>= 1.0.4, <= 1.6.7) 56 | chef-zero (2.2.1) 57 | ffi-yajl (~> 1.1) 58 | hashie (~> 2.0) 59 | mixlib-log (~> 1.3) 60 | rack 61 | chefspec (4.1.1) 62 | chef (>= 11.14) 63 | fauxhai (~> 2.0) 64 | rspec (~> 3.0) 65 | cleanroom (1.0.0) 66 | coderay (1.1.0) 67 | dep-selector-libgecode (1.0.2) 68 | dep_selector (1.0.3) 69 | dep-selector-libgecode (~> 1.0) 70 | ffi (~> 1.9) 71 | diff-lcs (1.2.5) 72 | erubis (2.7.0) 73 | excon (0.42.1) 74 | faraday (0.9.0) 75 | multipart-post (>= 1.2, < 3) 76 | fauxhai (2.2.0) 77 | net-ssh 78 | ohai 79 | ffi (1.9.6) 80 | ffi-yajl (1.3.1) 81 | ffi (~> 1.5) 82 | libyajl2 (~> 1.2) 83 | fission (0.5.0) 84 | CFPropertyList (~> 2.2) 85 | fog (1.26.0) 86 | fog-atmos 87 | fog-brightbox (~> 0.4) 88 | fog-core (~> 1.27, >= 1.27.1) 89 | fog-ecloud 90 | fog-json 91 | fog-profitbricks 92 | fog-radosgw (>= 0.0.2) 93 | fog-sakuracloud (>= 0.0.4) 94 | fog-softlayer 95 | fog-storm_on_demand 96 | fog-terremark 97 | fog-vmfusion 98 | fog-voxel 99 | fog-xml (~> 0.1.1) 100 | ipaddress (~> 0.5) 101 | nokogiri (~> 1.5, >= 1.5.11) 102 | fog-atmos (0.1.0) 103 | fog-core 104 | fog-xml 105 | fog-brightbox (0.7.1) 106 | fog-core (~> 1.22) 107 | fog-json 108 | inflecto (~> 0.0.2) 109 | fog-core (1.27.2) 110 | builder 111 | excon (~> 0.38) 112 | formatador (~> 0.2) 113 | mime-types 114 | net-scp (~> 1.1) 115 | net-ssh (>= 2.1.3) 116 | fog-ecloud (0.0.2) 117 | fog-core 118 | fog-xml 119 | fog-json (1.0.0) 120 | multi_json (~> 1.0) 121 | fog-profitbricks (0.0.1) 122 | fog-core 123 | fog-xml 124 | nokogiri 125 | fog-radosgw (0.0.3) 126 | fog-core (>= 1.21.0) 127 | fog-json 128 | fog-xml (>= 0.0.1) 129 | fog-sakuracloud (0.1.1) 130 | fog-core 131 | fog-json 132 | fog-softlayer (0.3.25) 133 | fog-core 134 | fog-json 135 | fog-storm_on_demand (0.1.0) 136 | fog-core 137 | fog-json 138 | fog-terremark (0.0.3) 139 | fog-core 140 | fog-xml 141 | fog-vmfusion (0.0.1) 142 | fission 143 | fog-core 144 | fog-voxel (0.0.2) 145 | fog-core 146 | fog-xml 147 | fog-xml (0.1.1) 148 | fog-core 149 | nokogiri (~> 1.5, >= 1.5.11) 150 | formatador (0.2.5) 151 | hashie (2.1.2) 152 | highline (1.6.21) 153 | hitimes (1.2.2) 154 | inflecto (0.0.2) 155 | ipaddress (0.8.0) 156 | json (1.8.1) 157 | kitchen-ec2 (0.8.0) 158 | fog 159 | test-kitchen (~> 1.0) 160 | kitchen-vagrant (0.15.0) 161 | test-kitchen (~> 1.0) 162 | libyajl2 (1.2.0) 163 | method_source (0.8.2) 164 | mime-types (1.25.1) 165 | mini_portile (0.6.1) 166 | minitar (0.5.4) 167 | mixlib-authentication (1.3.0) 168 | mixlib-log 169 | mixlib-cli (1.5.0) 170 | mixlib-config (2.1.0) 171 | mixlib-log (1.6.0) 172 | mixlib-shellout (1.6.1) 173 | multi_json (1.10.1) 174 | multipart-post (2.0.0) 175 | net-http-persistent (2.9.4) 176 | net-scp (1.2.1) 177 | net-ssh (>= 2.6.5) 178 | net-ssh (2.9.1) 179 | net-ssh-gateway (1.2.0) 180 | net-ssh (>= 2.6.5) 181 | net-ssh-multi (1.2.0) 182 | net-ssh (>= 2.6.5) 183 | net-ssh-gateway (>= 1.2.0) 184 | nio4r (1.0.1) 185 | nokogiri (1.6.5) 186 | mini_portile (~> 0.6.0) 187 | octokit (3.7.0) 188 | sawyer (~> 0.6.0, >= 0.5.3) 189 | ohai (7.4.0) 190 | ffi (~> 1.9) 191 | ffi-yajl (~> 1.0) 192 | ipaddress 193 | mime-types (~> 1.16) 194 | mixlib-cli 195 | mixlib-config (~> 2.0) 196 | mixlib-log 197 | mixlib-shellout (~> 1.2) 198 | systemu (~> 2.6.4) 199 | wmi-lite (~> 1.0) 200 | plist (3.1.0) 201 | pry (0.10.1) 202 | coderay (~> 1.1.0) 203 | method_source (~> 0.8.1) 204 | slop (~> 3.4) 205 | rack (1.6.0) 206 | rest-client (1.6.7) 207 | mime-types (>= 1.16) 208 | retryable (1.3.6) 209 | ridley (4.1.1) 210 | addressable 211 | buff-config (~> 1.0) 212 | buff-extensions (~> 1.0) 213 | buff-ignore (~> 1.1) 214 | buff-shell_out (~> 0.1) 215 | celluloid (~> 0.16.0) 216 | celluloid-io (~> 0.16.1) 217 | erubis 218 | faraday (~> 0.9.0) 219 | hashie (>= 2.0.2, < 3.0.0) 220 | json (>= 1.7.7) 221 | mixlib-authentication (>= 1.3.0) 222 | net-http-persistent (>= 2.8) 223 | retryable 224 | semverse (~> 1.1) 225 | varia_model (~> 0.4) 226 | rspec (3.1.0) 227 | rspec-core (~> 3.1.0) 228 | rspec-expectations (~> 3.1.0) 229 | rspec-mocks (~> 3.1.0) 230 | rspec-core (3.1.7) 231 | rspec-support (~> 3.1.0) 232 | rspec-expectations (3.1.2) 233 | diff-lcs (>= 1.2.0, < 2.0) 234 | rspec-support (~> 3.1.0) 235 | rspec-mocks (3.1.3) 236 | rspec-support (~> 3.1.0) 237 | rspec-support (3.1.2) 238 | safe_yaml (1.0.4) 239 | sawyer (0.6.0) 240 | addressable (~> 2.3.5) 241 | faraday (~> 0.8, < 0.10) 242 | semverse (1.2.1) 243 | slop (3.6.0) 244 | solve (1.2.1) 245 | dep_selector (~> 1.0) 246 | semverse (~> 1.1) 247 | systemu (2.6.4) 248 | test-kitchen (1.2.1) 249 | mixlib-shellout (~> 1.2) 250 | net-scp (~> 1.1) 251 | net-ssh (~> 2.7) 252 | safe_yaml (~> 1.0) 253 | thor (~> 0.18) 254 | thor (0.19.1) 255 | timers (4.0.1) 256 | hitimes 257 | varia_model (0.4.0) 258 | buff-extensions (~> 1.0) 259 | hashie (>= 2.0.2, < 3.0.0) 260 | wmi-lite (1.0.0) 261 | 262 | PLATFORMS 263 | ruby 264 | 265 | DEPENDENCIES 266 | berkshelf 267 | chefspec (~> 4.1.1) 268 | kitchen-ec2 269 | kitchen-vagrant 270 | test-kitchen (~> 1.2) 271 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Timezone II 2 | =========== 3 | 4 | The Timezone II cookbook contains recipes for installing the latest tzdata 5 | (a.k.a. IANA or Olson) timezone database and setting the timezone on your 6 | system. It is a fork of the [timezone cookbook by James 7 | Harton.](http://community.opscode.com/cookbooks/timezone) 8 | 9 | Requirements 10 | ------------ 11 | 12 | This cookbook is known to work with: 13 | 14 | * Amazon Linux 15 | * CentOS and RHEL 16 | * Debian 17 | * Fedora 18 | * Gentoo 19 | * PLD Linux 20 | * Ubuntu 21 | 22 | It _should_ work with any OS that uses the IANA/Olson timezone database and 23 | stores local timezone data in /etc/localtime (the only OS I know of that does 24 | _not_ do this is MS Windows). However, some OSs not mentioned above have their 25 | own system utility for setting the timezone, and this may overwrite the changes 26 | made by this cookbook. 27 | 28 | Attributes 29 | ---------- 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 49 | 50 | 51 | 52 | 53 | 54 | 56 | 57 | 58 | 59 | 60 | 61 | 64 | 65 | 66 |
KeyTypeDescriptionDefault
['tz']Stringthe timezone name as defined in tzdata"Etc/UTC" on Debian platforms; "UTC" for all other platforms
['timezone']['tzdata_dir']Stringthe path to the root of the tzdata files; the default value is for 48 | most known distributions of Linux/usr/share/zoneinfo
['timezone']['localtime_path']Stringthe path to the file used by the kernel to read the local timezone's 55 | settings; the default works for Linux and other *ix variants/etc/localtime
['timezone']['use_symlink']Booleanwhether to use a symlink into the tzdata tree rather than make a copy 62 | of the appropriate timezone data file (amazon and linux-generic recipes 63 | only)false
67 | 68 | Usage 69 | ----- 70 | 71 | Set the "tz" attribute to your desired timezone and include the "timezone-ii" 72 | recipe in your node's run list: 73 | 74 | { 75 | "name": "my_node", 76 | "tz": "Africa/Timbuktu", 77 | "run_list": [ 78 | "recipe[timezone-ii]" 79 | ] 80 | } 81 | 82 | ### timezone-ii::default 83 | 84 | The default recipe will first install or upgrade the IANA/Olson 85 | timezone database package for your OS (`timezone-data` on Gentoo, `tzdata` on 86 | all others). Then it will call one of the recipes below according to your 87 | node's platform. 88 | 89 | ### timezone-ii::amazon 90 | 91 | This changes the timezone on Amazon Linux by: 92 | 93 | 1. including the "timezone-ii::linux-generic" recipe, then 94 | 2. including the "timezone-ii::rhel" recipe. 95 | 96 | Refer to the sections for those recipes for details. 97 | 98 | ### timezone-ii::debian 99 | 100 | This changes the timezone on Debian-family platforms by: 101 | 102 | 1. writing the value of `tz` to `/etc/timezone`, then 103 | 2. calling `dpkg-reconfigure -f noninteractive tzdata`; 104 | 3. if `dpkg-reconfigure` amends the timezone value (e.g. by changing "UTC" to 105 | "Etc/UTC" or "EET" to "Europe/Helsinki"), it logs a warning. 106 | 107 | Only the `tz` attribute is used; all others are ignored. 108 | 109 | ### timezone-ii::fedora 110 | 111 | Because Fedora sets its timezone the same way RHEL 7 does, this simply 112 | includes the "timezone-ii::rhel7" recipe. 113 | 114 | ### timezone-ii::linux-generic 115 | 116 | This changes the time on all OSs without a more specific recipe. It assumes that 117 | the kernel gets data on the local timezone from `/etc/localtime`. (This is true 118 | for FreeBSD as well as Linux, so "linux-generic" is a bit of a misnomer.) 119 | 120 | What this recipe does: 121 | 122 | 1. verifies that the value of `tz` corresponds with a timezone data file under 123 | the directory specified in `timezone.tzdata_dir` (default: 124 | `/usr/share/zoneinfo`), then 125 | 2. creates a copy of or symbolic link to that data file in the path specified in 126 | `timezone.localtime_path` (default: `/etc/localtime`). 127 | 128 | The truthiness of `timezone.use_symlink` (default: `false`) determines whether a 129 | symlink or a copy is made. 130 | 131 | ### timezone-ii::pld 132 | 133 | This changes the timezone on PLD Linux. It writes the appropriate timezone 134 | configuration file, making use of the `tz` and `timezone.tz_datadir` attributes. 135 | Other attributes are ignored. 136 | 137 | ### timezone-ii::rhel 138 | 139 | This changes the timezone on RedHat Enterprise Linux (RHEL) and RHEL-family 140 | platforms such as CentOS. It is intended only for versions prior to 7.0, but 141 | should the recipe be called on a system with version 7.0 or newer, it will 142 | automatically include the "timezone-ii::rhel7" recipe and do nothing else. 143 | 144 | This recipe updates the `/etc/sysconfig/clock` file with the value of the `tz` 145 | attribute, then calls `tzdata-update` (if available) to change the timezone. 146 | All node attributes other than `tz` are ignored. 147 | 148 | ### timezone-ii::rhel7 149 | 150 | This changes the timezone on EL 7 platforms by calling `timedatectl 151 | set-timezone` with the value of `tz`. 152 | 153 | Only the `tz` attribute is used; all others are ignored. 154 | 155 | Contributing 156 | ------------ 157 | 1. Fork the [repository on GitHub](https://github.com/L2G/timezone-ii) 158 | 2. Create a named feature branch (like `add_component_x`) 159 | 3. Write your change 160 | 4. If at all possible, write tests for your change and ensure they all pass 161 | 5. Submit a pull request using GitHub 162 | 163 | Acknowledgements 164 | ---------------- 165 | 166 | Thanks to: 167 | 168 | * James Harton, for launching the timezone cookbook 169 | * Elan Ruusamäe, for PLD support 170 | * Mike Conigliaro, for bringing testing up to date 171 | * "fraD00r4", for RHEL/CentOS support 172 | 173 | 174 | License and Authors 175 | ------------------- 176 | 177 | Copyright © 2010 James Harton 178 | Copyright © 2013-2015 Lawrence Leonard Gilbert 179 | Copyright © 2013 Elan Ruusamäe 180 | Copyright © 2013 fraD00r4 181 | 182 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use 183 | this file except in compliance with the License. You may obtain a copy of the 184 | License at 185 | 186 | http://www.apache.org/licenses/LICENSE-2.0 187 | 188 | Unless required by applicable law or agreed to in writing, software distributed 189 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 190 | CONDITIONS OF ANY KIND, either express or implied. See the License for the 191 | specific language governing permissions and limitations under the License. 192 | -------------------------------------------------------------------------------- /Thorfile: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | 3 | require 'bundler' 4 | require 'bundler/setup' 5 | require 'berkshelf/thor' 6 | 7 | begin 8 | require 'kitchen/thor_tasks' 9 | Kitchen::ThorTasks.new 10 | rescue LoadError 11 | puts ">>>>> Kitchen gem not loaded, omitting tasks" unless ENV['CI'] 12 | end 13 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant.configure("2") do |config| 5 | # All Vagrant configuration is done here. The most common configuration 6 | # options are documented and commented below. For a complete reference, 7 | # please see the online documentation at vagrantup.com. 8 | 9 | config.vm.hostname = "timezone-ii-berkshelf" 10 | 11 | # Every Vagrant virtual environment requires a box to build off of. 12 | config.vm.box = 'opscode-ubuntu-14.04' 13 | 14 | # The url from where the 'config.vm.box' box will be fetched if it 15 | # doesn't already exist on the user's system. 16 | #config.vm.box_url = "https://dl.dropbox.com/u/31081437/Berkshelf-CentOS-6.3-x86_64-minimal.box" 17 | 18 | # Assign this VM to a host-only network IP, allowing you to access it 19 | # via the IP. Host-only networks can talk to the host machine as well as 20 | # any other machines on the same network, but cannot be accessed (through this 21 | # network interface) by any external networks. 22 | config.vm.network :private_network, ip: "33.33.33.10" 23 | 24 | # Create a public network, which generally matched to bridged network. 25 | # Bridged networks make the machine appear as another physical device on 26 | # your network. 27 | 28 | # config.vm.network :public_network 29 | 30 | # Create a forwarded port mapping which allows access to a specific port 31 | # within the machine from a port on the host machine. In the example below, 32 | # accessing "localhost:8080" will access port 80 on the guest machine. 33 | 34 | # Share an additional folder to the guest VM. The first argument is 35 | # the path on the host to the actual folder. The second argument is 36 | # the path on the guest to mount the folder. And the optional third 37 | # argument is a set of non-required options. 38 | # config.vm.synced_folder "../data", "/vagrant_data" 39 | 40 | # Provider-specific configuration so you can fine-tune various 41 | # backing providers for Vagrant. These expose provider-specific options. 42 | # Example for VirtualBox: 43 | # 44 | # config.vm.provider :virtualbox do |vb| 45 | # # Don't boot with headless mode 46 | # vb.gui = true 47 | # 48 | # # Use VBoxManage to customize the VM. For example to change memory: 49 | # vb.customize ["modifyvm", :id, "--memory", "1024"] 50 | # end 51 | # 52 | # View the documentation for the provider you're using for more 53 | # information on available options. 54 | 55 | # The path to the Berksfile to use with Vagrant Berkshelf 56 | # config.berkshelf.berksfile_path = "./Berksfile" 57 | 58 | # Enabling the Berkshelf plugin. To enable this globally, add this configuration 59 | # option to your ~/.vagrant.d/Vagrantfile file 60 | config.berkshelf.enabled = true 61 | 62 | # An array of symbols representing groups of cookbook described in the Vagrantfile 63 | # to exclusively install and copy to Vagrant's shelf. 64 | # config.berkshelf.only = [] 65 | 66 | # An array of symbols representing groups of cookbook described in the Vagrantfile 67 | # to skip installing and copying to Vagrant's shelf. 68 | # config.berkshelf.except = [] 69 | 70 | config.vm.provision :chef_solo do |chef| 71 | chef.json = { 72 | } 73 | 74 | chef.run_list = [ 75 | "recipe[timezone-ii::default]" 76 | ] 77 | end 78 | end 79 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # Use universal time if no other timezone is specified 2 | default.tz = value_for_platform_family( 3 | 'debian' => 'Etc/UTC', 4 | 'default' => 'UTC' 5 | ) 6 | 7 | # Path to tzdata directory 8 | default.timezone.tzdata_dir = '/usr/share/zoneinfo' 9 | 10 | # Path to file used by kernel for local timezone's data 11 | default.timezone.localtime_path = '/etc/localtime' 12 | 13 | # Whether to use a symlink to tzdata (instead of copying). 14 | # Used only in the linux-default recipe. 15 | default.timezone.use_symlink = false 16 | -------------------------------------------------------------------------------- /chefignore: -------------------------------------------------------------------------------- 1 | # Put files/directories that should be ignored in this file when uploading 2 | # or sharing to the community site. 3 | # Lines that start with '# ' are comments. 4 | 5 | # OS generated files # 6 | ###################### 7 | .DS_Store 8 | Icon? 9 | nohup.out 10 | ehthumbs.db 11 | Thumbs.db 12 | 13 | # SASS # 14 | ######## 15 | .sass-cache 16 | 17 | # EDITORS # 18 | ########### 19 | \#* 20 | .#* 21 | *~ 22 | *.sw[a-z] 23 | *.bak 24 | REVISION 25 | TAGS* 26 | tmtags 27 | *_flymake.* 28 | *_flymake 29 | *.tmproj 30 | .project 31 | .settings 32 | mkmf.log 33 | 34 | ## COMPILED ## 35 | ############## 36 | a.out 37 | *.o 38 | *.pyc 39 | *.so 40 | *.com 41 | *.class 42 | *.dll 43 | *.exe 44 | */rdoc/ 45 | 46 | # Testing # 47 | ########### 48 | .watchr 49 | .rspec 50 | spec/* 51 | spec/fixtures/* 52 | test/* 53 | features/* 54 | Guardfile 55 | Procfile 56 | 57 | # SCM # 58 | ####### 59 | .git 60 | */.git 61 | .gitignore 62 | .gitmodules 63 | .gitconfig 64 | .gitattributes 65 | .svn 66 | */.bzr/* 67 | */.hg/* 68 | */.svn/* 69 | 70 | # Berkshelf # 71 | ############# 72 | Berksfile 73 | Berksfile.lock 74 | cookbooks/* 75 | tmp 76 | 77 | # Cookbooks # 78 | ############# 79 | CONTRIBUTING 80 | CHANGELOG* 81 | 82 | # Strainer # 83 | ############ 84 | Colanderfile 85 | Strainerfile 86 | .colander 87 | .strainer 88 | 89 | # Vagrant # 90 | ########### 91 | .vagrant 92 | Vagrantfile 93 | 94 | # Travis # 95 | ########## 96 | .travis.yml 97 | -------------------------------------------------------------------------------- /files/default/tests/minitest/default_test.rb: -------------------------------------------------------------------------------- 1 | require 'minitest/spec' 2 | 3 | class TimezoneIiSpec < MiniTest::Chef::Spec 4 | 5 | describe_recipe 'timezone-ii::default' do 6 | 7 | it 'updates the timezone' do 8 | IO.read('/etc/localtime').must_equal IO.read("/usr/share/zoneinfo/#{node[:tz]}") 9 | end 10 | 11 | end 12 | 13 | end 14 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | name "timezone-ii" 2 | maintainer "Lawrence Leonard Gilbert" 3 | maintainer_email "larry@L2G.to" 4 | license "Apache 2.0" 5 | description "Configure the system timezone on *ix systems" 6 | version "0.2.9992" 7 | 8 | replaces "timezone" 9 | 10 | # These are platform versions where this cookbook has been tested at some point 11 | # in time 12 | supports "amazon" 13 | supports "centos" 14 | supports "debian" 15 | supports "fedora" 16 | supports "gentoo" 17 | supports "ubuntu" 18 | supports "pld" 19 | supports "redhat" 20 | -------------------------------------------------------------------------------- /recipes/amazon.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: timezone-ii 3 | # Recipe:: amazon 4 | # 5 | # Copyright 2014, Lawrence Leonard Gilbert 6 | # 7 | # Apache 2.0 License. 8 | # 9 | 10 | # Amazon recommends editing /etc/sysconfig/clock as in the rhel recipe, but then 11 | # creating a link for /etc/localtime. It doesn't have a tzdata-update command 12 | # like the other flavors of RHEL. 13 | # 14 | # Source: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html 15 | # (as of 2014-12-18) 16 | 17 | include_recipe 'timezone-ii::linux-generic' 18 | include_recipe 'timezone-ii::rhel' 19 | -------------------------------------------------------------------------------- /recipes/debian.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: timezone-ii 3 | # Recipe:: debian 4 | # 5 | # Copyright 2010, James Harton 6 | # Copyright 2013, Lawrence Leonard Gilbert 7 | # 8 | # Apache 2.0 License. 9 | # 10 | 11 | # Set timezone for Debian family: Put the timezone string in plain text in 12 | # /etc/timezone and then re-run the tzdata configuration to pick it up. 13 | 14 | TIMEZONE_FILE = '/etc/timezone' 15 | 16 | template TIMEZONE_FILE do 17 | source "timezone.conf.erb" 18 | owner 'root' 19 | group 'root' 20 | mode 0644 21 | notifies :run, 'execute[dpkg-reconfigure-tzdata]' 22 | end 23 | 24 | execute 'dpkg-reconfigure-tzdata' do 25 | command '/usr/sbin/dpkg-reconfigure -f noninteractive tzdata' 26 | action :nothing 27 | end 28 | 29 | # Certain values get normalized by dpkg-reconfigure, causing this recipe to try 30 | # to rewrite the file over and over. This raises a red flag in such a case. 31 | log 'if-unexpected-timezone-change' do 32 | message "dpkg-reconfigure is amending the value #{node['tz'].inspect} "\ 33 | "in #{TIMEZONE_FILE}" 34 | level :warn 35 | not_if { ::File.read(TIMEZONE_FILE).chomp == node['tz'] } 36 | action :nothing 37 | subscribes :write, 'execute[dpkg-reconfigure-tzdata]', :immediately 38 | end 39 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: timezone-ii 3 | # Recipe:: default 4 | # 5 | # Copyright 2010, James Harton 6 | # Copyright 2013, Lawrence Leonard Gilbert 7 | # 8 | # Apache 2.0 License. 9 | # 10 | 11 | # Make sure the tzdata database is installed. (Arthur David Olson, the computer 12 | # timekeeping field is forever in your debt.) 13 | package value_for_platform_family( 14 | 'gentoo' => 'timezone-data', 15 | 'default' => 'tzdata' 16 | ) 17 | 18 | case node.platform_family 19 | when 'rhel' 20 | include_recipe value_for_platform( 21 | 'amazon' => { 'default' => 'timezone-ii::amazon' }, 22 | 'default' => 'timezone-ii::rhel' 23 | ) 24 | 25 | when 'debian', 'fedora', 'pld' 26 | include_recipe "timezone-ii::#{node.platform_family}" 27 | 28 | else 29 | if node.os == "linux" 30 | # Load the generic Linux recipe if there's no better known way to change the 31 | # timezone. Log a warning (unless this is known to be the best way on a 32 | # particular platform). 33 | message = "Linux platform '#{node.platform}' is unknown to this recipe; " + 34 | "using generic Linux method" 35 | log message do 36 | level :warn 37 | not_if { %w( centos gentoo rhel ).include? node.platform_family } 38 | end 39 | 40 | include_recipe 'timezone-ii::linux-generic' 41 | 42 | else 43 | message = "Don't know how to configure timezone for " + 44 | "'#{node.platform_family}'!" 45 | log message do 46 | level :error 47 | end 48 | 49 | end # if/else node.os 50 | 51 | end # case node.platform_family 52 | -------------------------------------------------------------------------------- /recipes/fedora.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: timezone-ii 3 | # Recipe:: fedora 4 | # 5 | # Copyright 2013, 2015 Lawrence Leonard Gilbert 6 | # 7 | # Apache 2.0 License. 8 | # 9 | 10 | # Fedora and EL 7 currently use the same timedatectl utility 11 | include_recipe 'timezone-ii::rhel7' 12 | -------------------------------------------------------------------------------- /recipes/linux-generic.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: timezone-ii 3 | # Recipe:: linux-generic 4 | # 5 | # Copyright 2013, Lawrence Leonard Gilbert 6 | # 7 | # Apache 2.0 License. 8 | # 9 | 10 | # Generic timezone-changing method for Linux that should work for any distro 11 | # without a platform-specific method. 12 | 13 | timezone_data_file = File.join(node.timezone.tzdata_dir, node.tz) 14 | localtime_path = node.timezone.localtime_path 15 | 16 | ruby_block "confirm timezone" do 17 | block { 18 | unless File.exist?(timezone_data_file) 19 | raise "Can't find #{timezone_data_file}!" 20 | end 21 | } 22 | end 23 | 24 | if node.timezone.use_symlink 25 | link localtime_path do 26 | to timezone_data_file 27 | owner 'root' 28 | group 'root' 29 | mode 0644 30 | end 31 | 32 | else 33 | file localtime_path do 34 | content File.open(timezone_data_file, 'rb').read 35 | owner 'root' 36 | group 'root' 37 | mode 0644 38 | not_if { 39 | File.symlink?(localtime_path) and 40 | Chef::Log.error "You must remove symbolic link at #{localtime_path}" + 41 | " or set attribute ['timezone']['use_symlink']=true" 42 | } 43 | end 44 | end # if/else node.timezone.use_symlink 45 | -------------------------------------------------------------------------------- /recipes/pld.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: timezone-ii 3 | # Recipe:: pld 4 | # 5 | # Copyright 2010, James Harton 6 | # Copyright 2013, Lawrence Leonard Gilbert 7 | # Copyright 2013, Elan Ruusamäe 8 | # 9 | # Apache 2.0 License. 10 | # 11 | 12 | # Set timezone for PLD family: Put the timezone string in plain text in 13 | # /etc/sysconfig/timezone and then re-run the timezone service to pick it up. 14 | 15 | template "/etc/sysconfig/timezone" do 16 | source "timezone.conf.erb" 17 | owner 'root' 18 | group 'root' 19 | mode 0644 20 | notifies :reload, 'service[timezone]' 21 | end 22 | 23 | service 'timezone' do 24 | action :nothing 25 | end 26 | -------------------------------------------------------------------------------- /recipes/rhel.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: timezone-ii 3 | # Recipe:: rhel 4 | # 5 | # Copyright 2013, fraD00r4 6 | # Copyright 2015, Lawrence Leonard Gilbert 7 | # 8 | # Apache 2.0 License. 9 | # 10 | 11 | # This recipe sets the timezone on EL 6 and older (RedHat Enterprise Linux, 12 | # CentOS, etc.) 13 | # 14 | # If it is being run on EL 7 or newer, the recipe will be skipped and 15 | # the "rhel7" recipe will be included instead. 16 | 17 | el_version = node[:platform_version].split('.')[0].to_i 18 | 19 | if el_version >= 7 20 | include_recipe 'timezone-ii::rhel7' 21 | 22 | else 23 | template '/etc/sysconfig/clock' do 24 | source 'clock.erb' 25 | owner 'root' 26 | group 'root' 27 | mode 0644 28 | notifies :run, 'execute[tzdata-update]' 29 | end 30 | 31 | execute 'tzdata-update' do 32 | command '/usr/sbin/tzdata-update' 33 | action :nothing 34 | # Amazon Linux doesn't have this command! 35 | only_if { ::File.executable?('/usr/sbin/tzdata-update') } 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /recipes/rhel7.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Cookbook Name:: timezone-ii 3 | # Recipe:: rhel7 4 | # 5 | # Copyright 2015 Lawrence Leonard Gilbert 6 | # 7 | # Apache 2.0 License. 8 | # 9 | 10 | # This sets the timezone on EL 7 distributions (e.g. RedHat and CentOS) 11 | execute "timedatectl --no-ask-password set-timezone #{node[:tz]}" 12 | -------------------------------------------------------------------------------- /spec/attributes_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'timezone-ii default attributes' do 4 | context 'on Debian' do 5 | let(:chef_run) do 6 | ChefSpec::SoloRunner.new(platform: 'debian', version: '7.4').converge('timezone-ii') 7 | end 8 | 9 | specify { expect(chef_run.node[:tz]) .to eq 'Etc/UTC' } 10 | specify { expect(chef_run.node[:timezone][:tzdata_dir]) .to eq '/usr/share/zoneinfo' } 11 | specify { expect(chef_run.node[:timezone][:localtime_path]).to eq '/etc/localtime' } 12 | specify { expect(chef_run.node[:timezone][:use_symlink]) .to be_falsey } 13 | end 14 | 15 | context 'on non-Debian' do 16 | let(:chef_run) do 17 | ChefSpec::SoloRunner.new.converge('timezone-ii') 18 | end 19 | 20 | specify { expect(chef_run.node[:tz]) .to eq 'UTC' } 21 | specify { expect(chef_run.node[:timezone][:tzdata_dir]) .to eq '/usr/share/zoneinfo' } 22 | specify { expect(chef_run.node[:timezone][:localtime_path]).to eq '/etc/localtime' } 23 | specify { expect(chef_run.node[:timezone][:use_symlink]) .to be_falsey } 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /spec/recipes/amazon_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'timezone-ii::amazon' do 4 | let(:chef_run) do 5 | allow(::File).to receive(:symlink?).with('/etc/localtime').and_return(false) 6 | ChefSpec::SoloRunner.new.converge(described_recipe) 7 | end 8 | 9 | specify { expect(chef_run).to include_recipe('timezone-ii::linux-generic') } 10 | specify { expect(chef_run).to include_recipe('timezone-ii::rhel') } 11 | end 12 | -------------------------------------------------------------------------------- /spec/recipes/debian_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'timezone-ii::debian' do 4 | let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) } 5 | 6 | specify { expect(chef_run).to create_template('/etc/timezone') } 7 | 8 | context 'template[/etc/timezone]' do 9 | let(:template) { chef_run.template('/etc/timezone') } 10 | 11 | it 'should notify the update script when it is created' do 12 | expect(template).to notify('execute[dpkg-reconfigure-tzdata]').to(:run).delayed 13 | end 14 | end 15 | 16 | context 'execute[dpkg-reconfigure-tzdata]' do 17 | let(:execute) { chef_run.execute('dpkg-reconfigure-tzdata') } 18 | 19 | it 'should do nothing by default' do 20 | expect(execute).to do_nothing 21 | end 22 | end 23 | 24 | context 'log[if-unexpected-timezone-change]' do 25 | it 'is in need of tests' 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /spec/recipes/default_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'timezone-ii::default' do 4 | shared_examples 'an unsupported OS' do |platform_family, platform_version| 5 | let(:chef_run) do 6 | allow(::File).to receive(:symlink?).with('/etc/localtime') 7 | .and_return(false) 8 | ChefSpec::SoloRunner 9 | .new(platform: platform_family, version: platform_version) 10 | .converge(described_recipe) 11 | end 12 | 13 | specify do 14 | pending 15 | expect(chef_run).not_to install_package('tzdata') 16 | end 17 | 18 | specify do 19 | expect(chef_run).not_to include_recipe('timezone-ii::linux-generic') 20 | end 21 | 22 | specify do 23 | expect(chef_run) 24 | .to write_log("Don't know how to configure timezone for "\ 25 | "'#{platform_family}'!") 26 | .with(level: :error) 27 | end 28 | end 29 | 30 | context 'on Amazon Linux' do 31 | let(:chef_run) do 32 | allow(::File).to receive(:symlink?).with('/etc/localtime') 33 | .and_return(false) 34 | ChefSpec::SoloRunner.new(platform: 'amazon', version: '2014.03') 35 | .converge(described_recipe) 36 | end 37 | 38 | specify { expect(chef_run).to install_package('tzdata') } 39 | specify { expect(chef_run).to include_recipe('timezone-ii::amazon') } 40 | specify { expect(chef_run).to include_recipe('timezone-ii::linux-generic') } 41 | specify { expect(chef_run).to include_recipe('timezone-ii::rhel') } 42 | end 43 | 44 | context 'on CentOS 6.5' do 45 | let(:chef_run) do 46 | allow(::File).to receive(:symlink?).with('/etc/localtime') 47 | .and_return(false) 48 | ChefSpec::SoloRunner.new(platform: 'centos', version: '6.5') 49 | .converge(described_recipe) 50 | end 51 | 52 | specify { expect(chef_run).to install_package('tzdata') } 53 | specify { expect(chef_run).to include_recipe('timezone-ii::rhel') } 54 | specify do 55 | expect(chef_run).not_to include_recipe('timezone-ii::linux-generic') 56 | end 57 | end 58 | 59 | context 'on CentOS 7.0' do 60 | let(:chef_run) do 61 | ChefSpec::SoloRunner.new(platform: 'centos', version: '7.0') 62 | .converge(described_recipe) 63 | end 64 | 65 | specify { expect(chef_run).to install_package('tzdata') } 66 | specify { expect(chef_run).to include_recipe('timezone-ii::rhel7') } 67 | specify do 68 | expect(chef_run).not_to include_recipe('timezone-ii::linux-generic') 69 | end 70 | end 71 | 72 | context 'on Debian' do 73 | let(:chef_run) do 74 | allow(::File).to receive(:symlink?).with('/etc/localtime') 75 | .and_return(false) 76 | ChefSpec::SoloRunner.new(platform: 'debian', version: '7.0') 77 | .converge(described_recipe) 78 | end 79 | 80 | specify { expect(chef_run).to install_package('tzdata') } 81 | specify { expect(chef_run).to include_recipe('timezone-ii::debian') } 82 | specify do 83 | expect(chef_run).not_to include_recipe('timezone-ii::linux-generic') 84 | end 85 | end 86 | 87 | context 'on Fedora' do 88 | let(:chef_run) do 89 | allow(::File).to receive(:symlink?).with('/etc/localtime') 90 | .and_return(false) 91 | ChefSpec::SoloRunner.new(platform: 'fedora', version: '20') 92 | .converge(described_recipe) 93 | end 94 | 95 | specify { expect(chef_run).to install_package('tzdata') } 96 | specify { expect(chef_run).to include_recipe('timezone-ii::fedora') } 97 | end 98 | 99 | context 'on FreeBSD' do 100 | it_should_behave_like 'an unsupported OS', 'freebsd', '10.0' 101 | end 102 | 103 | context 'on Gentoo' do 104 | let(:chef_run) do 105 | allow(::File).to receive(:symlink?).with('/etc/localtime') 106 | .and_return(false) 107 | ChefSpec::SoloRunner.new(platform: 'gentoo', version: '2.1') 108 | .converge(described_recipe) 109 | end 110 | 111 | specify { expect(chef_run).to install_package('timezone-data') } 112 | specify do 113 | expect(chef_run).to include_recipe('timezone-ii::linux-generic') 114 | end 115 | specify do 116 | expect(chef_run).not_to write_log(anything) 117 | end 118 | end 119 | 120 | context 'on PLD' do 121 | pending 122 | end 123 | 124 | context 'on Mac OS' do 125 | it_should_behave_like 'an unsupported OS', 'mac_os_x', '10.9.2' 126 | end 127 | 128 | context 'on OmniOS' do 129 | it_should_behave_like 'an unsupported OS', 'omnios', '151008' 130 | end 131 | 132 | context 'on OpenBSD' do 133 | it_should_behave_like 'an unsupported OS', 'openbsd', '5.4' 134 | end 135 | 136 | context 'on OpenSUSE' do 137 | pending 138 | end 139 | 140 | context 'on Oracle Linux' do 141 | pending 142 | end 143 | 144 | context 'on RedHat' do 145 | pending 146 | end 147 | 148 | context 'on SmartOS' do 149 | it_should_behave_like 'an unsupported OS', 'smartos', '5.11' 150 | end 151 | 152 | context 'on Solaris2' do 153 | it_should_behave_like 'an unsupported OS', 'solaris2', '5.11' 154 | end 155 | 156 | context 'on SUSE' do 157 | pending 158 | end 159 | 160 | context 'on Ubuntu' do 161 | pending 162 | end 163 | 164 | context 'on Windows' do 165 | pending 166 | end 167 | end 168 | -------------------------------------------------------------------------------- /spec/recipes/fedora_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'timezone-ii::fedora' do 4 | let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) } 5 | 6 | specify { expect(chef_run).to include_recipe('timezone-ii::rhel7') } 7 | end 8 | -------------------------------------------------------------------------------- /spec/recipes/linux-generic_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'timezone-ii::linux-generic' do 4 | let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) } 5 | 6 | it 'should be tested ;-)' 7 | end 8 | -------------------------------------------------------------------------------- /spec/recipes/pld_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'timezone-ii::pld' do 4 | let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) } 5 | 6 | it 'should be tested ;-)' 7 | end 8 | -------------------------------------------------------------------------------- /spec/recipes/rhel7_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'timezone-ii::rhel7' do 4 | let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) } 5 | 6 | specify { expect(chef_run).not_to create_template('/etc/sysconfig/clock') } 7 | 8 | it 'runs the timedatectl utility to change the timezone' do 9 | expect(chef_run).to run_execute('timedatectl --no-ask-password set-timezone UTC') 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /spec/recipes/rhel_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'timezone-ii::rhel' do 4 | context 'on unspecified platforms' do 5 | let(:chef_run) { ChefSpec::SoloRunner.new.converge(described_recipe) } 6 | 7 | specify { expect(chef_run).to create_template('/etc/sysconfig/clock') } 8 | 9 | context 'template[/etc/sysconfig/clock]' do 10 | let(:template) { chef_run.template('/etc/sysconfig/clock') } 11 | 12 | it 'should notify the update script when it is created' do 13 | expect(template).to notify('execute[tzdata-update]').to(:run).delayed 14 | end 15 | end 16 | 17 | specify do 18 | expect(chef_run.execute('tzdata-update')).to do_nothing 19 | end 20 | 21 | it 'should NOT run the tzdata-update command', 22 | pending: 'need to find a way to verify behavior of "run" notification' 23 | end 24 | 25 | context 'on Centos 6.5' do 26 | let(:chef_run) do 27 | ChefSpec::SoloRunner.new(platform: 'centos', version: '6.5') 28 | .converge(described_recipe) 29 | end 30 | 31 | specify { expect(chef_run).to create_template('/etc/sysconfig/clock') } 32 | specify { expect(chef_run).not_to include_recipe('timezone-ii::rhel7') } 33 | 34 | context 'template[/etc/sysconfig/clock]' do 35 | let(:template) { chef_run.template('/etc/sysconfig/clock') } 36 | 37 | it 'should notify the update script when it is created' do 38 | expect(template).to notify('execute[tzdata-update]').to(:run).delayed 39 | end 40 | end 41 | 42 | it 'should run the tzdata-update command', 43 | pending: 'need to find a way to verify behavior of "run" notification' 44 | end 45 | 46 | context 'on Centos 7.0' do 47 | let(:chef_run) do 48 | ChefSpec::SoloRunner.new(platform: 'centos', version: '7.0') 49 | .converge(described_recipe) 50 | end 51 | 52 | specify { expect(chef_run).not_to create_template('/etc/sysconfig/clock') } 53 | specify { expect(chef_run).to include_recipe('timezone-ii::rhel7') } 54 | end 55 | 56 | context 'on Amazon Linux' do 57 | it 'needs tests...' 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'chefspec' 2 | require 'chefspec/berkshelf' 3 | 4 | ChefSpec::Coverage.start! 5 | -------------------------------------------------------------------------------- /templates/amazon/clock.erb: -------------------------------------------------------------------------------- 1 | ZONE="<%= node[:tz] %>" 2 | -------------------------------------------------------------------------------- /templates/centos/clock.erb: -------------------------------------------------------------------------------- 1 | ZONE="<%= node[:tz] %>" 2 | -------------------------------------------------------------------------------- /templates/default/timezone.conf.erb: -------------------------------------------------------------------------------- 1 | <%= node[:tz] %> 2 | -------------------------------------------------------------------------------- /templates/pld/timezone.conf.erb: -------------------------------------------------------------------------------- 1 | # Time zone information. 2 | 3 | # Directory containing zone information files. 4 | ZONE_INFO_DIR="<%= node['timezone']['tzdata_dir'] %>" 5 | 6 | # Scheme you would like to use in your system. 7 | ZONE_INFO_SCHEME="posix" 8 | 9 | # Name of the time zone for your system. 10 | TIMEZONE="<%= node[:tz] %>" 11 | -------------------------------------------------------------------------------- /templates/redhat/clock.erb: -------------------------------------------------------------------------------- 1 | ZONE="<%= node[:tz] %>" 2 | -------------------------------------------------------------------------------- /test/integration/default/bats/date_output.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | @test "Date output in correct time zone" { 4 | date | grep -q " TOT " 5 | } 6 | -------------------------------------------------------------------------------- /test/integration/default/bats/debian.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helper 4 | 5 | @test "/etc/timezone content correct" { 6 | if [ "debian" != "$ohai_platform_family" ]; then 7 | skip "test only applicable to debian family, not $ohai_platform_family family" 8 | fi 9 | 10 | grep -q -x Pacific/Tongatapu /etc/timezone 11 | } 12 | -------------------------------------------------------------------------------- /test/integration/default/bats/etc_localtime.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | load helper 4 | 5 | symlink_ok_on_this_platform () { 6 | [ "centos" == "$ohai_platform" ] || \ 7 | [ "fedora" == "$ohai_platform" ] 8 | } 9 | 10 | @test "/etc/localtime content correct" { 11 | diff -q /etc/localtime /usr/share/zoneinfo/Pacific/Tongatapu 12 | } 13 | 14 | @test "/etc/localtime not a symlink (default linux-generic behavior)" { 15 | if symlink_ok_on_this_platform; then 16 | skip "Not applicable to $ohai_platform" 17 | fi 18 | 19 | [ '!' -L /etc/localtime ] 20 | } 21 | -------------------------------------------------------------------------------- /test/integration/helpers/bats/helper.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | $(ohai | /opt/chef/embedded/bin/ruby -rjson -e 'ohai_data = JSON.load($stdin.read); ohai_data.each {|key, value| next unless /^platform/.match(key); puts "export ohai_#{key}=#{value}"}') 3 | --------------------------------------------------------------------------------