├── .chef ├── .node_name ├── dna.json ├── first-boot.json ├── solo.rb └── zero.rb ├── .codeclimate.yml ├── .gitignore ├── .kitchen-docker.yml ├── .kitchen.yml ├── .rubocop.yml ├── .travis.yml ├── Berksfile ├── Berksfile.lock ├── CHANGELOG.md ├── Dockerfile ├── Dockerfile.mutable ├── Gemfile ├── Gemfile.lock ├── Guardfile ├── Guardfile.integration ├── LICENSE ├── Makefile ├── README.md ├── Rakefile ├── Strainerfile ├── TESTING.md ├── Thorfile ├── Vagrantfile ├── attributes ├── default.rb └── profile.rb ├── chefignore ├── libraries ├── host_info.rb ├── matchers.rb └── url_package.rb ├── metadata.rb ├── providers ├── environment.rb ├── hostname.rb ├── packages.rb ├── profile.rb └── timezone.rb ├── recipes ├── default.rb ├── environment.rb ├── hostname.rb ├── install_packages.rb ├── profile.rb ├── reboot.rb ├── shutdown.rb ├── test_fqdn_set.rb ├── timezone.rb ├── uninstall_packages.rb ├── update_package_list.rb └── upgrade_packages.rb ├── resources ├── environment.rb ├── hostname.rb ├── packages.rb ├── profile.rb └── timezone.rb ├── templates ├── arch │ ├── environment.erb │ └── profile.erb ├── centos │ ├── environment.erb │ └── profile.erb ├── debian │ ├── environment.erb │ └── profile.erb ├── default │ ├── environment.erb │ ├── profile.erb │ └── test_fqdn_set.erb ├── fedora │ ├── environment.erb │ └── profile.erb ├── freebsd │ └── profile.erb ├── redhat │ ├── environment.erb │ └── profile.erb └── ubuntu │ ├── environment.erb │ └── profile.erb └── test ├── integration └── default │ └── serverspec │ ├── default_spec.rb │ └── spec_helper.rb └── unit └── spec ├── default_spec.rb └── spec_helper.rb /.chef/.node_name: -------------------------------------------------------------------------------- 1 | chef-system-build 2 | -------------------------------------------------------------------------------- /.chef/dna.json: -------------------------------------------------------------------------------- 1 | { 2 | "run_list": [ 3 | "recipe[system::default]" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.chef/first-boot.json: -------------------------------------------------------------------------------- 1 | { 2 | "run_list": [ 3 | "recipe[system::default]" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.chef/solo.rb: -------------------------------------------------------------------------------- 1 | require 'chef-init' 2 | 3 | node_name ChefInit.node_name 4 | cookbook_path ['/var/chef/cookbooks'] 5 | ssl_verify_mode :verify_peer 6 | -------------------------------------------------------------------------------- /.chef/zero.rb: -------------------------------------------------------------------------------- 1 | require 'chef-init' 2 | 3 | node_name ChefInit.node_name 4 | cookbook_path ['/var/chef/cookbooks'] 5 | ssl_verify_mode :verify_peer 6 | -------------------------------------------------------------------------------- /.codeclimate.yml: -------------------------------------------------------------------------------- 1 | languages: 2 | Ruby: true 3 | # exclude_paths: 4 | # - "foo/bar.rb" 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | *~ 3 | *# 4 | .#* 5 | \#*# 6 | .*.sw[a-z] 7 | *.un~ 8 | /cookbooks 9 | /vendor/ 10 | 11 | # Bundler 12 | bin/* 13 | .bundle/* 14 | 15 | .kitchen/ 16 | .kitchen.local.yml 17 | 18 | metadata.json 19 | -------------------------------------------------------------------------------- /.kitchen-docker.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: docker 4 | 5 | # before running test kitchen: 6 | # export KITCHEN_YAML=.kitchen-docker.yml 7 | 8 | driver_config: 9 | require_chef_omnibus: latest 10 | # require_chef_omnibus: 12.5.1 11 | # require_chef_omnibus: 11.18.14 12 | 13 | provisioner: 14 | name: chef_zero 15 | 16 | platforms: 17 | # not supported :( 18 | # https://github.com/chef/omnitruck/issues/77 19 | # - name: archlinux 20 | # driver: 21 | # box: 'terrywang/archlinux' 22 | # attributes: 23 | # system: 24 | # primary_interface: enp0s8 25 | - name: debian-8.1 26 | attributes: 27 | system: 28 | primary_interface: eth1 29 | - name: debian-7.8 30 | attributes: 31 | system: 32 | primary_interface: eth1 33 | - name: ubuntu-14.04 34 | attributes: 35 | system: 36 | primary_interface: eth1 37 | - name: ubuntu-12.04 38 | attributes: 39 | system: 40 | primary_interface: eth1 41 | - name: ubuntu-15.04 42 | attributes: 43 | system: 44 | primary_interface: eth1 45 | - name: centos-7.1 46 | attributes: 47 | system: 48 | primary_interface: enp0s8 49 | - name: centos-6.6 50 | attributes: 51 | system: 52 | primary_interface: eth1 53 | - name: fedora-21 54 | attributes: 55 | system: 56 | primary_interface: enp0s8 57 | - name: fedora-20 58 | attributes: 59 | system: 60 | primary_interface: enp0s8 61 | suites: 62 | - name: default 63 | run_list: 64 | - recipe[system::timezone] 65 | - recipe[system::install_packages] 66 | - recipe[system::uninstall_packages] 67 | - recipe[system::profile] 68 | - recipe[system::environment] 69 | driver: 70 | network: 71 | - ["private_network", {ip: "172.16.172.16"}] 72 | attributes: 73 | system: 74 | short_hostname: test 75 | domain_name: kitchen 76 | environment: 77 | extra: 78 | DINNER: Pizza 79 | DESERT: Ice cream 80 | timezone: Australia/Sydney 81 | static_hosts: 82 | 95.211.29.66: supermarket.io 83 | 184.106.28.82: chef.io 84 | packages: 85 | install: 86 | - "curl" 87 | - "wget" 88 | install_compile_time: 89 | - "sudo" 90 | uninstall: 91 | - "gcc" 92 | profile: 93 | append_scripts: 94 | - "export CHEF_IS_AWESOME=1" 95 | - "echo helloworld > /dev/null" 96 | path_prepend: 97 | - "/opt/local/food/bin" 98 | path_append: 99 | - "/opt/local/bin" 100 | -------------------------------------------------------------------------------- /.kitchen.yml: -------------------------------------------------------------------------------- 1 | --- 2 | driver: 3 | name: vagrant 4 | 5 | provisioner: 6 | name: chef_zero 7 | 8 | platforms: 9 | # not supported :( 10 | # https://github.com/chef/omnitruck/issues/77 11 | # - name: archlinux 12 | # driver: 13 | # box: 'terrywang/archlinux' 14 | # attributes: 15 | # system: 16 | # primary_interface: enp0s8 17 | - name: debian-8.6 18 | attributes: 19 | system: 20 | primary_interface: eth1 21 | - name: debian-7.11 22 | attributes: 23 | system: 24 | primary_interface: eth1 25 | - name: ubuntu-14.04 26 | attributes: 27 | system: 28 | primary_interface: eth1 29 | - name: ubuntu-12.04 30 | attributes: 31 | system: 32 | primary_interface: eth1 33 | - name: ubuntu-16.04 34 | attributes: 35 | system: 36 | primary_interface: eth0 37 | - name: centos-7.2 38 | attributes: 39 | system: 40 | primary_interface: enp0s8 41 | - name: centos-6.8 42 | attributes: 43 | system: 44 | primary_interface: eth1 45 | - name: fedora-24 46 | attributes: 47 | system: 48 | primary_interface: enp0s8 49 | - name: fedora-23 50 | attributes: 51 | system: 52 | primary_interface: enp0s8 53 | - name: freebsd-10.3 54 | attributes: 55 | system: 56 | primary_interface: em1 57 | driver_config: 58 | ssh: 59 | shell: '/bin/sh' 60 | network: 61 | - ["private_network", {ip: "172.16.172.16"}] 62 | - name: freebsd-9.3 63 | attributes: 64 | system: 65 | primary_interface: em1 66 | driver_config: 67 | ssh: 68 | shell: '/bin/sh' 69 | network: 70 | - ["private_network", {ip: "172.16.172.16"}] 71 | suites: 72 | - name: default 73 | run_list: 74 | - recipe[system::default] 75 | - recipe[system::timezone] 76 | - recipe[system::install_packages] 77 | - recipe[system::uninstall_packages] 78 | - recipe[system::profile] 79 | - recipe[system::environment] 80 | driver: 81 | network: 82 | - ["private_network", {ip: "172.16.172.16"}] 83 | attributes: 84 | system: 85 | hostsfile_behaviour: create 86 | short_hostname: test 87 | domain_name: kitchen 88 | environment: 89 | extra: 90 | DINNER: Pizza 91 | DESERT: Ice cream 92 | timezone: Australia/Sydney 93 | static_hosts: 94 | 95.211.29.66: supermarket.io 95 | 184.106.28.82: chef.io 96 | packages: 97 | install: 98 | - "curl" 99 | - "wget" 100 | install_compile_time: 101 | - "sudo" 102 | uninstall: 103 | - "gcc" 104 | profile: 105 | append_scripts: 106 | - "export CHEF_IS_AWESOME=1" 107 | - "echo helloworld > /dev/null" 108 | path_prepend: 109 | - "/opt/local/food/bin" 110 | path_append: 111 | - "/opt/local/bin" 112 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | # Common configuration. 2 | AllCops: 3 | # Include common Ruby source files. 4 | Include: 5 | - '**/*.builder' 6 | - '**/*.fcgi' 7 | - '**/*.gemspec' 8 | - '**/*.god' 9 | - '**/*.jb' 10 | - '**/*.jbuilder' 11 | - '**/*.mspec' 12 | - '**/*.opal' 13 | - '**/*.pluginspec' 14 | - '**/*.podspec' 15 | - '**/*.rabl' 16 | - '**/*.rake' 17 | - '**/*.rbuild' 18 | - '**/*.rbw' 19 | - '**/*.rbx' 20 | - '**/*.ru' 21 | - '**/*.ruby' 22 | - '**/*.spec' 23 | - '**/*.thor' 24 | - '**/*.watchr' 25 | - '**/.irbrc' 26 | - '**/.pryrc' 27 | - '**/buildfile' 28 | - '**/config.ru' 29 | - '**/Appraisals' 30 | - '**/Berksfile' 31 | - '**/Brewfile' 32 | - '**/Buildfile' 33 | - '**/Capfile' 34 | - '**/Cheffile' 35 | - '**/Dangerfile' 36 | - '**/Deliverfile' 37 | - '**/Fastfile' 38 | - '**/*Fastfile' 39 | - '**/Gemfile' 40 | - '**/Guardfile' 41 | - '**/Jarfile' 42 | - '**/Mavenfile' 43 | - '**/Podfile' 44 | - '**/Puppetfile' 45 | - '**/Rakefile' 46 | - '**/Snapfile' 47 | - '**/Thorfile' 48 | - '**/Vagabondfile' 49 | - '**/Vagrantfile' 50 | Exclude: 51 | - 'vendor/**/*' 52 | 53 | BlockLength: 54 | Max: 300 55 | 56 | Encoding: 57 | Enabled: false 58 | 59 | LineLength: 60 | Max: 200 61 | 62 | IfUnlessModifier: 63 | Enabled: false 64 | 65 | MethodLength: 66 | Max: 15 67 | 68 | TrivialAccessors: 69 | ExactNameMatch: true 70 | 71 | SpaceBeforeFirstArg: 72 | Enabled: false 73 | 74 | NumericLiteralPrefix: 75 | EnforcedOctalStyle: zero_only 76 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | 2 | # Use Travis's cointainer based infrastructure 3 | sudo: false 4 | addons: 5 | apt: 6 | sources: 7 | - chef-current-precise 8 | packages: 9 | - chefdk 10 | 11 | # Don't `bundle install` 12 | install: echo "skip bundle install" 13 | 14 | branches: 15 | only: 16 | - master 17 | 18 | # Ensure we make ChefDK's Ruby the default 19 | before_script: 20 | - eval "$(/opt/chefdk/bin/chef shell-init bash)" 21 | 22 | script: 23 | - /opt/chefdk/embedded/bin/chef --version 24 | - /opt/chefdk/embedded/bin/cookstyle --version && /opt/chefdk/embedded/bin/cookstyle . 25 | - /opt/chefdk/embedded/bin/foodcritic --version && /opt/chefdk/embedded/bin/foodcritic -t ~FC072 -t ~FC074 . 26 | -------------------------------------------------------------------------------- /Berksfile: -------------------------------------------------------------------------------- 1 | source 'https://supermarket.chef.io' 2 | 3 | metadata 4 | -------------------------------------------------------------------------------- /Berksfile.lock: -------------------------------------------------------------------------------- 1 | DEPENDENCIES 2 | system 3 | path: . 4 | metadata: true 5 | 6 | GRAPH 7 | apt (6.1.4) 8 | cron (5.0.1) 9 | hostsfile (3.0.1) 10 | system (0.12.0) 11 | apt (>= 0.0.0) 12 | cron (>= 0.0.0) 13 | hostsfile (>= 0.0.0) 14 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | system CHANGELOG 2 | ================ 3 | 4 | This file is used to list changes made in each version of the system cookbook. 5 | 6 | 0.0.1 7 | ----- 8 | - Initial pre-release version 9 | 10 | 0.1.0 11 | ----- 12 | - Initial 'pre 1' minor release 13 | 14 | 0.2.2 15 | ----- 16 | - Includes bug fixes, revised code and more testing files 17 | 18 | 0.2.3 19 | ----- 20 | - Fix missing quote for rs_tag command in hostname provider 21 | 22 | 0.3.2 23 | ----- 24 | - Fix missing equals sign for service_action variable 25 | - Fix notifies for service[hostname] for Debian 26 | - Set 127.0.1.1 on Debian if needed 27 | - Fix for OHAI-389 28 | - Set supports status false for hostname service 29 | - Use service_name for hostname resource name 30 | - Minor log text improvements for show host info 31 | - Notify the hostname service immediately. 32 | - Address FC037: Invalid notification action 33 | - Add chefignore 34 | - Add TESTING.md 35 | 36 | 0.3.3 37 | ----- 38 | - Revision only to address https://github.com/xhost-cookbooks/system/issues/6 39 | 40 | 0.3.4 41 | ----- 42 | - Revision only to address https://github.com/xhost-cookbooks/system/issues/8 43 | 44 | 0.4.0 45 | ----- 46 | - Better platform support for default cron service 47 | - timezone provider ensures inclusion of cron recipe 48 | - Other minor fixes for cron 49 | - Improve test suite, add basic tests 50 | - Add a recipe to test setting of the fqdn 51 | - New attribute, permanent_ip to affect usage of 127.0.1.1 on debian 52 | - Fix setting hosts in /etc/hosts by using lazy loading of fqdn 53 | - Set fqdn in compile phase, to be sure 54 | 55 | 0.4.1 56 | ----- 57 | - Revision only to address https://github.com/xhost-cookbooks/system/issues/10 58 | 59 | 0.5.0 60 | ----- 61 | - Add a hostsfile entry for 127.0.0.1 against localhost.localdomain when not using permanent_ip 62 | - Include the FQDN in the hostfile entry for for 127.0.0.1 when not on Debian 63 | - Add resource for the network service in RHEL platform family (restart it on hostname change) 64 | - Use Chef::Util::FileEdit instead of sed to update /etc/sysconfig/network 65 | - permanent_ip is now true by default 66 | - Add support for hostnamectl (mostly for EL 7) 67 | - Fix missing trailing line return for /etc/hostname 68 | - Test Debian and CentOS with test-kitchen 69 | 70 | 0.6.0 71 | ----- 72 | - Mac OS X support (including NetBIOS and Workgroup names)! 73 | - Pull request #11 (default timezone is now 'Etc/UTC') 74 | - Fail when an invalid timezone is provided 75 | - Support providing a zone with a space instead of underscore (for the humans) 76 | - Make before and after tz-info log resources debug log level 77 | - update_package_list recipe will now sync MacPorts tree 78 | - upgrade_packages recipe will now upgrade installed ports for MacPorts 79 | - Improved test suite including use of chef_zero with test-kitchen, more platforms/versions 80 | - Add a good handful of Serverspec tests 81 | 82 | 0.6.1 83 | ----- 84 | - Ensure the crond service is available for restarting in timezone provider 85 | - Add mac_os_x to supports in metadata 86 | 87 | 0.6.2 88 | ----- 89 | - Fix cron daemon usage for arch linux (uses cronie which is not yet supported in the cron cookbook yet) 90 | - Fix cron_service_name for arch linux (cronie) in default attributes 91 | - Fix supports for arch linux in metadata.rb 92 | 93 | 0.6.3 94 | ----- 95 | - Use regex with readlines grep when checking for hostname in /etc/sysconfig/network on EL-based distros (fix for issue #14) 96 | - Help bad images/systems that have a null hostname (fix for issue #15) 97 | 98 | 0.6.4 99 | ----- 100 | - Fix for issue #17 removing unique hostfile entry for 127.0.0.1 101 | - Fix render of static_hosts via node attributes 102 | - Add hostfile entries for ipv6 hosts 103 | - Let the cron cookbook manage the cron resources entirely 104 | - Various test elements added/improved 105 | 106 | 0.7.0 107 | ----- 108 | - New system_packages LWRP 109 | - Support for installing remote packages by URL using the system_packages LWRP 110 | - timezone provider now defaults to Etc/UTC timezone 111 | 112 | 0.8.0 113 | ----- 114 | - Initial FreeBSD support 115 | - Manage /etc/profile by recipe or system_profile LWRP 116 | - system::hostname recipe parameterizes available provider attributes 117 | - Support for using the name_attribute of the hostname resource for fqdn 118 | - Fix for issue #22 (timezone set idempotency) 119 | - Various minor fixes 120 | 121 | 0.9.0 122 | ----- 123 | - Manage /etc/environment by recipe or system_environment LWRP 124 | - Support optional management of /etc/hosts (e.g. do not add hostname to this file) 125 | - Support optional inclusion of the cron recipe 126 | - Use ohai to determine network IP (pr #26) 127 | - Allow specification primary network interface for hostsfile generation (pr #26) 128 | - Improve/fix templating for system profile (/etc/profile) 129 | 130 | 0.9.1 131 | ----- 132 | - Fix missing end statement in templates/arch/profile.erb 133 | 134 | 0.10.0 135 | ------ 136 | - Make it possible to control which phase package upgrades occur (issue #28) 137 | - More lazy string from bool support for attributes in RightScale 138 | - Support for Ubuntu 15.04 (issue #30 and #31) 139 | - Chef 13 forward compliance (Do not specify both default and name_property together on property filename of resource) 140 | - Better docker support and with test-kitchen (.kitchen-docker.yml) 141 | - Add a Dockerfile 142 | - timedatectl for supported systems (issue #32) 143 | - Support path_append and path_prepend (issue #27) 144 | 145 | 0.10.1 146 | ------ 147 | - Fix missing underscore in ip_address attribute for 127.0.1.1 hostsfile entry 148 | - Fix logic on if the cron service should be notified or used within timezone provider resources 149 | 150 | 0.11.0 151 | ------ 152 | - Fix cookbook templates attempting to use incorrect cookbook templates (pr #40) 153 | - Raspbian platform support (pr #41) 154 | - Add ChefSpec matchers (pr #42) 155 | - Refresh TESTING.md (issue #39) 156 | - /etc/hostname should be short hostname and mode 0644 (issue #37) 157 | - Do not include any comment lines in /etc/hostname out of safeness 158 | - Remove temporary archlinux code for cron (timezone provider) 159 | - Only set hostsfile entry if private IP is set (issue #35) 160 | - Network restart control feature (pr #36) 161 | - Make attribute de-reference safe for failing attributes when undefined (pr #34) 162 | - Test Kitchen path fix for docker (issue #33) 163 | - Various test related improvements, bumps, fixes 164 | 165 | 0.11.1 166 | ------ 167 | 168 | Fix release to address issue #47 where hostname does not persist after reboot. 169 | 170 | - always set HOSTNAME in /etc/sysconfig/network if the config file exists 171 | - do not run domainname if the domainname is already as desired 172 | - configure preserve_hostname with cloud-init if cloud-init is installed 173 | - update hostname with nmcli if installed 174 | - restart systemd-hostnamed if enabled 175 | 176 | 0.11.2 177 | ------ 178 | 179 | Fix release to address issue #49 where an only_if attribute causes a fatal error 180 | 181 | - check for that systemctl command exists first with type command 182 | - fix expectation of hostname command returning FQDN in serverspec 183 | - ubuntu 16.04 now tested with test-kitchen 184 | 185 | 0.11.3 186 | ------ 187 | 188 | - Add support for Debian > 8 (systemd) in hostname recipe 189 | 190 | 0.12.0 191 | ------ 192 | 193 | - Use dnf for fedora instead of yum (pr #58) 194 | - Provide an empty hash for the static_hosts attribute instead of nil (issue #53) 195 | - Bump dep cookbook versions in Berks lock (issue #55) 196 | - Numerous cookbook and ruby style/syntax improvements and fixes 197 | - Use cookstyle instead of rubocop 198 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM chef/ubuntu-14.04:latest 2 | 3 | # berks package && docker build -t chef-system . 4 | 5 | COPY .chef/ /etc/chef/ 6 | 7 | ADD ./cookbooks-*.tar.gz /var/chef/ 8 | 9 | RUN chef-init --bootstrap 10 | RUN rm -rf /etc/chef/secure/* 11 | 12 | ENTRYPOINT ["chef-init"] 13 | 14 | CMD ["--onboot"] 15 | -------------------------------------------------------------------------------- /Dockerfile.mutable: -------------------------------------------------------------------------------- 1 | FROM chef/ubuntu-14.04:latest 2 | 3 | # berks package && docker build -t chef-system-mutable -f Dockerfile.mutable . 4 | 5 | COPY .chef/ /etc/chef/ 6 | 7 | ADD ./cookbooks-*.tar.gz /var/chef/ 8 | 9 | RUN chef-init --bootstrap 10 | RUN rm -rf /etc/chef/secure/* 11 | 12 | CMD ["chef-solo", "-j", "/etc/chef/dna.json"] 13 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # -*- mode: ruby -*- 4 | # vi: set ft=ruby : 5 | 6 | # let's be bleeding and not specify andy versions until v1.0.0 7 | 8 | source 'https://rubygems.org' 9 | 10 | chef_version = ENV.key?('CHEF_VERSION') ? ENV['CHEF_VERSION'] : nil 11 | 12 | gem 'activesupport' 13 | gem 'buff-extensions' 14 | 15 | group :development do 16 | gem 'berkshelf' 17 | gem 'chef', chef_version unless chef_version.nil? # Ruby 1.9.3 support 18 | gem 'rake' 19 | gem 'rb-fsevent' 20 | end 21 | 22 | group :test do 23 | gem 'chefspec' 24 | gem 'codeclimate-test-reporter', group: :test, require: nil 25 | gem 'rspec' 26 | end 27 | 28 | group :lint do 29 | gem 'cookstyle' 30 | gem 'foodcritic' 31 | end 32 | 33 | group :kitchen_common do 34 | gem 'test-kitchen' 35 | end 36 | 37 | group :kitchen_docker do 38 | gem 'kitchen-docker' 39 | end 40 | 41 | group :kitchen_vagrant do 42 | gem 'kitchen-vagrant' 43 | end 44 | 45 | group :kitchen_cloud do 46 | gem 'kitchen-digitalocean' 47 | gem 'kitchen-ec2' 48 | end 49 | 50 | group :guard do 51 | gem 'guard' 52 | # use below for gems like guard-foodcritic which 53 | # don't yet support guard 3 :( 54 | # gem 'guard', '= 2.8.2' 55 | gem 'guard-foodcritic' 56 | gem 'guard-kitchen' 57 | gem 'guard-rspec' 58 | gem 'guard-rubocop' 59 | # to support down to ruby 2.1 60 | gem 'listen', '= 3.0.7' 61 | end 62 | 63 | group :integration do 64 | gem 'vagrant-wrapper' 65 | end 66 | 67 | group :integration, :integration_cloud do 68 | gem 'serverspec' 69 | end 70 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | activesupport (5.1.4) 5 | concurrent-ruby (~> 1.0, >= 1.0.2) 6 | i18n (~> 0.7) 7 | minitest (~> 5.1) 8 | tzinfo (~> 1.1) 9 | addressable (2.5.2) 10 | public_suffix (>= 2.0.2, < 4.0) 11 | ast (2.3.0) 12 | aws-sdk (2.10.85) 13 | aws-sdk-resources (= 2.10.85) 14 | aws-sdk-core (2.10.85) 15 | aws-sigv4 (~> 1.0) 16 | jmespath (~> 1.0) 17 | aws-sdk-resources (2.10.85) 18 | aws-sdk-core (= 2.10.85) 19 | aws-sigv4 (1.0.2) 20 | axiom-types (0.1.1) 21 | descendants_tracker (~> 0.0.4) 22 | ice_nine (~> 0.11.0) 23 | thread_safe (~> 0.3, >= 0.3.1) 24 | backports (3.10.3) 25 | berkshelf (6.3.1) 26 | buff-config (~> 2.0) 27 | buff-extensions (~> 2.0) 28 | chef (>= 12.7.2) 29 | cleanroom (~> 1.0) 30 | concurrent-ruby (~> 1.0) 31 | faraday (~> 0.9) 32 | httpclient (~> 2.7) 33 | minitar (~> 0.5, >= 0.5.4) 34 | mixlib-archive (~> 0.4) 35 | mixlib-shellout (~> 2.0) 36 | octokit (~> 4.0) 37 | retryable (~> 2.0) 38 | ridley (~> 5.0) 39 | solve (~> 4.0) 40 | thor (~> 0.19, < 0.19.2) 41 | buff-config (2.0.0) 42 | buff-extensions (~> 2.0) 43 | varia_model (~> 0.6) 44 | buff-extensions (2.0.0) 45 | buff-ignore (1.2.0) 46 | buff-ruby_engine (1.0.0) 47 | buff-shell_out (1.1.0) 48 | buff-ruby_engine (~> 1.0) 49 | builder (3.2.3) 50 | celluloid (0.16.0) 51 | timers (~> 4.0.0) 52 | celluloid-io (0.16.2) 53 | celluloid (>= 0.16.0) 54 | nio4r (>= 1.1.0) 55 | chef (13.6.4) 56 | addressable 57 | bundler (>= 1.10) 58 | chef-config (= 13.6.4) 59 | chef-zero (>= 13.0) 60 | diff-lcs (~> 1.2, >= 1.2.4) 61 | erubis (~> 2.7) 62 | ffi-yajl (~> 2.2) 63 | highline (~> 1.6, >= 1.6.9) 64 | iniparse (~> 1.4) 65 | iso8601 (~> 0.9.1) 66 | mixlib-archive (~> 0.4) 67 | mixlib-authentication (~> 1.4) 68 | mixlib-cli (~> 1.7) 69 | mixlib-log (~> 1.3) 70 | mixlib-shellout (~> 2.0) 71 | net-sftp (~> 2.1, >= 2.1.2) 72 | net-ssh (>= 2.9, < 5.0) 73 | net-ssh-multi (~> 1.2, >= 1.2.1) 74 | ohai (~> 13.0) 75 | plist (~> 3.2) 76 | proxifier (~> 1.0) 77 | rspec-core (~> 3.5) 78 | rspec-expectations (~> 3.5) 79 | rspec-mocks (~> 3.5) 80 | rspec_junit_formatter (~> 0.2.0) 81 | serverspec (~> 2.7) 82 | specinfra (~> 2.10) 83 | syslog-logger (~> 1.6) 84 | uuidtools (~> 2.1.5) 85 | chef-config (13.6.4) 86 | addressable 87 | fuzzyurl 88 | mixlib-config (~> 2.0) 89 | mixlib-shellout (~> 2.0) 90 | chef-zero (13.1.0) 91 | ffi-yajl (~> 2.2) 92 | hashie (>= 2.0, < 4.0) 93 | mixlib-log (~> 1.3) 94 | rack (~> 2.0) 95 | uuidtools (~> 2.1) 96 | chefspec (7.1.0) 97 | chef (>= 12.14.89) 98 | fauxhai (>= 4, < 6) 99 | rspec (~> 3.0) 100 | cleanroom (1.0.0) 101 | codeclimate-test-reporter (1.0.8) 102 | simplecov (<= 0.13) 103 | coderay (1.1.2) 104 | coercible (1.0.0) 105 | descendants_tracker (~> 0.0.1) 106 | concurrent-ruby (1.0.5) 107 | cookstyle (2.1.0) 108 | rubocop (= 0.49.1) 109 | cucumber-core (3.0.0) 110 | backports (>= 3.8.0) 111 | cucumber-tag_expressions (>= 1.0.1) 112 | gherkin (>= 4.1.3) 113 | cucumber-tag_expressions (1.0.1) 114 | descendants_tracker (0.0.4) 115 | thread_safe (~> 0.3, >= 0.3.1) 116 | diff-lcs (1.3) 117 | docile (1.1.5) 118 | droplet_kit (2.2.1) 119 | activesupport (> 3.0, < 6) 120 | faraday (~> 0.9) 121 | kartograph (~> 0.2.3) 122 | resource_kit (~> 0.1.5) 123 | virtus (~> 1.0.3) 124 | equalizer (0.0.11) 125 | erubis (2.7.0) 126 | excon (0.59.0) 127 | faraday (0.13.1) 128 | multipart-post (>= 1.2, < 3) 129 | fauxhai (5.5.0) 130 | net-ssh 131 | ffi (1.9.18) 132 | ffi-yajl (2.3.1) 133 | libyajl2 (~> 1.2) 134 | foodcritic (12.2.1) 135 | cucumber-core (>= 1.3) 136 | erubis 137 | ffi-yajl (~> 2.0) 138 | nokogiri (>= 1.5, < 2.0) 139 | rake 140 | rufus-lru (~> 1.0) 141 | treetop (~> 1.4) 142 | formatador (0.2.5) 143 | fuzzyurl (0.9.0) 144 | gherkin (5.0.0) 145 | gssapi (1.2.0) 146 | ffi (>= 1.0.1) 147 | guard (2.14.1) 148 | formatador (>= 0.2.4) 149 | listen (>= 2.7, < 4.0) 150 | lumberjack (~> 1.0) 151 | nenv (~> 0.1) 152 | notiffany (~> 0.0) 153 | pry (>= 0.9.12) 154 | shellany (~> 0.0) 155 | thor (>= 0.18.1) 156 | guard-compat (1.2.1) 157 | guard-foodcritic (3.0.0) 158 | foodcritic (>= 8) 159 | guard (~> 2.12) 160 | guard-compat (~> 1.2) 161 | guard-kitchen (0.0.2) 162 | guard 163 | mixlib-shellout 164 | guard-rspec (4.7.3) 165 | guard (~> 2.1) 166 | guard-compat (~> 1.1) 167 | rspec (>= 2.99.0, < 4.0) 168 | guard-rubocop (1.3.0) 169 | guard (~> 2.0) 170 | rubocop (~> 0.20) 171 | gyoku (1.3.1) 172 | builder (>= 2.1.2) 173 | hashie (3.5.6) 174 | highline (1.7.8) 175 | hitimes (1.2.6) 176 | httpclient (2.8.3) 177 | i18n (0.9.1) 178 | concurrent-ruby (~> 1.0) 179 | ice_nine (0.11.2) 180 | iniparse (1.4.4) 181 | ipaddress (0.8.3) 182 | iso8601 (0.9.1) 183 | jmespath (1.3.1) 184 | json (2.1.0) 185 | kartograph (0.2.4) 186 | kitchen-digitalocean (0.9.8) 187 | droplet_kit (~> 2.2) 188 | test-kitchen (~> 1.17) 189 | kitchen-docker (2.6.0) 190 | test-kitchen (>= 1.0.0) 191 | kitchen-ec2 (1.3.2) 192 | aws-sdk (~> 2) 193 | excon 194 | multi_json 195 | retryable (~> 2.0) 196 | test-kitchen (~> 1.4, >= 1.4.1) 197 | kitchen-vagrant (1.2.1) 198 | test-kitchen (~> 1.4) 199 | libyajl2 (1.2.0) 200 | listen (3.0.7) 201 | rb-fsevent (>= 0.9.3) 202 | rb-inotify (>= 0.9.7) 203 | little-plugger (1.1.4) 204 | logging (2.2.2) 205 | little-plugger (~> 1.1) 206 | multi_json (~> 1.10) 207 | lumberjack (1.0.12) 208 | method_source (0.9.0) 209 | mini_portile2 (2.3.0) 210 | minitar (0.6.1) 211 | minitest (5.10.3) 212 | mixlib-archive (0.4.1) 213 | mixlib-log 214 | mixlib-authentication (1.4.2) 215 | mixlib-cli (1.7.0) 216 | mixlib-config (2.2.4) 217 | mixlib-install (3.8.0) 218 | mixlib-shellout 219 | mixlib-versioning 220 | thor 221 | mixlib-log (1.7.1) 222 | mixlib-shellout (2.3.2) 223 | mixlib-versioning (1.2.2) 224 | molinillo (0.6.4) 225 | multi_json (1.12.2) 226 | multipart-post (2.0.0) 227 | nenv (0.3.0) 228 | net-scp (1.2.1) 229 | net-ssh (>= 2.6.5) 230 | net-sftp (2.1.2) 231 | net-ssh (>= 2.6.5) 232 | net-ssh (4.2.0) 233 | net-ssh-gateway (1.3.0) 234 | net-ssh (>= 2.6.5) 235 | net-ssh-multi (1.2.1) 236 | net-ssh (>= 2.6.5) 237 | net-ssh-gateway (>= 1.2.0) 238 | net-telnet (0.1.1) 239 | nio4r (2.1.0) 240 | nokogiri (1.8.1) 241 | mini_portile2 (~> 2.3.0) 242 | nori (2.6.0) 243 | notiffany (0.1.1) 244 | nenv (~> 0.1) 245 | shellany (~> 0.0) 246 | octokit (4.7.0) 247 | sawyer (~> 0.8.0, >= 0.5.3) 248 | ohai (13.6.0) 249 | chef-config (>= 12.5.0.alpha.1, < 14) 250 | ffi (~> 1.9) 251 | ffi-yajl (~> 2.2) 252 | ipaddress 253 | mixlib-cli 254 | mixlib-config (~> 2.0) 255 | mixlib-log (>= 1.7.1, < 2.0) 256 | mixlib-shellout (~> 2.0) 257 | plist (~> 3.1) 258 | systemu (~> 2.6.4) 259 | wmi-lite (~> 1.0) 260 | parallel (1.12.0) 261 | parser (2.4.0.2) 262 | ast (~> 2.3) 263 | plist (3.3.0) 264 | polyglot (0.3.5) 265 | powerpack (0.1.1) 266 | proxifier (1.0.3) 267 | pry (0.11.3) 268 | coderay (~> 1.1.0) 269 | method_source (~> 0.9.0) 270 | public_suffix (3.0.1) 271 | rack (2.0.3) 272 | rainbow (2.2.2) 273 | rake 274 | rake (12.3.0) 275 | rb-fsevent (0.10.2) 276 | rb-inotify (0.9.10) 277 | ffi (>= 0.5.0, < 2) 278 | resource_kit (0.1.7) 279 | addressable (>= 2.3.6, < 3.0.0) 280 | retryable (2.0.4) 281 | ridley (5.1.1) 282 | addressable 283 | buff-config (~> 2.0) 284 | buff-extensions (~> 2.0) 285 | buff-ignore (~> 1.2) 286 | buff-shell_out (~> 1.0) 287 | celluloid (~> 0.16.0) 288 | celluloid-io (~> 0.16.1) 289 | chef-config (>= 12.5.0) 290 | erubis 291 | faraday (~> 0.9) 292 | hashie (>= 2.0.2, < 4.0.0) 293 | httpclient (~> 2.7) 294 | json (>= 1.7.7) 295 | mixlib-authentication (>= 1.3.0) 296 | retryable (~> 2.0) 297 | semverse (~> 2.0) 298 | varia_model (~> 0.6) 299 | rspec (3.7.0) 300 | rspec-core (~> 3.7.0) 301 | rspec-expectations (~> 3.7.0) 302 | rspec-mocks (~> 3.7.0) 303 | rspec-core (3.7.0) 304 | rspec-support (~> 3.7.0) 305 | rspec-expectations (3.7.0) 306 | diff-lcs (>= 1.2.0, < 2.0) 307 | rspec-support (~> 3.7.0) 308 | rspec-its (1.2.0) 309 | rspec-core (>= 3.0.0) 310 | rspec-expectations (>= 3.0.0) 311 | rspec-mocks (3.7.0) 312 | diff-lcs (>= 1.2.0, < 2.0) 313 | rspec-support (~> 3.7.0) 314 | rspec-support (3.7.0) 315 | rspec_junit_formatter (0.2.3) 316 | builder (< 4) 317 | rspec-core (>= 2, < 4, != 2.12.0) 318 | rubocop (0.49.1) 319 | parallel (~> 1.10) 320 | parser (>= 2.3.3.1, < 3.0) 321 | powerpack (~> 0.1) 322 | rainbow (>= 1.99.1, < 3.0) 323 | ruby-progressbar (~> 1.7) 324 | unicode-display_width (~> 1.0, >= 1.0.1) 325 | ruby-progressbar (1.9.0) 326 | rubyntlm (0.6.2) 327 | rubyzip (1.2.1) 328 | rufus-lru (1.1.0) 329 | safe_yaml (1.0.4) 330 | sawyer (0.8.1) 331 | addressable (>= 2.3.5, < 2.6) 332 | faraday (~> 0.8, < 1.0) 333 | semverse (2.0.0) 334 | serverspec (2.41.3) 335 | multi_json 336 | rspec (~> 3.0) 337 | rspec-its 338 | specinfra (~> 2.72) 339 | sfl (2.3) 340 | shellany (0.0.1) 341 | simplecov (0.13.0) 342 | docile (~> 1.1.0) 343 | json (>= 1.8, < 3) 344 | simplecov-html (~> 0.10.0) 345 | simplecov-html (0.10.2) 346 | solve (4.0.0) 347 | molinillo (~> 0.6) 348 | semverse (>= 1.1, < 3.0) 349 | specinfra (2.72.1) 350 | net-scp 351 | net-ssh (>= 2.7, < 5.0) 352 | net-telnet 353 | sfl 354 | syslog-logger (1.6.8) 355 | systemu (2.6.5) 356 | test-kitchen (1.19.0) 357 | mixlib-install (~> 3.6) 358 | mixlib-shellout (>= 1.2, < 3.0) 359 | net-scp (~> 1.1) 360 | net-ssh (>= 2.9, < 5.0) 361 | net-ssh-gateway (~> 1.2) 362 | safe_yaml (~> 1.0) 363 | thor (~> 0.19, < 0.19.2) 364 | winrm (~> 2.0) 365 | winrm-elevated (~> 1.0) 366 | winrm-fs (~> 1.0.2) 367 | thor (0.19.1) 368 | thread_safe (0.3.6) 369 | timers (4.0.4) 370 | hitimes 371 | treetop (1.6.8) 372 | polyglot (~> 0.3) 373 | tzinfo (1.2.4) 374 | thread_safe (~> 0.1) 375 | unicode-display_width (1.3.0) 376 | uuidtools (2.1.5) 377 | vagrant-wrapper (2.0.3) 378 | varia_model (0.6.0) 379 | buff-extensions (~> 2.0) 380 | hashie (>= 2.0.2, < 4.0.0) 381 | virtus (1.0.5) 382 | axiom-types (~> 0.1) 383 | coercible (~> 1.0) 384 | descendants_tracker (~> 0.0, >= 0.0.3) 385 | equalizer (~> 0.0, >= 0.0.9) 386 | winrm (2.2.3) 387 | builder (>= 2.1.2) 388 | erubis (~> 2.7) 389 | gssapi (~> 1.2) 390 | gyoku (~> 1.0) 391 | httpclient (~> 2.2, >= 2.2.0.2) 392 | logging (>= 1.6.1, < 3.0) 393 | nori (~> 2.0) 394 | rubyntlm (~> 0.6.0, >= 0.6.1) 395 | winrm-elevated (1.1.0) 396 | winrm (~> 2.0) 397 | winrm-fs (~> 1.0) 398 | winrm-fs (1.0.2) 399 | erubis (~> 2.7) 400 | logging (>= 1.6.1, < 3.0) 401 | rubyzip (~> 1.1) 402 | winrm (~> 2.0) 403 | wmi-lite (1.0.0) 404 | 405 | PLATFORMS 406 | ruby 407 | 408 | DEPENDENCIES 409 | activesupport 410 | berkshelf 411 | buff-extensions 412 | chefspec 413 | codeclimate-test-reporter 414 | cookstyle 415 | foodcritic 416 | guard 417 | guard-foodcritic 418 | guard-kitchen 419 | guard-rspec 420 | guard-rubocop 421 | kitchen-digitalocean 422 | kitchen-docker 423 | kitchen-ec2 424 | kitchen-vagrant 425 | listen (= 3.0.7) 426 | rake 427 | rb-fsevent 428 | rspec 429 | serverspec 430 | test-kitchen 431 | vagrant-wrapper 432 | 433 | BUNDLED WITH 434 | 1.13.7 435 | -------------------------------------------------------------------------------- /Guardfile: -------------------------------------------------------------------------------- 1 | # More info at https://github.com/guard/guard#readme 2 | 3 | # waiting for guard-foodcritic updates 4 | # https://github.com/cgriego/guard-foodcritic/issues/7 5 | group :style do 6 | guard 'foodcritic', cookbook_paths: '.', all_on_start: false do 7 | watch(%r{attributes\/.+\.rb$}) 8 | watch(%r{providers\/.+\.rb$}) 9 | watch(%r{recipes\/.+\.rb$}) 10 | watch(%r{resources\/.+\.rb$}) 11 | watch('metadata.rb') 12 | end 13 | end 14 | 15 | group :lint do 16 | guard 'rubocop' do 17 | watch(%r{attributes\/.+\.rb$}) 18 | watch(%r{providers\/.+\.rb$}) 19 | watch(%r{recipes\/.+\.rb$}) 20 | watch(%r{resources\/.+\.rb$}) 21 | watch(%r{test\/.+\.rb$}) 22 | watch('metadata.rb') 23 | watch('Rakefile') 24 | end 25 | end 26 | 27 | scope groups: %i(lint style) 28 | -------------------------------------------------------------------------------- /Guardfile.integration: -------------------------------------------------------------------------------- 1 | # More info at https://github.com/guard/guard#readme 2 | 3 | group :integration do 4 | guard 'kitchen' do 5 | watch(%r{test/.+}) 6 | watch(%r{^recipes/(.+)\.rb$}) 7 | watch(%r{^attributes/(.+)\.rb$}) 8 | watch(%r{^files/(.+)}) 9 | watch(%r{^templates/(.+)}) 10 | watch(%r{^providers/(.+)\.rb}) 11 | watch(%r{^resources/(.+)\.rb}) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /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 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: docker-build docker-tag docker-push 2 | 3 | release:: docker-build docker-tag docker-push 4 | 5 | docker-push:: 6 | @docker push flaccid/chef-system 7 | 8 | docker-tag:: 9 | @docker tag -f chef-system flaccid/chef-system 10 | 11 | docker-build:: 12 | @berks package && docker build -t chef-system . 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | system Cookbook 2 | =============== 3 | 4 | [![Cookbook Version](https://img.shields.io/badge/cookbook-v0.12.0-blue.svg)](https://supermarket.chef.io/cookbooks/system) 5 | [![Dependency Status](https://gemnasium.com/xhost-cookbooks/system.svg)](https://gemnasium.com/xhost-cookbooks/system) 6 | [![Code Climate](https://codeclimate.com/github/xhost-cookbooks/system.png)](https://codeclimate.com/github/xhost-cookbooks/system) 7 | [![License](https://img.shields.io/badge/license-Apache_2-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) 8 | [![Join the chat at https://gitter.im/xhost-cookbooks/system](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/xhost-cookbooks/system?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) 9 | 10 | Build Status 11 | ------------ 12 | 13 | | | Travis CI | 14 | |-----------|-----------------| 15 | | **Master** |[![Build status](https://secure.travis-ci.org/xhost-cookbooks/system.png?branch=master)](http://travis-ci.org/xhost-cookbooks/system)| 16 | | **Latest Release** ([**0.12.0**](https://github.com/xhost-cookbooks/system/releases/tag/v0.12.0)) |[![Build status](https://secure.travis-ci.org/xhost-cookbooks/system.png?branch=v0.12.0)](https://travis-ci.org/xhost-cookbooks/system/builds/303425827)| 17 | 18 | Overview 19 | -------- 20 | 21 | This cookbook is designed to provide a set of recipes and LWRPs for managing the core properties of a host's system. 22 | 23 | Currently the main features (from a high level) include: 24 | - setting the hostname/domain name 25 | - setting the default NetBIOS name and Workgroup (OS X only) 26 | - setting the timezone 27 | - configuring the system-wide profile (`/etc/profile`) 28 | - managing packages (install, uninstall & upgrade) 29 | 30 | Ad-hoc style operational tasks such as reboot and shutdown are also implemented by recipes. 31 | 32 | Get it now from your (local) [supermarket](https://supermarket.chef.io/cookbooks/system)! 33 | 34 | 35 | Requirements 36 | ------------ 37 | - Chef >= 12.x 38 | - Ruby >= 2.2.x 39 | 40 | Older versions may work, but are not supported. See [Platforms and Supported Versions](https://docs.chef.io/platforms.html#versions). 41 | 42 | ### Platforms Supported 43 | - Debian, Ubuntu 44 | - CentOS, RHEL, Fedora 45 | - Arch Linux 46 | - FreeBSD 47 | - Mac OS X 48 | 49 | ### Cookbooks 50 | - apt 51 | - cron 52 | - hostsfile 53 | 54 | 55 | Attributes 56 | ---------- 57 | 58 | See `attributes/default.rb` for default values. 59 | 60 | - `node['system']['timezone']` - the system timezone to set, default `Etc/UTC` 61 | - `node['system']['short_hostname']` - the short hostname to set on the node, default is `node['hostname']` 62 | - `node['system']['domain_name']` - the domain name to set on the node, default `localdomain` 63 | - `node['system']['netbios_name']` - the NetBIOS name to set on the node, default is `node['system']['short_hostname']` upper-cased (OS X only) 64 | - `node['system']['workgroup']` - the NetBIOS workgroup name to set on the node, default is `WORKGROUP` (OS X only) 65 | - `node['system']['static_hosts']` - a hash of static hosts to add to `/etc/hosts` 66 | - `node['system']['upgrade_packages']` - whether to upgrade the system's packages, default `true` 67 | - `node['system']['upgrade_packages_at_compile']` - whether upgrade of the system's packages in Chef's compilation phase, default `true` 68 | - `node['system']['enable_cron']` - whether to include the cron recipe, default `true` 69 | - `node['system']['packages']['install']` - an array of packages to install (also supports remote package URLs) 70 | - `node['system']['packages']['install_compile_time']` - an array of packages to install in Chef's compilation phase (also supports remote package URLs) 71 | - `node['system']['manage_hostsfile']` - whether or not to manage `/etc/hostsfile` (in any way) 72 | - `node['system']['permanent_ip']` - whether the system has a permenent IP address (http://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_hostname_resolution) 73 | - `node['system']['primary_interface']` - Specify primary network interface, used by hostname to set the correct address in hostsfile, default is `node['network']['default_interface']` 74 | - `node['system']['delay_network_restart']` - whether to trigger restart event as delayed. false causes an immediate restart instead. default `true` 75 | 76 | Attributes (all arrays) to manipulate the system-wide profile (usually for `/etc/profile`): 77 | 78 | - `node['system']['profile']['path']` - override the default `PATH` for the system 79 | - `node['system']['profile']['path_append']` - append more paths to the base path 80 | - `node['system']['profile']['path_prepend']` - prepend more paths to the base path 81 | - `node['system']['profile']['append_scripts']` - an array of shell scripts to be appended to the system profile (include raw scripts without shebangs) 82 | 83 | 84 | Usage 85 | ----- 86 | 87 | ### Recipes 88 | 89 | ##### `system::default` 90 | Includes the `system::update_package_list`, `system::timezone` and `system::hostname` recipes only. 91 | 92 | NOTE: if applicable, the system's package manager's package list will be updated, but installed packages won't be upgraded. To upgrade the system's packages, include the `system::upgrade_packages` recipe in your run_list or role. 93 | 94 | ##### `system::hostname` 95 | When using resources that reference `node['fqdn']` in variables or attribute values, note that you will 96 | need to lazy load to get the new hostname that is being set. 97 | 98 | Use with variables: 99 | ``` 100 | template '/tmp/foobar.txt' do 101 | source 'use_fqdn_in_variable.erb' 102 | variables lazy { 103 | { 104 | fqdn: node['fqdn'], 105 | foo: bar 106 | } 107 | } 108 | end 109 | ``` 110 | 111 | Use with a resource attribute: 112 | ``` 113 | log 'lazy_log_fqdn' do 114 | message lazy { node['fqdn'] } 115 | level :debug 116 | end 117 | ``` 118 | 119 | ##### `system::profile` 120 | Manages `/etc/profile` with optional shell scripts to append from `node['system']['profile']['append_scripts']`, 121 | configure `PATH` requirements per attributes documented above. 122 | 123 | ##### `system::install_packages` 124 | Installs a list of system packages as specified in the `node['system']['packages']['install']` attribute. 125 | Will also install packages provided at compile time from within `node['system']['packages']['install_compile_time']`. 126 | 127 | ##### `system::uninstall_packages` 128 | Uninstalls a list of system packages as specified in the `node['system']['packages']['uninstall']` attribute. 129 | Will also uninstall packages provided at compile time from within `node['system']['packages']['uninstall_compile_time']`. 130 | 131 | ##### `system::reboot` 132 | Attempts to gracefully reboot the operating system. 133 | 134 | ##### `system::shutdown` 135 | Attempts to gracefully shutdown the operating system. 136 | 137 | ##### `system::timezone` 138 | Sets the timezone of the system. 139 | 140 | ##### `system::update_package_list` 141 | Updates the local package manager's package list. 142 | 143 | ##### `system::upgrade_packages` 144 | Upgrades all installed packages of the local package manager. 145 | 146 | ### LWRPs 147 | 148 | The cookbook currently provides 3 Lightweight Resource Providers that can be used in your own recipes 149 | by depending on this cookbook. Recipes are provided interfacing each of these for convenience but 150 | you may find them useful in your own cookbook usage. 151 | 152 | #### `system_hostname` 153 | 154 | | Attribute | Description | Example | Default | 155 | |--------------------|-----------------------------------------------|--------------------|-----------| 156 | | short_hostname | The short hostname for the system | `starbug` | nil | 157 | | domain_name | The domain name for the system | `reddwarf.space` | nil | 158 | | static_hosts | An array of static hosts to add to /etc/hosts | `[{ '95.211.29.66' => 'supermarket.io' }, { '184.106.28.82' => 'chef.io' }]` | nil | 159 | 160 | ##### Examples 161 | 162 | Set the hostname providing the desired FQDN: 163 | ``` 164 | system_hostname 'starbug.reddwarf.space' 165 | ``` 166 | 167 | Providing the short hostname as the resource name and explicitly defining the domain name 168 | (alas this is a bit verbose), as well as some static hosts: 169 | ``` 170 | system_hostname 'starbug' do 171 | short_hostname 'starbug' 172 | domain_name 'reddwarf.space' 173 | static_hosts(({ '95.211.29.66' => 'supermarket.io', 174 | '184.106.28.82' => 'chef.io' })) 175 | end 176 | ``` 177 | The `system::hostname` recipe implements it this way as `short_hostname` and `domain_name` 178 | are the exposed cookbook attributes. 179 | 180 | #### `system_timezone` 181 | 182 | | Attribute | Description | Example | Default | 183 | |--------------------|-----------------------------------------------|----------------------|-----------| 184 | | timezone | The timezone to set the system to | `Australia/Sydney` | `Etc/UTC` | 185 | 186 | ##### Example 187 | 188 | ``` 189 | system_timezone 'Australia/Sydney' 190 | ``` 191 | 192 | #### `system_packages` 193 | 194 | | Attribute | Description | Example | Default | 195 | |--------------------|-----------------------------------------------|-------------------|-------------| 196 | | packages | The timezone to set the system to | `%w(wget curl)` | `[]` | 197 | | phase | The Chef phase to download the packages in | `:compile ` | `:converge` | 198 | 199 | ##### Example 200 | 201 | ``` 202 | system_packages %w(wget curl).join(',') do 203 | packages %w(wget curl) 204 | phase :compile 205 | end 206 | ``` 207 | 208 | #### `system_profile` 209 | 210 | | Attribute | Description | Example | Default | 211 | |--------------------|-------------------------------------------------------|------------------------|-----------------| 212 | | filename | The system profile file to manage | `/etc/profile` | `/etc/profile` | 213 | | template | The cookbook erb template for the profile file | `custom_profile.erb` | `profile.erb` | 214 | | path | An environment search path to prepend to the default | `/opt/local/bin` | `[]` | 215 | | append_scripts | Arbitrary scripts to append to the profile | `['export FOO=bar']` | `nil` | 216 | 217 | ##### Example 218 | 219 | ``` 220 | system_profile '/etc/profile' do 221 | path ['/opt/local/bin', '/opt/foo/bin'] 222 | append_scripts ['export FOO=bar'] 223 | end 224 | ``` 225 | 226 | ### Publish to Chef Supermarket 227 | 228 | $ cd .. 229 | $ knife cookbook site share system "Operating Systems & Virtualization" -o . -u xhost -k ~/.chef/xhost.pem 230 | 231 | 232 | License and Authors 233 | ------------------- 234 | - Author: Chris Fordham () 235 | 236 | ```text 237 | Copyright 2011-2016, Chris Fordham 238 | 239 | Licensed under the Apache License, Version 2.0 (the "License"); 240 | you may not use this file except in compliance with the License. 241 | You may obtain a copy of the License at 242 | 243 | http://www.apache.org/licenses/LICENSE-2.0 244 | 245 | Unless required by applicable law or agreed to in writing, software 246 | distributed under the License is distributed on an "AS IS" BASIS, 247 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 248 | See the License for the specific language governing permissions and 249 | limitations under the License. 250 | ``` 251 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | namespace :prepare do 4 | desc 'Install ChefDK' 5 | task :chefdk do 6 | begin 7 | gem 'chef-dk', '0.2.1' 8 | rescue Gem::LoadError 9 | puts 'ChefDK not found. Installing it for you...' 10 | sh %(wget -O /tmp/meez_chefdk.deb https://opscode-omnibus-packages.s3.amazonaws.com/ubuntu/12.04/x86_64/chefdk_0.2.1-1_amd64.deb) 11 | sh %(sudo dpkg -i /tmp/meez_chefdk.deb) 12 | end 13 | end 14 | 15 | task :bundle do 16 | if ENV['CI'] 17 | sh %(chef exec bundle install --path=.bundle --jobs 1 --retry 3 --verbose) 18 | else 19 | sh %(chef exec bundle install --path .bundle) 20 | end 21 | end 22 | 23 | task :berks do 24 | sh %(chef exec berks install) 25 | end 26 | end 27 | 28 | desc 'Install required Gems and Cookbooks' 29 | task prepare: ['prepare:bundle', 'prepare:berks'] 30 | 31 | namespace :style do 32 | task :cookstyle do 33 | sh %(chef exec cookstyle .) 34 | end 35 | 36 | task :foodcritic do 37 | # FC072: we don't agree with metadata attribute deprecation 38 | # - its useful for integration consumers 39 | # FC074: chef regressed or failed to support arch linux in cron cookbook 40 | sh %(chef exec foodcritic -t ~FC072 -t ~FC074 .) 41 | end 42 | end 43 | 44 | desc 'Run all style checks' 45 | task style: ['style:foodcritic', 'style:cookstyle'] 46 | 47 | namespace :integration do 48 | task :kitchen do 49 | sh %(chef exec kitchen test) 50 | end 51 | end 52 | 53 | task integration: ['integration:kitchen'] 54 | 55 | namespace :unit do 56 | task :chefspec do 57 | sh %(chef exec rspec test/unit/spec) 58 | end 59 | end 60 | 61 | namespace :travis do 62 | desc 'Run tests on Travis CI' 63 | task :ci do 64 | sh %(chef exec cookstyle .) 65 | sh %(chef exec foodcritic .) 66 | end 67 | end 68 | 69 | desc 'Run all unit tests' 70 | task unit: ['unit:chefspec'] 71 | task spec: ['unit'] 72 | 73 | # Run all tests 74 | desc 'Run all tests' 75 | task test: %w(style unit integration) 76 | 77 | # The default rake task should just run it all 78 | desc 'Install required Gems and Cookbook then run all tests' 79 | task default: %w(prepare test) 80 | 81 | begin 82 | require 'kitchen/rake_tasks' 83 | Kitchen::RakeTasks.new 84 | rescue LoadError 85 | puts '>>>>> Kitchen gem not loaded, omitting tasks' unless ENV['CI'] 86 | end 87 | -------------------------------------------------------------------------------- /Strainerfile: -------------------------------------------------------------------------------- 1 | # Strainerfile 2 | # This file is deprecated, but kept for completeness-sake. 3 | 4 | knife test: bundle exec knife cookbook test $COOKBOOK 5 | rubocop: bundle exec rubocop $COOKBOOK 6 | foodcritic: bundle exec foodcritic -f any $SANDBOX/$COOKBOOK 7 | chefspec: bundle exec rspec $SANDBOX/$COOKBOOK/test/unit/spec 8 | kitchen: bundle exec kitchen test --destroy=always 9 | -------------------------------------------------------------------------------- /TESTING.md: -------------------------------------------------------------------------------- 1 | Testing 2 | ======= 3 | 4 | Preparation 5 | ----------- 6 | 7 | Install Chef DK by following https://docs.chef.io/install_dk.html. 8 | 9 | Ensure both bin dirs from chefdk take precedence in your `$PATH`: 10 | 11 | $ export PATH="/opt/chefdk/bin:/opt/chefdk/embedded/bin:$PATH" 12 | 13 | List the rake tasks available: 14 | 15 | $ rake -T 16 | 17 | Install the gem dependencies and cookbooks: 18 | 19 | $ rake prepare 20 | 21 | All 22 | --- 23 | 24 | Run all tests, write a symphony while you wait: 25 | 26 | $ rake test 27 | 28 | Style 29 | ----- 30 | 31 | Rubocop and Foodcritic: 32 | 33 | $ rake style 34 | 35 | Unit 36 | ---- 37 | 38 | Currently ChefSpec only: 39 | 40 | $ rake unit 41 | 42 | Integration 43 | ----------- 44 | 45 | $ rake kitchen:all 46 | 47 | See `.kitchen.yml` and `test/` directory for details. 48 | 49 | Additional Information 50 | ---------------------- 51 | 52 | Rake is used as a wrapper, providing quick commands to do key tests. Feel free 53 | to use all the different methods provided by Chef DK and the development files 54 | included in the cookbook. 55 | 56 | These testing methods are also supported, although appear outdated at this time: 57 | 58 | https://github.com/chef-cookbooks/community_cookbook_documentation/blob/master/TESTING.MD 59 | -------------------------------------------------------------------------------- /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 | config.vm.hostname = 'system' 6 | config.vm.box = 'ubuntu-14.04' 7 | config.vm.box_url = "http://opscode-vm-bento.s3.amazonaws.com/vagrant/virtualbox/opscode_#{config.vm.box}_chef-provisionerless.box" 8 | config.omnibus.chef_version = 'latest' 9 | config.berkshelf.enabled = true 10 | 11 | config.vm.provision :chef_solo do |chef| 12 | chef.cookbooks_path = File.expand_path('~/.berkshelf/cookbooks') 13 | # chef.log_level = :debug 14 | chef.json = { 15 | 'system' => { 16 | 'short_hostname' => 'system', 17 | 'domain_name' => 'localdomain', 18 | 'timezone' => 'Australia/Sydney', 19 | }, 20 | } 21 | 22 | chef.run_list = [ 23 | 'recipe[system::default]', 24 | ] 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /attributes/default.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Attributes:: system 5 | # 6 | # Copyright 2012-2014, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | default['system']['timezone'] = 'Etc/UTC' 21 | 22 | # just in case the node/image fails to have a proper hostname 23 | default['system']['short_hostname'] = if node['hostname'] 24 | node['hostname'] 25 | else 26 | 'localhost' 27 | end 28 | 29 | default['system']['domain_name'] = 'localdomain' 30 | default['system']['netbios_name'] = node['system']['short_hostname'].upcase 31 | default['system']['workgroup'] = 'WORKGROUP' 32 | default['system']['static_hosts'] = {} 33 | default['system']['manage_hostsfile'] = true 34 | default['system']['hostsfile_behaviour'] = 'append' 35 | default['system']['upgrade_packages'] = true 36 | default['system']['upgrade_packages_at_compile'] = true 37 | default['system']['permanent_ip'] = true 38 | default['system']['primary_interface'] = node['network']['default_interface'] if node['network'] 39 | default['system']['delay_network_restart'] = true 40 | default['system']['enable_cron'] = true 41 | default['system']['packages']['install'] = [] 42 | default['system']['packages']['install_compile_time'] = [] 43 | 44 | default['system']['packages']['uninstall'] = [] 45 | default['system']['packages']['uninstall_compile_time'] = [] 46 | 47 | default['system']['environment']['extra'] = {} 48 | 49 | # RightScale doesn't support boolean attributes in metadata 50 | node.override['system']['manage_hostsfile'] = false if node['system']['manage_hostsfile'] == 'false' 51 | node.override['system']['manage_hostsfile'] = true if node['system']['manage_hostsfile'] == 'true' 52 | 53 | node.override['system']['upgrade_packages'] = false if node['system']['upgrade_packages'] == 'false' 54 | node.override['system']['upgrade_packages'] = true if node['system']['upgrade_packages'] == 'true' 55 | 56 | node.override['system']['permanent_ip'] = false if node['system']['permanent_ip'] == 'false' 57 | node.override['system']['permanent_ip'] = true if node['system']['permanent_ip'] == 'true' 58 | 59 | node.override['system']['enable_cron'] = false if node['system']['enable_cron'] == 'false' 60 | node.override['system']['enable_cron'] = true if node['system']['enable_cron'] == 'true' 61 | -------------------------------------------------------------------------------- /attributes/profile.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Attributes:: system/profile 5 | # 6 | # Copyright 2012-2014, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | case node['platform_family'] 21 | when 'arch' 22 | # /etc/profile from the `filesystem` package 23 | default['system']['profile']['path'] = ['/usr/local/sbin', 24 | '/usr/local/bin', 25 | '/usr/bin'] 26 | # /usr/share/base-files/profile postinst installs to 27 | # /etc/profile from the `base-files` package 28 | when 'debian', 'raspbian' 29 | default['system']['profile']['path'] = ['/usr/local/bin', 30 | '/usr/bin', 31 | '/bin', 32 | '/usr/local/games', 33 | '/usr/games'] 34 | when 'rhel' 35 | default['system']['profile']['path'] = ['/usr/local/sbin', 36 | '/usr/local/bin', 37 | '/usr/sbin', 38 | '/usr/bin', 39 | '/sbin', 40 | '/bin'] 41 | when 'fedora' 42 | default['system']['profile']['path'] = ['/usr/local/sbin', 43 | '/usr/local/bin', 44 | '/usr/sbin', 45 | '/usr/bin', 46 | '/sbin', 47 | '/bin'] 48 | # base PATH on freebsd is set in /etc/rc, 49 | # we'll use the same here 50 | when 'freebsd' 51 | default['system']['profile']['path'] = ['/sbin', 52 | '/bin', 53 | '/usr/sbin', 54 | '/usr/bin'] 55 | # purposely sane defaults 56 | else 57 | default['system']['profile']['path'] = ['/usr/local/sbin', 58 | '/usr/local/bin', 59 | '/usr/sbin', 60 | '/usr/bin', 61 | '/sbin', 62 | '/bin'] 63 | end 64 | 65 | default['system']['profile']['path_prepend'] = [] 66 | default['system']['profile']['path_append'] = [] 67 | default['system']['profile']['append_scripts'] = [] 68 | -------------------------------------------------------------------------------- /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 | 98 | # Docker # 99 | ########## 100 | Dockerfile 101 | Dockerfile.mutable 102 | 103 | # archives # 104 | *.tar.giz 105 | *.zip 106 | *.xz 107 | 108 | # misc # 109 | .bundle 110 | .chef 111 | .kitchen 112 | Makefile 113 | vendor 114 | .vendor 115 | -------------------------------------------------------------------------------- /libraries/host_info.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Library:: host_info 5 | # 6 | # Copyright 2012-2014, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | # This module provides basic methods to shell-out and 21 | # return stripped output of system commands related 22 | # to its hostname information 23 | module HostInfo 24 | def self.shell_command(cmd) 25 | Mixlib::ShellOut.new(cmd).run_command.stdout.strip 26 | end 27 | 28 | def self.hostname 29 | shell_command('hostname') 30 | end 31 | 32 | def self.network_node 33 | shell_command('uname -n') 34 | end 35 | 36 | def self.host_aliases 37 | shell_command('hostname -a') 38 | end 39 | 40 | def self.short_name 41 | shell_command('hostname -s') 42 | end 43 | 44 | def self.domain_name 45 | shell_command('hostname -d') 46 | end 47 | 48 | def self.fqdn 49 | shell_command('hostname -f') 50 | end 51 | 52 | def self.host_ip 53 | shell_command('hostname -i') 54 | end 55 | 56 | def self.hostnamectl 57 | shell_command('hostnamectl') 58 | end 59 | 60 | def self.apple_smb_server 61 | shell_command('defaults read /Library/Preferences/SystemConfiguration/com.apple.smb.server') 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /libraries/matchers.rb: -------------------------------------------------------------------------------- 1 | # rubocop:disable Style/AccessorMethodName 2 | if defined?(ChefSpec) 3 | ChefSpec.define_matcher :system_timezone 4 | 5 | def set_system_timezone(resource_name) 6 | ChefSpec::Matchers::ResourceMatcher.new(:system_timezone, :set, resource_name) 7 | end 8 | 9 | ChefSpec.define_matcher :system_environment 10 | 11 | def configure_system_environment(resource_name) 12 | ChefSpec::Matchers::ResourceMatcher.new(:system_environment, :configure, resource_name) 13 | end 14 | 15 | ChefSpec.define_matcher :system_hostname 16 | 17 | def set_system_hostname(resource_name) 18 | ChefSpec::Matchers::ResourceMatcher.new(:system_hostname, :set, resource_name) 19 | end 20 | 21 | ChefSpec.define_matcher :system_packages 22 | 23 | def install_system_packages(resource_name) 24 | ChefSpec::Matchers::ResourceMatcher.new(:system_packages, :install, resource_name) 25 | end 26 | 27 | def uninstall_system_packages(resource_name) 28 | ChefSpec::Matchers::ResourceMatcher.new(:system_packages, :uninstall, resource_name) 29 | end 30 | 31 | ChefSpec.define_matcher :system_profile 32 | 33 | def configure_system_profile(resource_name) 34 | ChefSpec::Matchers::ResourceMatcher.new(:system_profile, :configure, resource_name) 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /libraries/url_package.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Library:: url_package 5 | # 6 | # Copyright 2012-2014, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | # This module provides a way of installing a package by URL 21 | module URLPackage 22 | def self.provider(filename) 23 | # return suitable package provider based on file extension 24 | case filename.split('.').last.downcase 25 | when 'deb' 26 | Chef::Provider::Package::Dpkg 27 | when 'rpm' 28 | Chef::Provider::Package::Rpm 29 | when 'gem' 30 | Chef::Provider::Package::Rubygems 31 | when 'xz' 32 | Chef::Provider::Package::Pacman 33 | else 34 | Chef::Provider::Package 35 | end 36 | end 37 | 38 | def self.filename(url) 39 | require 'uri' 40 | 41 | # get filename from URL 42 | pkg_file = ::File.basename(URI.parse(url).path) 43 | pkg_file 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /metadata.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | name 'system' 4 | version '0.12.0' 5 | maintainer 'Xhost Australia' 6 | maintainer_email 'cookbooks@xhost.com.au' 7 | license 'Apache-2.0' 8 | description 'Installs/Configures system elements such as the hostname and timezone.' 9 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) 10 | source_url 'https://github.com/xhost-cookbooks/system' 11 | issues_url 'https://github.com/xhost-cookbooks/system/issues' 12 | chef_version '>= 11.12.0' if respond_to?(:chef_version) 13 | 14 | recipe 'system::default', "Sets the system's hostname and timezone, updates the system's installed packages." 15 | recipe 'system::timezone', "Sets the system's' timezone." 16 | recipe 'system::hostname', "Sets the system's hostname." 17 | recipe 'system::profile', "Manage the system's profile such as search path and scripts (/etc/profile)." 18 | recipe 'system::upgrade_packages', "Upgrades the system's installed packages." 19 | recipe 'system::update_package_list', "Updates the system's list of packages in the package manager's cache." 20 | recipe 'system::install_packages', "Installs packages to the system with it's native package manager." 21 | recipe 'system::reboot', 'Attempts to gracefully reboot the operating system.' 22 | recipe 'system::shutdown', 'Attempts to gracefully shutdown the operating system.' 23 | 24 | %w(ubuntu debian centos fedora redhat arch mac_os_x).each { |os| supports os } 25 | 26 | depends 'apt' 27 | depends 'cron' 28 | depends 'hostsfile' 29 | 30 | attribute 'system/timezone', 31 | display_name: 'Timezone', 32 | description: 'The system timezone, which must be a valid zoneinfo/tz database entry.', 33 | required: 'optional', 34 | default: 'UTC', 35 | recipes: ['system::timezone', 'system::default'], 36 | choice: [ 37 | 'Africa/Casablanca', 38 | 'America/Bogota', 39 | 'America/Buenos_Aires', 40 | 'America/Caracas', 41 | 'America/La_Paz', 42 | 'America/Lima', 43 | 'America/Mexico_City', 44 | 'Asia/Almaty', 45 | 'Asia/Baghdad', 46 | 'Asia/Baku', 47 | 'Asia/Bangkok', 48 | 'Asia/Calcutta', 49 | 'Asia/Colombo', 50 | 'Asia/Dhaka', 51 | 'Asia/Hong_Kong', 52 | 'Asia/Jakarta', 53 | 'Asia/Kabul', 54 | 'Asia/Kamchatka', 55 | 'Asia/Karachi', 56 | 'Asia/Kathmandu', 57 | 'Asia/Magadan', 58 | 'Asia/Muscat', 59 | 'Asia/Riyadh', 60 | 'Asia/Seoul', 61 | 'Asia/Singapore', 62 | 'Asia/Tashkent', 63 | 'Asia/Tbilisi', 64 | 'Asia/Tehran', 65 | 'Asia/Tokyo', 66 | 'Asia/Vladivostok', 67 | 'Asia/Yakutsk', 68 | 'Asia/Yekaterinburg', 69 | 'Atlantic/Azores', 70 | 'Atlantic/Cape_Verde', 71 | 'Australia/Adelaide', 72 | 'Australia/Darwin', 73 | 'Australia/Perth', 74 | 'Australia/Sydney', 75 | 'Brazil/Acre', 76 | 'Brazil/DeNoronha', 77 | 'Brazil/East', 78 | 'Brazil/West', 79 | 'Canada/Atlantic', 80 | 'Canada/Newfoundland', 81 | 'Europe/Brussels', 82 | 'Europe/Copenhagen', 83 | 'Europe/Kaliningrad', 84 | 'Europe/Lisbon', 85 | 'Europe/London', 86 | 'Europe/Helsinki', 87 | 'Europe/Madrid', 88 | 'Europe/Moscow', 89 | 'Europe/Paris', 90 | 'Pacific/Auckland', 91 | 'Pacific/Fiji', 92 | 'Pacific/Guam', 93 | 'Pacific/Kwajalein', 94 | 'Pacific/Midway', 95 | 'US/Alaska', 96 | 'US/Central', 97 | 'US/Eastern', 98 | 'US/Hawaii', 99 | 'US/Mountain', 100 | 'US/Pacific', 101 | 'US/Samoa', 102 | 'GMT', 103 | 'UTC', 104 | 'localtime', 105 | ] 106 | 107 | attribute 'system/short_hostname', 108 | display_name: 'Short Hostname', 109 | description: 'The short hostname that you would like this node to have, e.g. kryten.', 110 | required: 'recommended', 111 | default: 'localhost', 112 | recipes: ['system::hostname', 'system::default'] 113 | 114 | attribute 'system/domain_name', 115 | display_name: 'Domain Name', 116 | description: 'The domain name that you would like this node to have, e.g. domain.suf. Note: Only set a valid domain name '\ 117 | 'to satisfy the resolution of a FQDN; use ignore:ignore for no domain name.', 118 | required: 'recommended', 119 | default: 'localdomain', 120 | recipes: ['system::hostname', 'system::default'] 121 | 122 | attribute 'system/netbios_name', 123 | display_name: 'NetBIOS Name', 124 | description: 'The NetBIOS name to set on the node, default is the value of node/short_hostname upper-cased (OS X only).', 125 | required: 'optional', 126 | recipes: ['system::hostname', 'system::default'] 127 | 128 | attribute 'system/workgroup', 129 | display_name: 'NetBIOS Workgroup', 130 | description: "The NetBIOS workgroup name to set on the node, default is 'WORKGROUP' (OS X only).", 131 | required: 'optional', 132 | default: 'WORKGROUP', 133 | recipes: ['system::hostname', 'system::default'] 134 | 135 | attribute 'system/upgrade_packages', 136 | display_name: 'Upgrade Packages', 137 | description: "Whether or not the system::upgrade_packages recipe will physically update the system's installed packages.", 138 | required: 'optional', 139 | type: 'boolean', 140 | choice: [true, false], 141 | default: true, 142 | recipes: ['system::upgrade_packages'] 143 | 144 | attribute 'system/upgrade_packages_at_compile', 145 | display_name: 'Upgrade Packages at compile time', 146 | description: "Whether or not the system::upgrade_packages recipe will update the system's installed packages at compile time.", 147 | required: 'optional', 148 | type: 'boolean', 149 | choice: [true, false], 150 | default: true, 151 | recipes: ['system::upgrade_packages'] 152 | 153 | attribute 'system/manage_hostsfile', 154 | display_name: 'Manage Hostsfile', 155 | description: 'Whether or not to manage /etc/hostsfile (in any way).', 156 | required: 'optional', 157 | type: 'boolean', 158 | choice: [true, false], 159 | default: true, 160 | recipes: ['system::hostname', 'system::default'] 161 | 162 | attribute 'system/enable_cron', 163 | display_name: 'Enable cron recipe', 164 | description: 'Whether or not the system::timezone recipe will include the cron recipe.', 165 | required: 'optional', 166 | type: 'boolean', 167 | choice: [true, false], 168 | default: true, 169 | recipes: ['system::timezone'] 170 | 171 | attribute 'system/packages/install', 172 | display_name: 'Install Packages', 173 | description: 'An array of system packages to install with the package resource in execute phase.', 174 | required: 'optional', 175 | type: 'array', 176 | recipes: ['system::install_packages'] 177 | 178 | attribute 'system/packages/install_compile_time', 179 | display_name: 'Install Packages Compile Phase', 180 | description: 'An array of system packages to install with the package resource in compile phase.', 181 | required: 'optional', 182 | type: 'array', 183 | recipes: ['system::install_packages'] 184 | 185 | attribute 'system/permanent_ip', 186 | display_name: 'Permanent IP Address', 187 | description: 'Whether the system has a permenent IP address (http://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_hostname_resolution).', 188 | required: 'optional', 189 | type: 'boolean', 190 | choice: [true, false], 191 | default: true, 192 | recipes: ['system::hostname', 'system::default'] 193 | 194 | attribute 'system/static_hosts', 195 | display_name: 'Static Hosts', 196 | description: 'A hash of static hosts to add to /etc/hosts.', 197 | required: 'optional', 198 | type: 'hash', 199 | recipes: ['system::hostname', 'system::default'] 200 | 201 | attribute 'system/primary_interface', 202 | display_name: 'Primary Network Interface', 203 | description: "Specify primary network interface, used by hostname to set the correct address in hostsfile. default is node['network']['default_interface'].", 204 | required: 'optional', 205 | recipes: ['system::hostname', 'system::default'] 206 | 207 | attribute 'system/delay_network_restart', 208 | display_name: 'Delay Network Restart', 209 | description: 'Whether or not the system hostnamem provider will trigger a network restart as delayed vs. immediate.', 210 | required: 'optional', 211 | type: 'boolean', 212 | choice: [true, false], 213 | default: true, 214 | recipes: ['system::hostname', 'system::default'] 215 | 216 | attribute 'system/profile/path', 217 | display_name: 'System Profile Path', 218 | description: 'Overrides the default path for the system.', 219 | required: 'optional', 220 | type: 'array', 221 | recipes: ['system::profile'] 222 | 223 | attribute 'system/profile/path_append', 224 | display_name: 'System Profile Path Append', 225 | description: 'Append more paths to the base path.', 226 | required: 'optional', 227 | type: 'array', 228 | recipes: ['system::profile'] 229 | 230 | attribute 'system/profile/path_prepend', 231 | display_name: 'System Profile Path Prepend', 232 | description: 'Prepends more paths to the base path.', 233 | required: 'optional', 234 | type: 'array', 235 | recipes: ['system::profile'] 236 | 237 | attribute 'system/profile/append_scripts', 238 | display_name: 'System Profile Path Append', 239 | description: 'An array of shell scripts to be appended to the system profile (include raw scripts without shebangs).', 240 | required: 'optional', 241 | type: 'array', 242 | recipes: ['system::profile'] 243 | -------------------------------------------------------------------------------- /providers/environment.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Provider:: environment 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | use_inline_resources 21 | 22 | action :configure do 23 | template new_resource.filename do 24 | variables( 25 | extra: new_resource.extra 26 | ) 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /providers/hostname.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Provider:: hostname 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | use_inline_resources 21 | 22 | # represents Chef 23 | class Chef 24 | # include the HostInfo library 25 | class Recipe 26 | include HostInfo 27 | end 28 | end 29 | 30 | action :set do 31 | # user can specify short_hostname and domain_name or simply 32 | # derive it from the name of the resource 33 | 34 | short_hostname = if new_resource.short_hostname 35 | new_resource.short_hostname 36 | else 37 | # as the resource must have a name, there will always 38 | # be one result from the split 39 | new_resource.hostname.split('.').first 40 | end 41 | 42 | domain_name = if new_resource.domain_name 43 | new_resource.domain_name 44 | elsif new_resource.hostname.split('.').count >= 2 45 | new_resource.hostname.split('.')[1..-1].join('.') 46 | else 47 | # fallback domain name to 'localdomain' 48 | # to complete a valid FQDN 49 | node['system']['domain_name'] 50 | end 51 | 52 | # finally, raise if we don't have a valid hostname 53 | # http://en.wikipedia.org/wiki/Hostname 54 | raise "#{short_hostname} is not a valid hostname!" unless \ 55 | short_hostname =~ /^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$/ 56 | 57 | # reconstruct the fqdn 58 | fqdn = "#{short_hostname}.#{domain_name}" 59 | ::Chef::Log.debug "FQDN determined to be: #{fqdn}" 60 | 61 | # https://tickets.opscode.com/browse/OHAI-389 62 | # http://lists.opscode.com/sympa/arc/chef/2014-10/msg00092.html 63 | node.automatic_attrs['fqdn'] = fqdn 64 | node.automatic_attrs['hostname'] = new_resource.short_hostname 65 | 66 | # FreeBSD 67 | ruby_block 'update hostname in /etc/rc.conf' do 68 | block do 69 | fe = ::Chef::Util::FileEdit.new('/etc/rc.conf') 70 | fe.search_file_replace_line(/hostname\=/, "hostname=#{fqdn}") 71 | fe.write_file 72 | end 73 | only_if { platform?('freebsd') } 74 | not_if { ::File.readlines('/etc/rc.conf').grep(/hostname=#{fqdn}/).any? } 75 | end 76 | 77 | if platform_family?('mac_os_x') 78 | execute 'set configd parameter: HostName' do 79 | command "scutil --set HostName #{fqdn}" 80 | not_if { Mixlib::ShellOut.new('scutil --get HostName').run_command.stdout.strip == fqdn } 81 | notifies :create, 'ruby_block[show host info]', :delayed 82 | end 83 | 84 | shorthost_params = %w(ComputerName LocalHostName) 85 | shorthost_params.each do |param| 86 | execute "set configd parameter: #{param}" do 87 | command "scutil --set #{param} #{short_hostname}" 88 | not_if { Mixlib::ShellOut.new("scutil --get #{param}").run_command.stdout.strip == short_hostname } 89 | notifies :create, 'ruby_block[show host info]', :delayed 90 | end 91 | end 92 | 93 | # https://discussions.apple.com/thread/2457573 94 | smb_params = { 'NetBIOSName' => new_resource.netbios_name, 95 | 'Workgroup' => new_resource.workgroup } 96 | default = '/Library/Preferences/SystemConfiguration/com.apple.smb.server' 97 | smb_params.each do |param, value| 98 | execute "set configd parameter: #{param}" do 99 | command "defaults write #{default} #{param} #{value}" 100 | not_if { Mixlib::ShellOut.new("defaults read #{default} #{param}").run_command.stdout.strip == value } 101 | notifies :create, 'ruby_block[show host info]', :delayed 102 | end 103 | end 104 | end 105 | 106 | primary_if = node['network']['interfaces'][node['system']['primary_interface']] 107 | primary_addrs = primary_if['addresses'] 108 | primary_addrs_ipv4 = primary_addrs.select { |_addr, attrs| attrs['family'] == 'inet' } 109 | primary_ip = primary_addrs_ipv4.keys.first 110 | ::Chef::Log.debug "primary_ip is: #{primary_ip}" 111 | 112 | # http://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_hostname_resolution 113 | if node['system']['permanent_ip'] 114 | # remove 127.0.0.1 from /etc/hosts when using permanent IP 115 | hostsfile_entry "127.0.1.1_#{new_resource.name}" do 116 | ip_address '127.0.1.1' 117 | action :remove 118 | only_if { new_resource.manage_hostsfile } 119 | end 120 | hostsfile_entry "127.0.0.1_#{new_resource.name}" do 121 | ip_address '127.0.0.1' 122 | hostname 'localhost.localdomain' 123 | aliases ['localhost'] 124 | action node['system']['hostsfile_behaviour'].to_sym 125 | only_if { new_resource.manage_hostsfile } 126 | end 127 | # condition used due to https://github.com/xhost-cookbooks/system/issues/35 128 | if primary_ip 129 | hostsfile_entry "#{primary_ip}_#{new_resource.name}" do 130 | ip_address primary_ip 131 | hostname lazy { fqdn } 132 | aliases [new_resource.short_hostname] 133 | action node['system']['hostsfile_behaviour'].to_sym 134 | only_if { new_resource.manage_hostsfile } 135 | end 136 | end 137 | else 138 | # condition used due to https://github.com/xhost-cookbooks/system/issues/35 139 | if primary_ip 140 | hostsfile_entry "#{primary_ip}_#{new_resource.name}" do 141 | ip_address primary_ip 142 | hostname lazy { fqdn } 143 | aliases [new_resource.short_hostname] 144 | action :remove 145 | only_if { new_resource.manage_hostsfile } 146 | end 147 | end 148 | hostsfile_entry "127.0.1.1_#{new_resource.name}" do 149 | ip_address '127.0.1.1' 150 | hostname lazy { fqdn } 151 | aliases [new_resource.short_hostname] 152 | action node['system']['hostsfile_behaviour'].to_sym 153 | only_if { platform_family?('debian') } 154 | only_if { new_resource.manage_hostsfile } 155 | end 156 | hostsfile_entry "127.0.0.1_#{new_resource.name}" do 157 | ip_address '127.0.0.1' 158 | hostname lazy { fqdn } 159 | aliases [new_resource.short_hostname, 'localhost.localdomain', 'localhost'] 160 | action node['system']['hostsfile_behaviour'].to_sym 161 | not_if { platform_family?('debian') } 162 | only_if { new_resource.manage_hostsfile } 163 | end 164 | end 165 | 166 | # add in/ensure this default host for mac_os_x 167 | hostsfile_entry "255.255.255.255_#{new_resource.name}" do 168 | ip_address '255.255.255.255' 169 | hostname 'broadcasthost' 170 | action node['system']['hostsfile_behaviour'].to_sym 171 | only_if { platform_family?('mac_os_x') } 172 | only_if { new_resource.manage_hostsfile } 173 | end 174 | 175 | # the following are desirable for IPv6 capable hosts 176 | ipv6_hosts = [ 177 | { ip: '::1', name: 'localhost6.localdomain6', 178 | aliases: %w(localhost6 ip6-localhost ip6-loopback) }, 179 | { ip: 'fe00::0', name: 'ip6-localnet' }, 180 | { ip: 'ff00::0', name: 'ip6-mcastprefix' }, 181 | { ip: 'ff02::1', name: 'ip6-allnodes' }, 182 | { ip: 'ff02::2', name: 'ip6-allrouters' }, 183 | ] 184 | 185 | # we'll keep ipv6 stock for os x 186 | if platform_family?('mac_os_x') 187 | ipv6_hosts.select { |h| h[:ip] == '::1' }[0][:name] = 'localhost' 188 | ipv6_hosts.select { |h| h[:ip] == '::1' }[0][:aliases] = nil 189 | ipv6_hosts = [ipv6_hosts.slice(1 - 1)] 190 | end 191 | 192 | # add the ipv6 hosts to /etc/hosts 193 | ipv6_hosts.each do |host| 194 | hostsfile_entry "#{host[:ip]}_#{new_resource.name}" do 195 | ip_address host[:ip] 196 | hostname host[:name] 197 | aliases host[:aliases] if host[:aliases] 198 | priority 5 199 | action node['system']['hostsfile_behaviour'].to_sym 200 | only_if { new_resource.manage_hostsfile } 201 | end 202 | end 203 | 204 | # additional static hosts 205 | new_resource.static_hosts.each do |ip, host| 206 | hostsfile_entry "#{ip}_#{new_resource.name}" do 207 | ip_address ip 208 | hostname host 209 | priority 6 210 | action node['system']['hostsfile_behaviour'].to_sym 211 | only_if { new_resource.manage_hostsfile } 212 | end 213 | end 214 | 215 | # (re)start the hostname[.sh] service on debian-based distros 216 | if platform_family?('debian') 217 | case node['platform'] 218 | when 'debian', 'raspbian' 219 | service_name = 'hostname.sh' 220 | service_supports = { 221 | start: true, 222 | restart: false, 223 | status: false, 224 | reload: false, 225 | } 226 | 227 | # Debian moved to systemd 228 | service_provider = if node['platform_version'] >= '8.0' 229 | ::Chef::Provider::Service::Systemd 230 | else 231 | ::Chef::Provider::Service::Init::Debian 232 | end 233 | when 'ubuntu' 234 | service_name = 'hostname' 235 | service_supports = { 236 | start: true, 237 | restart: true, 238 | status: false, 239 | reload: true, 240 | } 241 | 242 | # Ubuntu moved to systemd 243 | service_provider = if node['platform_version'] >= '15.04' 244 | ::Chef::Provider::Service::Systemd 245 | else 246 | ::Chef::Provider::Service::Upstart 247 | end 248 | end 249 | 250 | service service_name do 251 | supports service_supports 252 | provider service_provider 253 | not_if { service_provider == ::Chef::Provider::Service::Systemd } 254 | action :nothing 255 | end 256 | end 257 | 258 | # http://www.rackspace.com/knowledge_center/article/centos-hostname-change 259 | service 'network' do 260 | only_if { platform_family?('rhel') } 261 | only_if { node['platform_version'] < '7.0' } 262 | end 263 | 264 | # we want to physically set the hostname in the compile phase 265 | # as early as possible, just in case (although its not actually needed) 266 | execute 'run hostname' do 267 | command "hostname #{fqdn}" 268 | action :nothing 269 | not_if { Mixlib::ShellOut.new('hostname -f').run_command.stdout.strip == fqdn } 270 | end.run_action(:run) 271 | 272 | # let's not manage the entire file because its shared 273 | ruby_block 'update network sysconfig' do 274 | block do 275 | fe = ::Chef::Util::FileEdit.new('/etc/sysconfig/network') 276 | fe.search_file_replace_line(/HOSTNAME\=/, "HOSTNAME=#{fqdn}") 277 | fe.insert_line_if_no_match(/HOSTNAME\=/, "HOSTNAME=#{fqdn}") 278 | fe.write_file 279 | end 280 | only_if { ::File.exist?('/etc/sysconfig/network') } 281 | not_if { ::File.readlines('/etc/sysconfig/network').grep(/HOSTNAME=#{fqdn}/).any? } 282 | notifies :restart, 'service[network]', node['system']['delay_network_restart'] ? :delayed : :immediately 283 | end 284 | 285 | ruby_block 'show hostnamectl' do 286 | block do 287 | ::Chef::Log.info('== hostnamectl ==') 288 | ::Chef::Log.info(HostInfo.hostnamectl) 289 | end 290 | action :nothing 291 | only_if "bash -c 'type -P hostnamectl'" 292 | end 293 | 294 | # https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/sec_Configuring_Host_Names_Using_hostnamectl.html 295 | # hostnamectl is used by other distributions too 296 | execute 'run hostnamectl' do 297 | command "hostnamectl set-hostname #{fqdn}" 298 | only_if "bash -c 'type -P hostnamectl'" 299 | not_if { Mixlib::ShellOut.new('hostname -f').run_command.stdout.strip == fqdn } 300 | notifies :create, 'ruby_block[show hostnamectl]', :delayed 301 | end 302 | 303 | # run domainname command if available 304 | execute 'run domainname' do 305 | command "domainname #{new_resource.domain_name}" 306 | only_if "bash -c 'type -P domainname'" 307 | not_if { Mixlib::ShellOut.new('domainname').run_command.stdout.strip == new_resource.domain_name } 308 | action :nothing 309 | end 310 | 311 | # for systems with cloud-init, ensure preserve hostname 312 | # https://aws.amazon.com/premiumsupport/knowledge-center/linux-static-hostname-rhel7-centos7/ 313 | file '/etc/cloud/cloud.cfg.d/01_preserve_hostname.cfg' do 314 | content "preserve_hostname: true\n" 315 | only_if { ::File.exist?('/etc/cloud/cloud.cfg.d') } 316 | end 317 | 318 | # for systems with nmcli (NetworkManager) 319 | execute 'update hostname via nmcli' do 320 | command "nmcli general hostname #{short_hostname}" 321 | not_if { Mixlib::ShellOut.new('hostname -s').run_command.stdout.strip == short_hostname } 322 | only_if "bash -c 'type -P nmcli'" 323 | end 324 | 325 | # for systemd systems with systemd-hostnamed unit 326 | service 'systemd-hostnamed' do 327 | provider ::Chef::Provider::Service::Systemd 328 | only_if "bash -c 'type -P systemctl && systemctl is-enabled systemd-hostnamed'" 329 | action :nothing 330 | end 331 | 332 | # Show the new host/node information 333 | ruby_block 'show host info' do 334 | block do 335 | ::Chef::Log.info('== New host/node information ==') 336 | ::Chef::Log.info("Hostname: #{HostInfo.hostname == '' ? '' : HostInfo.hostname}") 337 | ::Chef::Log.info("Network node hostname: #{HostInfo.network_node == '' ? '' : HostInfo.network_node}") 338 | ::Chef::Log.info("Alias names of host: #{HostInfo.host_aliases == '' ? '' : HostInfo.host_aliases}") 339 | ::Chef::Log.info("Short host name (cut from first dot of hostname): #{HostInfo.short_name == '' ? '' : HostInfo.short_name}") 340 | ::Chef::Log.info("Domain of hostname: #{HostInfo.domain_name == '' ? '' : HostInfo.domain_name}") 341 | ::Chef::Log.info("FQDN of host: #{HostInfo.fqdn == '' ? '' : HostInfo.fqdn}") 342 | ::Chef::Log.info("IP address(es) for the hostname: #{HostInfo.host_ip == '' ? '' : HostInfo.host_ip}") 343 | ::Chef::Log.info("Current FQDN in node object: #{node['fqdn']}") 344 | ::Chef::Log.info("Apple SMB Server: #{HostInfo.apple_smb_server}") if node['platform'] == 'mac_os_x' 345 | end 346 | action :nothing 347 | end 348 | 349 | file '/etc/hostname' do 350 | owner 'root' 351 | group 'root' 352 | mode 0644 353 | # https://www.freedesktop.org/software/systemd/man/hostname.html 354 | # do not include any comment lines to be on the safe side, 355 | # /etc/init.d/hostname.sh on debian does not ignore them 356 | content "#{short_hostname}\n" 357 | action :create 358 | notifies :start, resources("service[#{service_name}]"), :immediately if platform?('debian', 'raspbian') 359 | notifies :restart, resources("service[#{service_name}]"), :immediately if platform?('ubuntu') 360 | notifies :restart, resources('service[systemd-hostnamed]'), :delayed 361 | notifies :create, 'ruby_block[update network sysconfig]', :immediately 362 | notifies :run, 'execute[run domainname]', :immediately 363 | notifies :run, 'execute[run hostname]', :immediately 364 | notifies :create, 'ruby_block[show host info]', :delayed 365 | not_if { platform?('mac_os_x') } 366 | not_if { platform?('freebsd') } 367 | end 368 | 369 | # covers cases where a dhcp client has manually 370 | # set the hostname (such as with the hostname command) 371 | # and /etc/hostname has not changed 372 | # this can be the the case with ec2 ebs start 373 | execute "ensure hostname sync'd" do 374 | command "hostname #{fqdn}" 375 | not_if { Mixlib::ShellOut.new('hostname -f').run_command.stdout.strip == fqdn } 376 | end 377 | 378 | # rightscale support: rightlink CLI tools, rs_tag 379 | execute 'set rightscale server hostname tag' do 380 | command "rs_tag --add 'node:hostname=#{fqdn}'" 381 | only_if "bash -c 'type -P rs_tag'" 382 | end 383 | end # close action :set 384 | -------------------------------------------------------------------------------- /providers/packages.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Provider:: packages 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | use_inline_resources 21 | 22 | # represents Chef 23 | class Chef 24 | # include the URLPackage library 25 | class Recipe 26 | include URLPackage 27 | end 28 | end 29 | 30 | action :install do 31 | new_resource.packages.each do |package| 32 | require 'uri' 33 | 34 | if package =~ URI.regexp 35 | # package is remote by URL 36 | 37 | # get the filename from the URL 38 | pkg_file = URLPackage.filename(package) 39 | 40 | # fetch the remote package 41 | remote_file "#{::Chef::Config[:file_cache_path]}/#{pkg_file}" do 42 | source package 43 | end 44 | 45 | # install the package in compile time or normally 46 | if new_resource.phase == 'compile' 47 | p = package pkg_file.split('.').first do 48 | source "#{::Chef::Config[:file_cache_path]}/#{pkg_file}" 49 | provider URLPackage.provider(pkg_file) 50 | action :nothing 51 | end 52 | p.run_action(:install) 53 | else 54 | package pkg_file.split('.').first do 55 | source "#{::Chef::Config[:file_cache_path]}/#{pkg_file}" 56 | provider URLPackage.provider(pkg_file) 57 | end 58 | end 59 | elsif new_resource.phase == :compile 60 | # install the packages in compile time or normally 61 | p = package package do 62 | action :nothing 63 | end 64 | p.run_action(:install) 65 | else 66 | package package 67 | end 68 | end 69 | end # close action :install 70 | 71 | action :uninstall do 72 | if new_resource.phase == :compile 73 | # uninstall the packages in compile time 74 | new_resource.packages.each do |package| 75 | p = package package do 76 | action :nothing 77 | end 78 | p.run_action(:remove) 79 | end 80 | else 81 | # remove each package normally 82 | new_resource.packages.each do |package| 83 | package package do 84 | action :remove 85 | end 86 | end 87 | end 88 | end # close action :uninstall 89 | -------------------------------------------------------------------------------- /providers/profile.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Provider:: profile 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | use_inline_resources 21 | 22 | action :configure do 23 | template new_resource.filename do 24 | variables profile: { 25 | path: new_resource.path_prepend + \ 26 | new_resource.path + \ 27 | new_resource.path_append, 28 | append_scripts: new_resource.append_scripts, 29 | } 30 | # Specify that the templates are from the system 31 | # cookbook 32 | cookbook 'system' 33 | if new_resource.template 34 | new_resource.template.each do |attr, value| 35 | send attr, value 36 | end 37 | else 38 | source 'profile.erb' 39 | end 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /providers/timezone.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Provider:: timezone 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | # SYSTEMSETUP(8) could be used on mac_os_x, however from oberservation 21 | # linking /etc/localtime in the same manner as linux is adequate 22 | 23 | use_inline_resources 24 | 25 | action :set do 26 | # ensure the cron package is installed and cron is in the resource collection 27 | # http://jtimberman.housepub.org/blog/2015/01/17/quick-tip-define-resources-to-notifiy-in-lwrps/ 28 | # https://github.com/chef-cookbooks/cron/blob/master/recipes/default.rb#L20-L27 29 | if node['system']['enable_cron'] && node['platform'] != 'mac_os_x' 30 | node['cron']['package_name'].each do |pkg| 31 | package pkg 32 | end 33 | 34 | service 'cron' do 35 | service_name node['cron']['service_name'] unless node['cron']['service_name'].nil? 36 | action [:enable, :start] 37 | end 38 | end 39 | 40 | # support user specifying a space instead of underscore in zone file path 41 | zone_file = new_resource.timezone.sub(' ', '_') 42 | 43 | # the zone file needs to exist in the system share to succeed 44 | raise "#{zone_file} is not a valid timezone!" unless ::File.file?("/usr/share/zoneinfo/#{zone_file}") 45 | 46 | # initially assume a zone change 47 | zone_change = true 48 | 49 | # when already a symlink to the zone_file, no need to reconfigure timezone 50 | if ::File.symlink?('/etc/localtime') 51 | if ::File.readlink('/etc/localtime').include? zone_file 52 | zone_change = false 53 | end 54 | end 55 | 56 | log "tz-info (before set): #{Time.now.strftime('%z %Z')}" do 57 | level :debug 58 | only_if { zone_change } 59 | end 60 | 61 | if %w(debian ubuntu).member? node['platform'] 62 | package 'tzdata' 63 | 64 | bash 'dpkg-reconfigure tzdata' do 65 | user 'root' 66 | code '/usr/sbin/dpkg-reconfigure -f noninteractive tzdata' 67 | action :nothing 68 | end 69 | 70 | file '/etc/timezone' do 71 | owner 'root' 72 | group 'root' 73 | content "#{zone_file}\n" 74 | notifies :run, 'bash[dpkg-reconfigure tzdata]' 75 | end 76 | end 77 | 78 | execute "timedatectl set-timezone #{zone_file}" do 79 | if node['system']['enable_cron'] && node['platform'] != 'mac_os_x' 80 | notifies :restart, 'service[cron]', :immediately 81 | end 82 | notifies :create, 'ruby_block[verify newly-linked timezone]', :delayed 83 | only_if "bash -c 'type -P timedatectl'" 84 | not_if { Mixlib::ShellOut.new('timedatectl').run_command.stdout.include?(zone_file) } 85 | end 86 | 87 | link '/etc/localtime' do 88 | to "/usr/share/zoneinfo/#{zone_file}" 89 | if node['system']['enable_cron'] && node['platform'] != 'mac_os_x' 90 | notifies :restart, 'service[cron]', :immediately 91 | end 92 | notifies :create, 'ruby_block[verify newly-linked timezone]', :delayed 93 | not_if "bash -c 'type -P timedatectl'" 94 | end 95 | 96 | ruby_block 'verify newly-linked timezone' do 97 | block do 98 | tz_info = ::Time.now.strftime('%z %Z') 99 | tz_info << "#{::File.readlink('/etc/localtime').gsub(/^/, ' (').gsub(/$/, ')')})" 100 | ::Chef::Log.debug("tz-info (after set): #{tz_info}") 101 | end 102 | action :nothing 103 | only_if { ::File.symlink?('/etc/localtime') } 104 | only_if { zone_change } 105 | end 106 | end 107 | -------------------------------------------------------------------------------- /recipes/default.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: default 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | include_recipe 'system::update_package_list' 21 | include_recipe 'system::timezone' 22 | include_recipe 'system::hostname' 23 | -------------------------------------------------------------------------------- /recipes/environment.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: environment 5 | # 6 | # Copyright 2015-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | system_environment '/etc/environment' do 21 | extra node['system']['environment']['extra'] 22 | end 23 | -------------------------------------------------------------------------------- /recipes/hostname.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: hostname 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | system_hostname node['system']['short_hostname'] do 21 | short_hostname node['system']['short_hostname'] 22 | domain_name node['system']['domain_name'] 23 | static_hosts node['system']['static_hosts'] 24 | netbios_name node['system']['netbios_name'] 25 | workgroup node['system']['workgroup'] 26 | manage_hostsfile node['system']['manage_hostsfile'] 27 | not_if { node['virtualization'] && node['virtualization']['system'] && node['virtualization']['system'] == 'docker' } 28 | 29 | # https://github.com/chef/ohai/pull/569 not yet in most used chef versions 30 | not_if '[ -e /.dockerinit ]' 31 | end 32 | -------------------------------------------------------------------------------- /recipes/install_packages.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: install_packages 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | system_packages node['system']['packages']['install'].join(',') do 21 | packages node['system']['packages']['install'] 22 | end 23 | 24 | system_packages node['system']['packages']['install_compile_time'].join(',') do 25 | packages node['system']['packages']['install_compile_time'] 26 | phase :compile 27 | end 28 | -------------------------------------------------------------------------------- /recipes/profile.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: profile 5 | # 6 | # Copyright 2015-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | system_profile '/etc/profile' do 21 | node['system']['profile'].each do |attr, value| 22 | send attr, value 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /recipes/reboot.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: reboot 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | execute 'reboot_system' do 21 | command '(sleep 5 && reboot) > /dev/null 2>&1' 22 | end 23 | -------------------------------------------------------------------------------- /recipes/shutdown.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: shutdown 5 | # 6 | # Copyright 2015-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | execute 'shutdown_system' do 21 | command '(sleep 5 && shutdown -h now) > /dev/null 2>&1' 22 | end 23 | -------------------------------------------------------------------------------- /recipes/test_fqdn_set.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: test_fqdn_template 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | template '/tmp/test_fqdn_set.txt' do 21 | source 'test_fqdn_set.erb' 22 | variables lazy { 23 | { 24 | fqdn: node['fqdn'], 25 | } 26 | } 27 | end 28 | 29 | log 'lazy_log_fqdn' do 30 | message lazy { node['fqdn'] } 31 | end 32 | -------------------------------------------------------------------------------- /recipes/timezone.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: timezone 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | system_timezone node['system']['timezone'] 21 | -------------------------------------------------------------------------------- /recipes/uninstall_packages.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: uninstall_packages 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | system_packages node['system']['packages']['uninstall'].join(',') do 21 | packages node['system']['packages']['uninstall'] 22 | action :uninstall 23 | end 24 | 25 | system_packages node['system']['packages']['uninstall_compile_time'].join(',') do 26 | packages node['system']['packages']['uninstall_compile_time'] 27 | action :uninstall 28 | phase :compile 29 | end 30 | -------------------------------------------------------------------------------- /recipes/update_package_list.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: update_package_list 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | include_recipe 'apt' if platform_family?('debian') 21 | 22 | # sync the MacPorts tree if older than 1 week 23 | execute 'sync macports tree' do 24 | command 'port -d sync' 25 | only_if { platform_family?('mac_os_x') } 26 | only_if "bash -c 'type -P port'" 27 | only_if { (Time.now - File.mtime('/opt/local/var/macports/pingtimes')) >= 604_800 } 28 | end 29 | -------------------------------------------------------------------------------- /recipes/upgrade_packages.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Recipe:: upgrade_packages 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | include_recipe 'system::update_package_list' 21 | 22 | upgrade_cmd = value_for_platform( 23 | %w(ubuntu debian) => { 24 | 'default' => 'export DEBIAN_FRONTEND=noninteractive; apt-get -y upgrade', 25 | }, 26 | %w(centos redhat scientific amazon) => { 27 | 'default' => 'yum -y update && yum -y upgrade', 28 | }, 29 | 'fedora' => { 'default' => 'dnf -y upgrade' }, 30 | 'suse' => { 'default' => 'zypper --non-interactive update' }, 31 | 'arch' => { 32 | 'default' => 'pacman --sync --refresh --sysupgrade --noprogressbar -q', 33 | }, 34 | 'freebsd' => { 'default' => 'portupgrade -af' }, 35 | 'mac_os_x' => { 'default' => 'port upgrade installed' } 36 | ) 37 | 38 | e = execute 'upgrade system packages' do 39 | command upgrade_cmd 40 | action(node['system']['upgrade_packages_at_compile'] ? :nothing : :run) 41 | only_if { node['system']['upgrade_packages'] } 42 | end 43 | 44 | if node['system']['upgrade_packages_at_compile'] 45 | # supports type string if defined through metadata 46 | e.run_action(:run) 47 | end 48 | -------------------------------------------------------------------------------- /resources/environment.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Resource:: environment 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | actions [:configure] 21 | default_action :configure 22 | 23 | # typically '/etc/environment' 24 | attribute :filename, 25 | name_attribute: true, 26 | kind_of: String 27 | 28 | attribute :extra, 29 | kind_of: Hash, 30 | default: nil 31 | -------------------------------------------------------------------------------- /resources/hostname.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Resource:: hostname 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | actions :set 21 | default_action :set 22 | 23 | attribute :hostname, 24 | kind_of: String, 25 | name_attribute: true 26 | 27 | attribute :short_hostname, 28 | kind_of: String, 29 | default: nil 30 | 31 | attribute :domain_name, 32 | kind_of: String, 33 | default: nil 34 | 35 | attribute :static_hosts, 36 | kind_of: Hash, 37 | default: {} 38 | 39 | attribute :manage_hostsfile, 40 | kind_of: [TrueClass, FalseClass], 41 | default: true 42 | 43 | attribute :netbios_name, 44 | kind_of: String, 45 | default: nil 46 | 47 | attribute :workgroup, 48 | kind_of: String, 49 | default: nil 50 | -------------------------------------------------------------------------------- /resources/packages.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Resource:: packages 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | actions [:install, :uninstall] 21 | default_action :install 22 | 23 | attribute :packages, 24 | kind_of: Array, 25 | default: [] 26 | 27 | attribute :phase, 28 | kind_of: [String, Symbol], 29 | default: :converge 30 | -------------------------------------------------------------------------------- /resources/profile.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Resource:: profile 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | actions [:configure] 21 | default_action :configure 22 | 23 | # typically '/etc/profile' 24 | attribute :filename, 25 | name_attribute: true, 26 | kind_of: String 27 | 28 | attribute :template, 29 | kind_of: Hash, 30 | default: nil 31 | 32 | attribute :path, 33 | kind_of: Array, 34 | default: [] 35 | 36 | attribute :path_append, 37 | kind_of: Array, 38 | default: [] 39 | 40 | attribute :path_prepend, 41 | kind_of: Array, 42 | default: [] 43 | 44 | attribute :append_scripts, 45 | kind_of: Array, 46 | default: [] 47 | -------------------------------------------------------------------------------- /resources/timezone.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | # Cookbook Name:: system 4 | # Resource:: timezone 5 | # 6 | # Copyright 2012-2016, Chris Fordham 7 | # 8 | # Licensed under the Apache License, Version 2.0 (the "License"); 9 | # you may not use this file except in compliance with the License. 10 | # You may obtain a copy of the License at 11 | # 12 | # http://www.apache.org/licenses/LICENSE-2.0 13 | # 14 | # Unless required by applicable law or agreed to in writing, software 15 | # distributed under the License is distributed on an "AS IS" BASIS, 16 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | # See the License for the specific language governing permissions and 18 | # limitations under the License. 19 | 20 | # use 'Etc/UTC' for UTC/GMT 21 | attribute :timezone, 22 | kind_of: String, 23 | name_attribute: true 24 | 25 | actions :set 26 | default_action :set 27 | 28 | def initialize(*args) 29 | super 30 | @action = :set 31 | 32 | # arch can be removed once arch linux support is in the cron cookbook 33 | # looks like arch got jib'd again 34 | # https://github.com/opscode-cookbooks/cron/pull/49 needs merge 35 | @run_context.include_recipe 'cron' if node['system']['enable_cron'] && !(node['platform'] == 'arch' || node['platform'] == 'mac_os_x' || node['platform'] == 'freebsd') 36 | end 37 | -------------------------------------------------------------------------------- /templates/arch/environment.erb: -------------------------------------------------------------------------------- 1 | # 2 | # This file is parsed by pam_env module 3 | # 4 | # Syntax: simple "KEY=VAL" pairs on separate lines 5 | # 6 | # This file is managed by Chef 7 | # Do not edit this file by hand! 8 | 9 | <% @extra.each do |k, v| -%> 10 | <%= k %>=<%= v %> 11 | <% end -%> 12 | -------------------------------------------------------------------------------- /templates/arch/profile.erb: -------------------------------------------------------------------------------- 1 | # /etc/profile 2 | 3 | # This file is managed by Chef 4 | # Do not edit this file by hand! 5 | 6 | # Set our umask 7 | umask 022 8 | 9 | # Set our default path 10 | PATH=<%= @profile[:path].join ':' %> 11 | export PATH 12 | 13 | # Load profiles from /etc/profile.d 14 | if test -d /etc/profile.d/; then 15 | for profile in /etc/profile.d/*.sh; do 16 | test -r "$profile" && . "$profile" 17 | done 18 | unset profile 19 | fi 20 | 21 | # Source global bash config 22 | if test "$PS1" && test "$BASH" && test -r /etc/bash.bashrc; then 23 | . /etc/bash.bashrc 24 | fi 25 | 26 | # Termcap is outdated, old, and crusty, kill it. 27 | unset TERMCAP 28 | 29 | # Man is much better than us at figuring this out 30 | unset MANPATH 31 | 32 | <%= @profile[:append_scripts].join "\n" %> 33 | -------------------------------------------------------------------------------- /templates/centos/environment.erb: -------------------------------------------------------------------------------- 1 | # This file is managed by Chef 2 | # Do not edit this file by hand! 3 | 4 | <% @extra.each do |k, v| -%> 5 | <%= k %>=<%= v %> 6 | <% end -%> 7 | -------------------------------------------------------------------------------- /templates/centos/profile.erb: -------------------------------------------------------------------------------- 1 | # /etc/profile 2 | 3 | # This file is managed by Chef 4 | # Do not edit this file by hand! 5 | 6 | # System wide environment and startup programs, for login setup 7 | # Functions and aliases go in /etc/bashrc 8 | 9 | # It's NOT a good idea to change this file unless you know what you 10 | # are doing. It's much better to create a custom.sh shell script in 11 | # /etc/profile.d/ to make custom changes to your environment, as this 12 | # will prevent the need for merging in future updates. 13 | 14 | pathmunge () { 15 | case ":${PATH}:" in 16 | *:"$1":*) 17 | ;; 18 | *) 19 | if [ "$2" = "after" ] ; then 20 | PATH=<%= "#{@profile[:path].join ':'}:" unless @profile[:path].empty? %>$PATH:$1 21 | else 22 | PATH=<%= "#{@profile[:path].join ':'}:" unless @profile[:path].empty? %>$1:$PATH 23 | fi 24 | esac 25 | } 26 | 27 | 28 | if [ -x /usr/bin/id ]; then 29 | if [ -z "$EUID" ]; then 30 | # ksh workaround 31 | EUID=`id -u` 32 | UID=`id -ru` 33 | fi 34 | USER="`id -un`" 35 | LOGNAME=$USER 36 | MAIL="/var/spool/mail/$USER" 37 | fi 38 | 39 | # Path manipulation 40 | if [ "$EUID" = "0" ]; then 41 | pathmunge /usr/sbin 42 | pathmunge /usr/local/sbin 43 | else 44 | pathmunge /usr/local/sbin after 45 | pathmunge /usr/sbin after 46 | fi 47 | 48 | HOSTNAME=`/usr/bin/hostname 2>/dev/null` 49 | HISTSIZE=1000 50 | if [ "$HISTCONTROL" = "ignorespace" ] ; then 51 | export HISTCONTROL=ignoreboth 52 | else 53 | export HISTCONTROL=ignoredups 54 | fi 55 | 56 | export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL 57 | 58 | # By default, we want umask to get set. This sets it for login shell 59 | # Current threshold for system reserved uid/gids is 200 60 | # You could check uidgid reservation validity in 61 | # /usr/share/doc/setup-*/uidgid file 62 | if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then 63 | umask 002 64 | else 65 | umask 022 66 | fi 67 | 68 | for i in /etc/profile.d/*.sh ; do 69 | if [ -r "$i" ]; then 70 | if [ "${-#*i}" != "$-" ]; then 71 | . "$i" 72 | else 73 | . "$i" >/dev/null 74 | fi 75 | fi 76 | done 77 | 78 | unset i 79 | unset -f pathmunge 80 | 81 | <%= @profile[:append_scripts].join "\n" %> 82 | -------------------------------------------------------------------------------- /templates/debian/environment.erb: -------------------------------------------------------------------------------- 1 | # This file is managed by Chef 2 | # Do not edit this file by hand! 3 | 4 | <% @extra.each do |k, v| -%> 5 | <%= k %>=<%= v %> 6 | <% end -%> 7 | -------------------------------------------------------------------------------- /templates/debian/profile.erb: -------------------------------------------------------------------------------- 1 | # /etc/profile: system-wide .profile file for the Bourne shell (sh(1)) 2 | # and Bourne compatible shells (bash(1), ksh(1), ash(1), ...). 3 | 4 | # This file is managed by Chef 5 | # Do not edit this file by hand! 6 | 7 | if [ "`id -u`" -eq 0 ]; then 8 | # retain the default PATH for root 9 | PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" 10 | else 11 | PATH="<%= @profile[:path].join ':' %>" 12 | fi 13 | export PATH 14 | 15 | if [ "$PS1" ]; then 16 | if [ "$BASH" ] && [ "$BASH" != "/bin/sh" ]; then 17 | # The file bash.bashrc already sets the default PS1. 18 | # PS1='\h:\w\$ ' 19 | if [ -f /etc/bash.bashrc ]; then 20 | . /etc/bash.bashrc 21 | fi 22 | else 23 | if [ "`id -u`" -eq 0 ]; then 24 | PS1='# ' 25 | else 26 | PS1='$ ' 27 | fi 28 | fi 29 | fi 30 | 31 | if [ -d /etc/profile.d ]; then 32 | for i in /etc/profile.d/*.sh; do 33 | if [ -r $i ]; then 34 | . $i 35 | fi 36 | done 37 | unset i 38 | fi 39 | 40 | <%= @profile[:append_scripts].join "\n" %> 41 | -------------------------------------------------------------------------------- /templates/default/environment.erb: -------------------------------------------------------------------------------- 1 | # This file is managed by Chef 2 | # Do not edit this file by hand! 3 | 4 | <% @extra.each do |k, v| -%> 5 | <%= k %>=<%= v %> 6 | <% end -%> 7 | -------------------------------------------------------------------------------- /templates/default/profile.erb: -------------------------------------------------------------------------------- 1 | # /etc/profile 2 | 3 | # This file is managed by Chef 4 | # Do not edit this file by hand! 5 | 6 | # Set default path 7 | PATH="<%= @profile[:path].join ':' %>" 8 | export PATH 9 | 10 | # The default umask is now handled by pam_umask. 11 | # See pam_umask(8) and /etc/login.defs. 12 | #umask 022 13 | 14 | # Load profiles from /etc/profile.d 15 | if test -d /etc/profile.d/; then 16 | for profile in /etc/profile.d/*.sh; do 17 | test -r "$profile" && . "$profile" 18 | done 19 | unset profile 20 | fi 21 | 22 | # Source global bash config, other shells do it themselves 23 | if test "$PS1" && test "$BASH" && test -r /etc/bash.bashrc; then 24 | . /etc/bash.bashrc 25 | fi 26 | 27 | <%= @profile[:append_scripts].join "\n" %> 28 | -------------------------------------------------------------------------------- /templates/default/test_fqdn_set.erb: -------------------------------------------------------------------------------- 1 | Is @fqdn: [<%= @fqdn %>] the same as node['fqdn']: [<%= node['fqdn'] %>] ? 2 | -------------------------------------------------------------------------------- /templates/fedora/environment.erb: -------------------------------------------------------------------------------- 1 | # This file is managed by Chef 2 | # Do not edit this file by hand! 3 | 4 | <% @extra.each do |k, v| -%> 5 | <%= k %>=<%= v %> 6 | <% end -%> 7 | -------------------------------------------------------------------------------- /templates/fedora/profile.erb: -------------------------------------------------------------------------------- 1 | # /etc/profile 2 | 3 | # This file is managed by Chef 4 | # Do not edit this file by hand! 5 | 6 | # System wide environment and startup programs, for login setup 7 | # Functions and aliases go in /etc/bashrc 8 | 9 | # It's NOT a good idea to change this file unless you know what you 10 | # are doing. It's much better to create a custom.sh shell script in 11 | # /etc/profile.d/ to make custom changes to your environment, as this 12 | # will prevent the need for merging in future updates. 13 | 14 | pathmunge () { 15 | case ":${PATH}:" in 16 | *:"$1":*) 17 | ;; 18 | *) 19 | if [ "$2" = "after" ] ; then 20 | PATH=<%= "#{@profile[:path].join ':'}:" unless @profile[:path].empty? %>$PATH:$1 21 | else 22 | PATH=<%= "#{@profile[:path].join ':'}:" unless @profile[:path].empty? %>$1:$PATH 23 | fi 24 | esac 25 | } 26 | 27 | 28 | if [ -x /usr/bin/id ]; then 29 | if [ -z "$EUID" ]; then 30 | # ksh workaround 31 | EUID=`id -u` 32 | UID=`id -ru` 33 | fi 34 | USER="`id -un`" 35 | LOGNAME=$USER 36 | MAIL="/var/spool/mail/$USER" 37 | fi 38 | 39 | # Path manipulation 40 | if [ "$EUID" = "0" ]; then 41 | pathmunge /usr/sbin 42 | pathmunge /usr/local/sbin 43 | else 44 | pathmunge /usr/local/sbin after 45 | pathmunge /usr/sbin after 46 | fi 47 | 48 | HOSTNAME=`/usr/bin/hostname 2>/dev/null` 49 | HISTSIZE=1000 50 | if [ "$HISTCONTROL" = "ignorespace" ] ; then 51 | export HISTCONTROL=ignoreboth 52 | else 53 | export HISTCONTROL=ignoredups 54 | fi 55 | 56 | export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL 57 | 58 | # By default, we want umask to get set. This sets it for login shell 59 | # Current threshold for system reserved uid/gids is 200 60 | # You could check uidgid reservation validity in 61 | # /usr/share/doc/setup-*/uidgid file 62 | if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then 63 | umask 002 64 | else 65 | umask 022 66 | fi 67 | 68 | for i in /etc/profile.d/*.sh ; do 69 | if [ -r "$i" ]; then 70 | if [ "${-#*i}" != "$-" ]; then 71 | . "$i" 72 | else 73 | . "$i" >/dev/null 74 | fi 75 | fi 76 | done 77 | 78 | unset i 79 | unset -f pathmunge 80 | 81 | <%= @profile[:append_scripts].join "\n" %> 82 | -------------------------------------------------------------------------------- /templates/freebsd/profile.erb: -------------------------------------------------------------------------------- 1 | # $FreeBSD: releng/10.1/etc/profile 208116 2010-05-15 17:49:56Z jilles $ 2 | # 3 | # System-wide .profile file for sh(1). 4 | # 5 | # This file is managed by Chef 6 | # Do not edit this file by hand! 7 | # 8 | # Uncomment this to give you the default 4.2 behavior, where disk 9 | # information is shown in K-Blocks 10 | # BLOCKSIZE=K; export BLOCKSIZE 11 | # 12 | # For the setting of languages and character sets please see 13 | # login.conf(5) and in particular the charset and lang options. 14 | # For full locales list check /usr/share/locale/* 15 | # You should also read the setlocale(3) man page for information 16 | # on how to achieve more precise control of locale settings. 17 | # 18 | # Check system messages 19 | # msgs -q 20 | # Allow terminal messages 21 | # mesg y 22 | 23 | PATH=<%= @profile[:path].join ':' %> 24 | 25 | <%= @profile[:append_scripts].join "\n" %> 26 | -------------------------------------------------------------------------------- /templates/redhat/environment.erb: -------------------------------------------------------------------------------- 1 | # This file is managed by Chef 2 | # Do not edit this file by hand! 3 | 4 | <% @extra.each do |k, v| -%> 5 | <%= k %>=<%= v %> 6 | <% end -%> 7 | -------------------------------------------------------------------------------- /templates/redhat/profile.erb: -------------------------------------------------------------------------------- 1 | # /etc/profile 2 | 3 | # This file is managed by Chef 4 | # Do not edit this file by hand! 5 | 6 | # System wide environment and startup programs, for login setup 7 | # Functions and aliases go in /etc/bashrc 8 | 9 | # It's NOT a good idea to change this file unless you know what you 10 | # are doing. It's much better to create a custom.sh shell script in 11 | # /etc/profile.d/ to make custom changes to your environment, as this 12 | # will prevent the need for merging in future updates. 13 | 14 | pathmunge () { 15 | case ":${PATH}:" in 16 | *:"$1":*) 17 | ;; 18 | *) 19 | if [ "$2" = "after" ] ; then 20 | PATH=<%= "#{@profile[:path].join ':'}:" unless @profile[:path].empty? %>$PATH:$1 21 | else 22 | PATH=<%= "#{@profile[:path].join ':'}:" unless @profile[:path].empty? %>$1:$PATH 23 | fi 24 | esac 25 | } 26 | 27 | 28 | if [ -x /usr/bin/id ]; then 29 | if [ -z "$EUID" ]; then 30 | # ksh workaround 31 | EUID=`id -u` 32 | UID=`id -ru` 33 | fi 34 | USER="`id -un`" 35 | LOGNAME=$USER 36 | MAIL="/var/spool/mail/$USER" 37 | fi 38 | 39 | # Path manipulation 40 | if [ "$EUID" = "0" ]; then 41 | pathmunge /usr/sbin 42 | pathmunge /usr/local/sbin 43 | else 44 | pathmunge /usr/local/sbin after 45 | pathmunge /usr/sbin after 46 | fi 47 | 48 | HOSTNAME=`/usr/bin/hostname 2>/dev/null` 49 | HISTSIZE=1000 50 | if [ "$HISTCONTROL" = "ignorespace" ] ; then 51 | export HISTCONTROL=ignoreboth 52 | else 53 | export HISTCONTROL=ignoredups 54 | fi 55 | 56 | export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL 57 | 58 | # By default, we want umask to get set. This sets it for login shell 59 | # Current threshold for system reserved uid/gids is 200 60 | # You could check uidgid reservation validity in 61 | # /usr/share/doc/setup-*/uidgid file 62 | if [ $UID -gt 199 ] && [ "`id -gn`" = "`id -un`" ]; then 63 | umask 002 64 | else 65 | umask 022 66 | fi 67 | 68 | for i in /etc/profile.d/*.sh ; do 69 | if [ -r "$i" ]; then 70 | if [ "${-#*i}" != "$-" ]; then 71 | . "$i" 72 | else 73 | . "$i" >/dev/null 74 | fi 75 | fi 76 | done 77 | 78 | unset i 79 | unset -f pathmunge 80 | 81 | PATH=<%= @profile[:path].join ':' %> 82 | 83 | <%= @profile[:append_scripts].join "\n" %> 84 | -------------------------------------------------------------------------------- /templates/ubuntu/environment.erb: -------------------------------------------------------------------------------- 1 | # This file is managed by Chef 2 | # Do not edit this file by hand! 3 | 4 | PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games" 5 | 6 | <% @extra.each do |k, v| -%> 7 | <%= k %>=<%= v %> 8 | <% end -%> 9 | -------------------------------------------------------------------------------- /templates/ubuntu/profile.erb: -------------------------------------------------------------------------------- 1 | # /etc/profile: system-wide .profile file for bash(1). 2 | 3 | # This file is managed by Chef 4 | # Do not edit this file by hand! 5 | 6 | if [ -f /etc/sysprofile ]; then 7 | if [ `grep -x ^SYSDEBUG=1 /etc/sysprofile` ]; then 8 | if [ ! -d /var/tmp/sysprofile ]; then 9 | mkdir -m 1777 /var/tmp/sysprofile 10 | touch /var/tmp/sysprofile/$USER 11 | chmod 600 /var/tmp/sysprofile/$USER 12 | fi 13 | . /etc/sysprofile >> /var/tmp/sysprofile/$USER 2>&1 14 | else 15 | . /etc/sysprofile 16 | fi 17 | fi 18 | 19 | PATH=$PATH:<%= @profile[:path].join ':' %> 20 | 21 | <%= @profile[:append_scripts].join "\n" %> 22 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/default_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require_relative 'spec_helper' 4 | 5 | # http://linux.die.net/man/1/hostname 6 | 7 | # hostname -s command should return the short hostname 8 | describe command('hostname -s') do 9 | its(:stdout) do 10 | should contain('test') 11 | end 12 | end 13 | 14 | # nsswitch on redhat-based expects the FQDN to be physically resolvable by DNS 15 | unless os[:family] == 'redhat' 16 | # hostname -f command should return the FQDN 17 | describe command('hostname -f') do 18 | its(:stdout) do 19 | should contain('test.kitchen') 20 | end 21 | end 22 | # hostname -d command should return the domain name (linux only) 23 | unless os[:family] == ('freebsd' || 'darwin') 24 | describe command('hostname -d') do 25 | its(:stdout) do 26 | should contain('kitchen') 27 | end 28 | end 29 | end 30 | end 31 | 32 | # /etc/hostname 33 | # no /etc/hostname used on bsd systems 34 | unless os[:family] == ('freebsd' || 'darwin') 35 | describe file('/etc/hostname') do 36 | it { should exist } 37 | it { should be_file } 38 | it { should be_owned_by 'root' } 39 | it { should be_grouped_into 'root' } 40 | it { should be_mode 644 } 41 | it { should be_readable.by('owner') } 42 | it { should be_readable.by('group') } 43 | it { should be_readable.by('others') } 44 | end 45 | end 46 | 47 | describe file('/etc/localtime') do 48 | it { should be_owned_by 'root' } 49 | end 50 | 51 | # timezone checks 52 | # /etc/timezone (debian family only) 53 | if os[:family] == 'debian' || os[:family] == 'ubuntu' 54 | describe file('/etc/timezone') do 55 | it { should be_file } 56 | it { should be_owned_by 'root' } 57 | end 58 | 59 | describe file('/etc/timezone') do 60 | its(:content) { should contain 'Australia/Sydney' } 61 | end 62 | else 63 | describe file('/etc/localtime') do 64 | it { should be_symlink } 65 | end 66 | 67 | describe command('ls -l /etc/localtime') do 68 | its(:stdout) do 69 | should contain('/usr/share/zoneinfo/Australia/Sydney').after('->') 70 | end 71 | end 72 | end 73 | 74 | # serverspec ping doesn't seem to work in freebsd 75 | unless os[:family] == 'freebsd' || os[:family] == 'darwin' 76 | describe host('localhost') do 77 | it { should be_resolvable.by('localhost') } 78 | it { should be_reachable } 79 | end 80 | end 81 | # redhat-based expects DNS resolution via nsswitch 82 | unless os[:family] == 'redhat' 83 | describe host('test.kitchen') do 84 | it { should be_resolvable.by('hosts') } 85 | it { should be_reachable } 86 | end 87 | end 88 | 89 | # it's a little early to be able to expect most 90 | # host/guest environments to be able to do these 91 | # ipv6_hosts = %w(localhost6.localdomain6 92 | # localhost6 93 | # ip6-localhost 94 | # ip6-loopback 95 | # ip6-localnet 96 | # ip6-mcastprefix 97 | # ip6-allnodes 98 | # ip6-allrouters) 99 | # ipv6_hosts.each do |host| 100 | # describe host(host) do 101 | # # ping 102 | # it { should be_reachable } 103 | # # resolution 104 | # it { should be_resolvable.by('hosts') } 105 | # end 106 | # end 107 | 108 | # /etc/hosts 109 | describe file('/etc/hosts') do 110 | it { should contain('localhost').after('::1') } 111 | it { should contain('localhost').after('127.0.0.1') } 112 | it { should contain('localhost.localdomain').after('127.0.0.1') } 113 | it { should contain('localdomain').after('127.0.0.1') } 114 | it { should contain('chef.io').after('184.106.28.82') } 115 | it { should contain('supermarket.io').after('95.211.29.66') } 116 | unless os[:family] == 'redhat' 117 | it { should contain('test.kitchen') } 118 | end 119 | end 120 | 121 | # el6 and older 122 | if %w(redhat).include?(os[:family]) && os[:release] < '7.0' 123 | describe file('/etc/sysconfig/network') do 124 | it 'is a file' do 125 | expect(subject).to be_file 126 | end 127 | it { should contain 'HOSTNAME=test.kitchen' } 128 | end 129 | end 130 | 131 | # the cron service should be running 132 | case os[:family] 133 | when 'redhat', 'fedora' 134 | cron_service_name = 'crond' 135 | when 'gentoo' 136 | cron_service_name = 'vixie-cron' 137 | when 'arch' 138 | cron_service_name = 'cronie' 139 | else 140 | cron_service_name = 'cron' 141 | end 142 | 143 | describe service(cron_service_name) do 144 | it { should be_running } 145 | end 146 | 147 | describe file('/etc/profile') do 148 | its(:content) { should contain 'export CHEF_IS_AWESOME=1' } 149 | its(:content) { should contain('/opt/local/bin').after('PATH=') } 150 | its(:content) { should contain('/opt/local/food/bin').after('PATH=') } 151 | end 152 | 153 | describe file('/etc/environment') do 154 | its(:content) { should contain 'DINNER=Pizza' } 155 | its(:content) { should contain 'DESERT=Ice cream' } 156 | end 157 | -------------------------------------------------------------------------------- /test/integration/default/serverspec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require 'serverspec' 4 | 5 | set :backend, :exec 6 | 7 | RSpec.configure do |c| 8 | c.before :all do 9 | c.path = '/bin:/sbin:/usr/sbin:/usr/bin' 10 | end 11 | end 12 | -------------------------------------------------------------------------------- /test/unit/spec/default_spec.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require_relative 'spec_helper' 4 | 5 | describe 'system::default' do 6 | let(:chef_run) do 7 | ChefSpec::SoloRunner.new do |_node| 8 | stub_command('ls /.dockerinit').and_return(false) 9 | end.converge(described_recipe) 10 | end 11 | 12 | it 'includes the `update_package_list` recipe' do 13 | expect(chef_run).to include_recipe('system::update_package_list') 14 | end 15 | 16 | it 'includes the `timezone` recipe' do 17 | expect(chef_run).to include_recipe('system::timezone') 18 | end 19 | 20 | it 'includes the `hostname` recipe' do 21 | expect(chef_run).to include_recipe('system::hostname') 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /test/unit/spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # encoding: UTF-8 2 | 3 | require 'codeclimate-test-reporter' 4 | CodeClimate::TestReporter.start 5 | 6 | require 'chefspec' 7 | require 'chefspec/berkshelf' 8 | require 'chef/application' 9 | 10 | ::LOG_LEVEL = :fatal 11 | ::UBUNTU_OPTS = { 12 | platform: 'ubuntu', 13 | version: '12.04', 14 | log_level: ::LOG_LEVEL, 15 | }.freeze 16 | ::CHEFSPEC_OPTS = { 17 | log_level: ::LOG_LEVEL, 18 | }.freeze 19 | 20 | def stub_resources; end 21 | 22 | at_exit { ChefSpec::Coverage.report! } 23 | --------------------------------------------------------------------------------