From 6a435337dfa95633e5692360468b878a08f880c1 Mon Sep 17 00:00:00 2001 From: Stefan Richter Date: Wed, 4 Dec 2013 23:19:09 +0100 Subject: [PATCH] completing the Vagrant config now using Puppet for simplicity should support VB as well as LXC oob --- Vagrantfile | 88 +- deployment/modules/apache/CHANGELOG.md | 133 ++ deployment/modules/apache/Gemfile | 26 + deployment/modules/apache/Gemfile.lock | 78 ++ deployment/modules/apache/LICENSE | 15 + deployment/modules/apache/Modulefile | 12 + deployment/modules/apache/README.md | 1168 ++++++++++++++++ deployment/modules/apache/README.passenger.md | 89 ++ deployment/modules/apache/Rakefile | 2 + deployment/modules/apache/files/httpd | 24 + .../apache/lib/puppet/provider/a2mod.rb | 34 + .../apache/lib/puppet/provider/a2mod/a2mod.rb | 35 + .../lib/puppet/provider/a2mod/gentoo.rb | 116 ++ .../lib/puppet/provider/a2mod/modfix.rb | 12 + .../lib/puppet/provider/a2mod/redhat.rb | 60 + .../modules/apache/lib/puppet/type/a2mod.rb | 30 + .../modules/apache/manifests/balancer.pp | 80 ++ .../apache/manifests/balancermember.pp | 52 + .../modules/apache/manifests/default_mods.pp | 73 + .../apache/manifests/default_mods/load.pp | 8 + deployment/modules/apache/manifests/dev.pp | 8 + deployment/modules/apache/manifests/init.pp | 258 ++++ deployment/modules/apache/manifests/listen.pp | 10 + deployment/modules/apache/manifests/mod.pp | 93 ++ .../modules/apache/manifests/mod/alias.pp | 16 + .../apache/manifests/mod/auth_basic.pp | 3 + .../modules/apache/manifests/mod/auth_kerb.pp | 5 + .../modules/apache/manifests/mod/autoindex.pp | 12 + .../modules/apache/manifests/mod/cache.pp | 3 + .../modules/apache/manifests/mod/cgi.pp | 4 + .../modules/apache/manifests/mod/cgid.pp | 22 + .../modules/apache/manifests/mod/dav.pp | 3 + .../modules/apache/manifests/mod/dav_fs.pp | 19 + .../modules/apache/manifests/mod/dav_svn.pp | 4 + .../modules/apache/manifests/mod/deflate.pp | 12 + .../modules/apache/manifests/mod/dev.pp | 5 + .../modules/apache/manifests/mod/dir.pp | 21 + .../apache/manifests/mod/disk_cache.pp | 19 + .../modules/apache/manifests/mod/fcgid.pp | 3 + .../modules/apache/manifests/mod/headers.pp | 3 + .../modules/apache/manifests/mod/info.pp | 14 + .../modules/apache/manifests/mod/itk.pp | 53 + .../modules/apache/manifests/mod/ldap.pp | 12 + .../modules/apache/manifests/mod/mime.pp | 12 + .../apache/manifests/mod/mime_magic.pp | 12 + .../modules/apache/manifests/mod/mpm_event.pp | 11 + .../apache/manifests/mod/negotiation.pp | 12 + .../modules/apache/manifests/mod/passenger.pp | 30 + .../modules/apache/manifests/mod/perl.pp | 3 + .../modules/apache/manifests/mod/php.pp | 17 + .../modules/apache/manifests/mod/prefork.pp | 63 + .../modules/apache/manifests/mod/proxy.pp | 15 + .../apache/manifests/mod/proxy_balancer.pp | 5 + .../apache/manifests/mod/proxy_html.pp | 25 + .../apache/manifests/mod/proxy_http.pp | 4 + .../modules/apache/manifests/mod/python.pp | 5 + .../apache/manifests/mod/reqtimeout.pp | 12 + .../modules/apache/manifests/mod/rewrite.pp | 4 + .../modules/apache/manifests/mod/setenvif.pp | 12 + .../modules/apache/manifests/mod/ssl.pp | 23 + .../modules/apache/manifests/mod/status.pp | 12 + .../modules/apache/manifests/mod/suphp.pp | 14 + .../modules/apache/manifests/mod/userdir.pp | 17 + .../apache/manifests/mod/vhost_alias.pp | 3 + .../modules/apache/manifests/mod/worker.pp | 64 + .../modules/apache/manifests/mod/wsgi.pp | 19 + .../modules/apache/manifests/mod/xsendfile.pp | 4 + .../apache/manifests/namevirtualhost.pp | 10 + deployment/modules/apache/manifests/params.pp | 132 ++ deployment/modules/apache/manifests/php.pp | 18 + deployment/modules/apache/manifests/proxy.pp | 15 + deployment/modules/apache/manifests/python.pp | 18 + .../modules/apache/manifests/service.pp | 29 + deployment/modules/apache/manifests/ssl.pp | 18 + deployment/modules/apache/manifests/vhost.pp | 413 ++++++ deployment/modules/apache/metadata.json | 234 ++++ .../apache/spec/classes/apache_spec.rb | 292 ++++ .../modules/apache/spec/classes/dev_spec.rb | 26 + .../apache/spec/classes/mod/auth_kerb_spec.rb | 29 + .../apache/spec/classes/mod/dav_svn_spec.rb | 29 + .../apache/spec/classes/mod/dev_spec.rb | 27 + .../apache/spec/classes/mod/dir_spec.rb | 61 + .../apache/spec/classes/mod/fcgid_spec.rb | 29 + .../apache/spec/classes/mod/info_spec.rb | 81 ++ .../apache/spec/classes/mod/itk_spec.rb | 19 + .../apache/spec/classes/mod/passenger_spec.rb | 94 ++ .../apache/spec/classes/mod/perl_spec.rb | 29 + .../apache/spec/classes/mod/php_spec.rb | 61 + .../apache/spec/classes/mod/prefork_spec.rb | 35 + .../spec/classes/mod/proxy_html_spec.rb | 33 + .../apache/spec/classes/mod/python_spec.rb | 29 + .../apache/spec/classes/mod/ssl_spec.rb | 41 + .../apache/spec/classes/mod/suphp_spec.rb | 27 + .../apache/spec/classes/mod/worker_spec.rb | 32 + .../apache/spec/classes/mod/wsgi_spec.rb | 42 + .../apache/spec/classes/params_spec.rb | 21 + .../apache/spec/classes/service_spec.rb | 62 + .../modules/apache/spec/defines/mod_spec.rb | 79 ++ .../modules/apache/spec/defines/vhost_spec.rb | 658 +++++++++ .../site_apache/templates/fake.conf.erb | 1 + deployment/modules/apache/spec/spec.opts | 4 + deployment/modules/apache/spec/spec_helper.rb | 1 + .../modules/apache/spec/spec_helper_system.rb | 28 + .../modules/apache/spec/system/basic_spec.rb | 22 + .../modules/apache/spec/system/class_spec.rb | 62 + .../apache/spec/system/default_mods_spec.rb | 102 ++ .../modules/apache/spec/system/itk_spec.rb | 36 + .../apache/spec/system/mod_php_spec.rb | 48 + .../apache/spec/system/mod_suphp_spec.rb | 43 + .../apache/spec/system/prefork_worker_spec.rb | 60 + .../apache/spec/system/service_spec.rb | 22 + .../modules/apache/spec/system/vhost_spec.rb | 183 +++ .../spec/unit/provider/a2mod/gentoo_spec.rb | 184 +++ .../modules/apache/templates/httpd.conf.erb | 86 ++ .../modules/apache/templates/listen.erb | 6 + .../apache/templates/mod/alias.conf.erb | 7 + .../apache/templates/mod/autoindex.conf.erb | 56 + .../apache/templates/mod/cgid.conf.erb | 1 + .../apache/templates/mod/dav_fs.conf.erb | 1 + .../apache/templates/mod/deflate.conf.erb | 4 + .../modules/apache/templates/mod/dir.conf.erb | 1 + .../apache/templates/mod/disk_cache.conf.erb | 8 + .../apache/templates/mod/info.conf.erb | 6 + .../modules/apache/templates/mod/itk.conf.erb | 8 + .../apache/templates/mod/ldap.conf.erb | 7 + .../apache/templates/mod/mime.conf.erb | 36 + .../apache/templates/mod/mime_magic.conf.erb | 1 + .../apache/templates/mod/mpm_event.conf.erb | 9 + .../apache/templates/mod/negotiation.conf.erb | 2 + .../apache/templates/mod/passenger.conf.erb | 27 + .../apache/templates/mod/php5.conf.erb | 30 + .../apache/templates/mod/prefork.conf.erb | 8 + .../apache/templates/mod/proxy.conf.erb | 21 + .../apache/templates/mod/proxy_html.conf.erb | 24 + .../apache/templates/mod/reqtimeout.conf.erb | 2 + .../apache/templates/mod/setenvif.conf.erb | 34 + .../modules/apache/templates/mod/ssl.conf.erb | 21 + .../apache/templates/mod/status.conf.erb | 12 + .../apache/templates/mod/suphp.conf.erb | 19 + .../apache/templates/mod/userdir.conf.erb | 19 + .../apache/templates/mod/worker.conf.erb | 9 + .../apache/templates/mod/wsgi.conf.erb | 10 + .../apache/templates/namevirtualhost.erb | 8 + .../modules/apache/templates/ports_header.erb | 5 + .../modules/apache/templates/vhost.conf.erb | 47 + .../apache/templates/vhost/_aliases.erb | 8 + .../modules/apache/templates/vhost/_block.erb | 10 + .../templates/vhost/_custom_fragment.erb | 5 + .../apache/templates/vhost/_directories.erb | 89 ++ .../modules/apache/templates/vhost/_itk.erb | 28 + .../modules/apache/templates/vhost/_proxy.erb | 21 + .../modules/apache/templates/vhost/_rack.erb | 7 + .../apache/templates/vhost/_redirect.erb | 12 + .../apache/templates/vhost/_requestheader.erb | 10 + .../apache/templates/vhost/_rewrite.erb | 14 + .../apache/templates/vhost/_scriptalias.erb | 14 + .../apache/templates/vhost/_serveralias.erb | 7 + .../apache/templates/vhost/_setenv.erb | 12 + .../modules/apache/templates/vhost/_ssl.erb | 26 + .../modules/apache/templates/vhost/_suphp.erb | 11 + .../modules/apache/templates/vhost/_wsgi.erb | 15 + deployment/modules/apache/tests/apache.pp | 6 + deployment/modules/apache/tests/dev.pp | 1 + deployment/modules/apache/tests/init.pp | 1 + deployment/modules/apache/tests/mods.pp | 9 + .../modules/apache/tests/mods_custom.pp | 16 + deployment/modules/apache/tests/php.pp | 1 + deployment/modules/apache/tests/vhost.pp | 185 +++ .../modules/apache/tests/vhost_directories.pp | 30 + .../modules/apache/tests/vhost_ip_based.pp | 25 + deployment/modules/apache/tests/vhost_ssl.pp | 23 + .../apache/tests/vhosts_without_listen.pp | 53 + deployment/modules/apt/manifests/init.pp | 6 + deployment/modules/concat/CHANGELOG | 66 + deployment/modules/concat/Gemfile | 21 + deployment/modules/concat/LICENSE | 14 + deployment/modules/concat/Modulefile | 8 + deployment/modules/concat/README | 91 ++ deployment/modules/concat/README.markdown | 154 +++ deployment/modules/concat/Rakefile | 2 + .../modules/concat/files/concatfragments.sh | 140 ++ .../concat/lib/facter/concat_basedir.rb | 11 + .../modules/concat/manifests/fragment.pp | 67 + deployment/modules/concat/manifests/init.pp | 190 +++ deployment/modules/concat/manifests/setup.pp | 55 + deployment/modules/concat/metadata.json | 39 + .../modules/concat/spec/defines/init_spec.rb | 115 ++ .../concat/spec/fixtures/manifests/site.pp | 0 deployment/modules/concat/spec/spec_helper.rb | 1 + .../modules/concat/spec/spec_helper_system.rb | 25 + .../modules/concat/spec/system/basic_spec.rb | 13 + .../modules/concat/spec/system/concat_spec.rb | 55 + .../modules/concat/spec/system/empty_spec.rb | 27 + .../concat/spec/system/replace_spec.rb | 37 + .../modules/concat/spec/system/warn_spec.rb | 41 + .../modules/evap/files/localsettings.py | 10 + deployment/modules/evap/manifests/init.pp | 2 + deployment/modules/mysql/CHANGELOG | 403 ++++++ deployment/modules/mysql/Gemfile | 24 + deployment/modules/mysql/Gemfile.lock | 129 ++ deployment/modules/mysql/LICENSE | 201 +++ deployment/modules/mysql/Modulefile | 9 + deployment/modules/mysql/README.md | 492 +++++++ deployment/modules/mysql/Rakefile | 2 + deployment/modules/mysql/TODO | 8 + deployment/modules/mysql/files/mysqltuner.pl | 966 +++++++++++++ .../parser/functions/mysql_deepmerge.rb | 52 + .../puppet/parser/functions/mysql_password.rb | 15 + .../parser/functions/mysql_strip_hash.rb | 21 + .../lib/puppet/provider/database/mysql.rb | 52 + .../puppet/provider/database_grant/mysql.rb | 210 +++ .../puppet/provider/database_user/mysql.rb | 76 ++ .../mysql/lib/puppet/provider/mysql.rb | 67 + .../puppet/provider/mysql_database/mysql.rb | 68 + .../lib/puppet/provider/mysql_grant/mysql.rb | 115 ++ .../lib/puppet/provider/mysql_user/mysql.rb | 115 ++ .../modules/mysql/lib/puppet/type/database.rb | 21 + .../mysql/lib/puppet/type/database_grant.rb | 79 ++ .../mysql/lib/puppet/type/database_user.rb | 31 + .../mysql/lib/puppet/type/mysql_database.rb | 22 + .../mysql/lib/puppet/type/mysql_grant.rb | 72 + .../mysql/lib/puppet/type/mysql_user.rb | 45 + deployment/modules/mysql/manifests/backup.pp | 31 + .../modules/mysql/manifests/bindings.pp | 33 + .../modules/mysql/manifests/bindings/java.pp | 10 + .../modules/mysql/manifests/bindings/perl.pp | 10 + .../modules/mysql/manifests/bindings/php.pp | 10 + .../mysql/manifests/bindings/python.pp | 10 + .../modules/mysql/manifests/bindings/ruby.pp | 10 + deployment/modules/mysql/manifests/client.pp | 27 + .../modules/mysql/manifests/client/install.pp | 8 + deployment/modules/mysql/manifests/db.pp | 59 + deployment/modules/mysql/manifests/init.pp | 100 ++ deployment/modules/mysql/manifests/params.pp | 230 ++++ deployment/modules/mysql/manifests/server.pp | 69 + .../manifests/server/account_security.pp | 22 + .../modules/mysql/manifests/server/backup.pp | 56 + .../modules/mysql/manifests/server/config.pp | 31 + .../modules/mysql/manifests/server/install.pp | 9 + .../modules/mysql/manifests/server/monitor.pp | 24 + .../mysql/manifests/server/mysqltuner.pp | 9 + .../mysql/manifests/server/providers.pp | 8 + .../mysql/manifests/server/root_password.pp | 21 + .../modules/mysql/manifests/server/service.pp | 19 + deployment/modules/mysql/metadata.json | 289 ++++ .../mysql/spec/classes/mysql_bindings_spec.rb | 58 + .../mysql/spec/classes/mysql_client_spec.rb | 16 + .../mysql_server_account_security_spec.rb | 41 + .../spec/classes/mysql_server_backup_spec.rb | 112 ++ .../spec/classes/mysql_server_monitor_spec.rb | 31 + .../classes/mysql_server_mysqltuner_spec.rb | 5 + .../mysql/spec/classes/mysql_server_spec.rb | 162 +++ .../mysql/spec/defines/mysql_db_spec.rb | 51 + deployment/modules/mysql/spec/spec.opts | 6 + deployment/modules/mysql/spec/spec_helper.rb | 5 + .../modules/mysql/spec/spec_helper_system.rb | 28 + .../spec/system/mysql_account_delete_spec.rb | 35 + .../mysql/spec/system/mysql_backup_spec.rb | 77 ++ .../mysql/spec/system/mysql_bindings_spec.rb | 90 ++ .../mysql/spec/system/mysql_db_spec.rb | 61 + .../spec/system/mysql_server_monitor_spec.rb | 30 + .../system/mysql_server_root_password_spec.rb | 71 + .../mysql/spec/system/mysql_server_spec.rb | 85 ++ .../spec/system/types/mysql_grant_spec.rb | 314 +++++ .../spec/system/types/mysql_user_spec.rb | 35 + .../mysql/spec/unit/mysql_password_spec.rb | 27 + .../puppet/functions/mysql_deepmerge_spec.rb | 77 ++ .../puppet/provider/database/mysql_spec.rb | 86 ++ .../provider/database_grant/mysql_spec.rb | 95 ++ .../provider/database_user/mysql_spec.rb | 119 ++ .../provider/mysql_database/mysql_spec.rb | 118 ++ .../puppet/provider/mysql_user/mysql_spec.rb | 130 ++ .../unit/puppet/type/mysql_database_spec.rb | 29 + .../spec/unit/puppet/type/mysql_user_spec.rb | 30 + deployment/modules/mysql/templates/my.cnf.erb | 17 + .../modules/mysql/templates/my.cnf.pass.erb | 7 + .../modules/mysql/templates/my.conf.cnf.erb | 17 + .../mysql/templates/mysqlbackup.sh.erb | 57 + deployment/modules/mysql/tests/backup.pp | 8 + deployment/modules/mysql/tests/bindings.pp | 3 + deployment/modules/mysql/tests/init.pp | 1 + deployment/modules/mysql/tests/java.pp | 1 + .../modules/mysql/tests/mysql_database.pp | 12 + deployment/modules/mysql/tests/mysql_grant.pp | 5 + deployment/modules/mysql/tests/mysql_user.pp | 23 + deployment/modules/mysql/tests/perl.pp | 1 + deployment/modules/mysql/tests/python.pp | 1 + deployment/modules/mysql/tests/ruby.pp | 1 + deployment/modules/mysql/tests/server.pp | 3 + .../mysql/tests/server/account_security.pp | 4 + .../modules/mysql/tests/server/config.pp | 11 + deployment/modules/sshd/files/sshd_config | 135 ++ deployment/modules/sshd/manifests/init.pp | 16 + deployment/modules/stdlib/CHANGELOG | 278 ++++ deployment/modules/stdlib/CONTRIBUTING.md | 65 + deployment/modules/stdlib/Gemfile | 42 + deployment/modules/stdlib/LICENSE | 19 + deployment/modules/stdlib/Modulefile | 11 + deployment/modules/stdlib/README.markdown | 1194 +++++++++++++++++ .../modules/stdlib/README_DEVELOPER.markdown | 35 + .../modules/stdlib/README_SPECS.markdown | 7 + .../modules/stdlib/RELEASE_PROCESS.markdown | 24 + deployment/modules/stdlib/Rakefile | 2 + .../modules/stdlib/lib/facter/facter_dot_d.rb | 202 +++ .../modules/stdlib/lib/facter/pe_version.rb | 53 + .../stdlib/lib/facter/puppet_vardir.rb | 26 + .../modules/stdlib/lib/facter/root_home.rb | 19 + .../stdlib/lib/facter/util/puppet_settings.rb | 21 + .../stdlib/lib/puppet/parser/functions/abs.rb | 36 + .../lib/puppet/parser/functions/any2array.rb | 33 + .../lib/puppet/parser/functions/bool2num.rb | 49 + .../lib/puppet/parser/functions/capitalize.rb | 34 + .../lib/puppet/parser/functions/chomp.rb | 35 + .../lib/puppet/parser/functions/chop.rb | 37 + .../lib/puppet/parser/functions/concat.rb | 37 + .../lib/puppet/parser/functions/count.rb | 22 + .../parser/functions/defined_with_params.rb | 35 + .../lib/puppet/parser/functions/delete.rb | 46 + .../lib/puppet/parser/functions/delete_at.rb | 49 + .../lib/puppet/parser/functions/dirname.rb | 15 + .../lib/puppet/parser/functions/downcase.rb | 33 + .../lib/puppet/parser/functions/empty.rb | 28 + .../parser/functions/ensure_packages.rb | 24 + .../parser/functions/ensure_resource.rb | 45 + .../lib/puppet/parser/functions/flatten.rb | 33 + .../lib/puppet/parser/functions/floor.rb | 20 + .../puppet/parser/functions/fqdn_rotate.rb | 46 + .../parser/functions/get_module_path.rb | 17 + .../lib/puppet/parser/functions/getparam.rb | 35 + .../lib/puppet/parser/functions/getvar.rb | 26 + .../lib/puppet/parser/functions/grep.rb | 33 + .../parser/functions/has_interface_with.rb | 52 + .../puppet/parser/functions/has_ip_address.rb | 25 + .../puppet/parser/functions/has_ip_network.rb | 25 + .../lib/puppet/parser/functions/has_key.rb | 28 + .../lib/puppet/parser/functions/hash.rb | 41 + .../lib/puppet/parser/functions/is_array.rb | 22 + .../puppet/parser/functions/is_domain_name.rb | 47 + .../lib/puppet/parser/functions/is_float.rb | 27 + .../parser/functions/is_function_available.rb | 23 + .../lib/puppet/parser/functions/is_hash.rb | 22 + .../lib/puppet/parser/functions/is_integer.rb | 27 + .../puppet/parser/functions/is_ip_address.rb | 32 + .../puppet/parser/functions/is_mac_address.rb | 27 + .../lib/puppet/parser/functions/is_numeric.rb | 27 + .../lib/puppet/parser/functions/is_string.rb | 26 + .../lib/puppet/parser/functions/join.rb | 41 + .../parser/functions/join_keys_to_values.rb | 47 + .../lib/puppet/parser/functions/keys.rb | 26 + .../lib/puppet/parser/functions/loadyaml.rb | 20 + .../lib/puppet/parser/functions/lstrip.rb | 33 + .../stdlib/lib/puppet/parser/functions/max.rb | 21 + .../lib/puppet/parser/functions/member.rb | 44 + .../lib/puppet/parser/functions/merge.rb | 33 + .../stdlib/lib/puppet/parser/functions/min.rb | 21 + .../lib/puppet/parser/functions/num2bool.rb | 43 + .../lib/puppet/parser/functions/parsejson.rb | 24 + .../lib/puppet/parser/functions/parseyaml.rb | 24 + .../lib/puppet/parser/functions/pick.rb | 29 + .../lib/puppet/parser/functions/prefix.rb | 45 + .../lib/puppet/parser/functions/range.rb | 80 ++ .../lib/puppet/parser/functions/reject.rb | 31 + .../lib/puppet/parser/functions/reverse.rb | 28 + .../lib/puppet/parser/functions/rstrip.rb | 32 + .../lib/puppet/parser/functions/shuffle.rb | 46 + .../lib/puppet/parser/functions/size.rb | 48 + .../lib/puppet/parser/functions/sort.rb | 27 + .../lib/puppet/parser/functions/squeeze.rb | 36 + .../lib/puppet/parser/functions/str2bool.rb | 46 + .../parser/functions/str2saltedsha512.rb | 32 + .../lib/puppet/parser/functions/strftime.rb | 107 ++ .../lib/puppet/parser/functions/strip.rb | 39 + .../lib/puppet/parser/functions/suffix.rb | 45 + .../lib/puppet/parser/functions/swapcase.rb | 39 + .../lib/puppet/parser/functions/time.rb | 49 + .../lib/puppet/parser/functions/to_bytes.rb | 28 + .../lib/puppet/parser/functions/type.rb | 50 + .../lib/puppet/parser/functions/unique.rb | 51 + .../lib/puppet/parser/functions/upcase.rb | 41 + .../lib/puppet/parser/functions/uriescape.rb | 36 + .../functions/validate_absolute_path.rb | 56 + .../puppet/parser/functions/validate_array.rb | 33 + .../parser/functions/validate_augeas.rb | 81 ++ .../puppet/parser/functions/validate_bool.rb | 34 + .../puppet/parser/functions/validate_cmd.rb | 47 + .../puppet/parser/functions/validate_hash.rb | 33 + .../puppet/parser/functions/validate_re.rb | 40 + .../parser/functions/validate_slength.rb | 52 + .../parser/functions/validate_string.rb | 33 + .../lib/puppet/parser/functions/values.rb | 39 + .../lib/puppet/parser/functions/values_at.rb | 98 ++ .../stdlib/lib/puppet/parser/functions/zip.rb | 65 + .../lib/puppet/provider/file_line/ruby.rb | 59 + .../modules/stdlib/lib/puppet/type/anchor.rb | 46 + .../stdlib/lib/puppet/type/file_line.rb | 70 + deployment/modules/stdlib/manifests/init.pp | 20 + deployment/modules/stdlib/manifests/stages.pp | 43 + deployment/modules/stdlib/metadata.json | 270 ++++ .../stdlib/spec/classes/anchor_spec.rb | 32 + .../stdlib/spec/fixtures/manifests/site.pp | 0 .../functions/defined_with_params_spec.rb | 37 + .../spec/functions/ensure_packages_spec.rb | 42 + .../spec/functions/ensure_resource_spec.rb | 64 + .../stdlib/spec/functions/getparam_spec.rb | 34 + .../monkey_patches/alias_should_to_must.rb | 8 + .../spec/monkey_patches/publicize_methods.rb | 10 + deployment/modules/stdlib/spec/spec.opts | 6 + deployment/modules/stdlib/spec/spec_helper.rb | 28 + .../unit/facter/pe_required_facts_spec.rb | 69 + .../spec/unit/facter/pe_version_spec.rb | 76 ++ .../stdlib/spec/unit/facter/root_home_spec.rb | 40 + .../unit/facter/util/puppet_settings_spec.rb | 35 + .../unit/puppet/parser/functions/abs_spec.rb | 25 + .../puppet/parser/functions/any2array_spec.rb | 55 + .../puppet/parser/functions/bool2num_spec.rb | 24 + .../parser/functions/capitalize_spec.rb | 19 + .../puppet/parser/functions/chomp_spec.rb | 19 + .../unit/puppet/parser/functions/chop_spec.rb | 19 + .../puppet/parser/functions/concat_spec.rb | 15 + .../puppet/parser/functions/count_spec.rb | 31 + .../puppet/parser/functions/delete_at_spec.rb | 19 + .../puppet/parser/functions/delete_spec.rb | 38 + .../puppet/parser/functions/dirname_spec.rb | 24 + .../puppet/parser/functions/downcase_spec.rb | 24 + .../puppet/parser/functions/empty_spec.rb | 23 + .../puppet/parser/functions/flatten_spec.rb | 27 + .../puppet/parser/functions/floor_spec.rb | 39 + .../parser/functions/fqdn_rotate_spec.rb | 33 + .../parser/functions/get_module_path_spec.rb | 46 + .../puppet/parser/functions/getvar_spec.rb | 37 + .../unit/puppet/parser/functions/grep_spec.rb | 19 + .../functions/has_interface_with_spec.rb | 64 + .../parser/functions/has_ip_address_spec.rb | 39 + .../parser/functions/has_ip_network_spec.rb | 36 + .../puppet/parser/functions/has_key_spec.rb | 42 + .../unit/puppet/parser/functions/hash_spec.rb | 19 + .../puppet/parser/functions/is_array_spec.rb | 29 + .../parser/functions/is_domain_name_spec.rb | 64 + .../puppet/parser/functions/is_float_spec.rb | 33 + .../parser/functions/is_function_available.rb | 31 + .../puppet/parser/functions/is_hash_spec.rb | 29 + .../parser/functions/is_integer_spec.rb | 34 + .../parser/functions/is_ip_address_spec.rb | 39 + .../parser/functions/is_mac_address_spec.rb | 29 + .../parser/functions/is_numeric_spec.rb | 39 + .../puppet/parser/functions/is_string_spec.rb | 34 + .../functions/join_keys_to_values_spec.rb | 40 + .../unit/puppet/parser/functions/join_spec.rb | 19 + .../unit/puppet/parser/functions/keys_spec.rb | 21 + .../puppet/parser/functions/lstrip_spec.rb | 19 + .../unit/puppet/parser/functions/max_spec.rb | 27 + .../puppet/parser/functions/member_spec.rb | 24 + .../puppet/parser/functions/merge_spec.rb | 47 + .../unit/puppet/parser/functions/min_spec.rb | 27 + .../puppet/parser/functions/num2bool_spec.rb | 67 + .../puppet/parser/functions/parsejson_spec.rb | 22 + .../puppet/parser/functions/parseyaml_spec.rb | 24 + .../unit/puppet/parser/functions/pick_spec.rb | 34 + .../puppet/parser/functions/prefix_spec.rb | 19 + .../puppet/parser/functions/range_spec.rb | 34 + .../puppet/parser/functions/reject_spec.rb | 20 + .../puppet/parser/functions/reverse_spec.rb | 19 + .../puppet/parser/functions/rstrip_spec.rb | 24 + .../puppet/parser/functions/shuffle_spec.rb | 24 + .../unit/puppet/parser/functions/size_spec.rb | 24 + .../unit/puppet/parser/functions/sort_spec.rb | 24 + .../puppet/parser/functions/squeeze_spec.rb | 24 + .../puppet/parser/functions/str2bool_spec.rb | 31 + .../parser/functions/str2saltedsha512_spec.rb | 45 + .../puppet/parser/functions/strftime_spec.rb | 29 + .../puppet/parser/functions/strip_spec.rb | 18 + .../puppet/parser/functions/suffix_spec.rb | 19 + .../puppet/parser/functions/swapcase_spec.rb | 19 + .../unit/puppet/parser/functions/time_spec.rb | 29 + .../puppet/parser/functions/to_bytes_spec.rb | 58 + .../unit/puppet/parser/functions/type_spec.rb | 43 + .../puppet/parser/functions/unique_spec.rb | 24 + .../puppet/parser/functions/upcase_spec.rb | 24 + .../puppet/parser/functions/uriescape_spec.rb | 24 + .../functions/validate_absolute_path_spec.rb | 83 ++ .../parser/functions/validate_array_spec.rb | 38 + .../parser/functions/validate_augeas_spec.rb | 102 ++ .../parser/functions/validate_bool_spec.rb | 51 + .../parser/functions/validate_cmd_spec.rb | 81 ++ .../parser/functions/validate_hash_spec.rb | 43 + .../parser/functions/validate_re_spec.rb | 76 ++ .../parser/functions/validate_slength_spec.rb | 48 + .../parser/functions/validate_string_spec.rb | 60 + .../puppet/parser/functions/values_at_spec.rb | 38 + .../puppet/parser/functions/values_spec.rb | 31 + .../unit/puppet/parser/functions/zip_spec.rb | 15 + .../puppet/provider/file_line/ruby_spec.rb | 127 ++ .../spec/unit/puppet/type/anchor_spec.rb | 11 + .../spec/unit/puppet/type/file_line_spec.rb | 69 + deployment/modules/stdlib/spec/watchr.rb | 86 ++ deployment/modules/stdlib/tests/file_line.pp | 9 + .../stdlib/tests/has_interface_with.pp | 10 + .../modules/stdlib/tests/has_ip_address.pp | 3 + .../modules/stdlib/tests/has_ip_network.pp | 4 + deployment/modules/stdlib/tests/init.pp | 1 + deployment/site.pp | 66 + 501 files changed, 24934 insertions(+), 75 deletions(-) create mode 100644 deployment/modules/apache/CHANGELOG.md create mode 100644 deployment/modules/apache/Gemfile create mode 100644 deployment/modules/apache/Gemfile.lock create mode 100644 deployment/modules/apache/LICENSE create mode 100644 deployment/modules/apache/Modulefile create mode 100644 deployment/modules/apache/README.md create mode 100644 deployment/modules/apache/README.passenger.md create mode 100644 deployment/modules/apache/Rakefile create mode 100644 deployment/modules/apache/files/httpd create mode 100644 deployment/modules/apache/lib/puppet/provider/a2mod.rb create mode 100644 deployment/modules/apache/lib/puppet/provider/a2mod/a2mod.rb create mode 100644 deployment/modules/apache/lib/puppet/provider/a2mod/gentoo.rb create mode 100644 deployment/modules/apache/lib/puppet/provider/a2mod/modfix.rb create mode 100644 deployment/modules/apache/lib/puppet/provider/a2mod/redhat.rb create mode 100644 deployment/modules/apache/lib/puppet/type/a2mod.rb create mode 100644 deployment/modules/apache/manifests/balancer.pp create mode 100644 deployment/modules/apache/manifests/balancermember.pp create mode 100644 deployment/modules/apache/manifests/default_mods.pp create mode 100644 deployment/modules/apache/manifests/default_mods/load.pp create mode 100644 deployment/modules/apache/manifests/dev.pp create mode 100644 deployment/modules/apache/manifests/init.pp create mode 100644 deployment/modules/apache/manifests/listen.pp create mode 100644 deployment/modules/apache/manifests/mod.pp create mode 100644 deployment/modules/apache/manifests/mod/alias.pp create mode 100644 deployment/modules/apache/manifests/mod/auth_basic.pp create mode 100644 deployment/modules/apache/manifests/mod/auth_kerb.pp create mode 100644 deployment/modules/apache/manifests/mod/autoindex.pp create mode 100644 deployment/modules/apache/manifests/mod/cache.pp create mode 100644 deployment/modules/apache/manifests/mod/cgi.pp create mode 100644 deployment/modules/apache/manifests/mod/cgid.pp create mode 100644 deployment/modules/apache/manifests/mod/dav.pp create mode 100644 deployment/modules/apache/manifests/mod/dav_fs.pp create mode 100644 deployment/modules/apache/manifests/mod/dav_svn.pp create mode 100644 deployment/modules/apache/manifests/mod/deflate.pp create mode 100644 deployment/modules/apache/manifests/mod/dev.pp create mode 100644 deployment/modules/apache/manifests/mod/dir.pp create mode 100644 deployment/modules/apache/manifests/mod/disk_cache.pp create mode 100644 deployment/modules/apache/manifests/mod/fcgid.pp create mode 100644 deployment/modules/apache/manifests/mod/headers.pp create mode 100644 deployment/modules/apache/manifests/mod/info.pp create mode 100644 deployment/modules/apache/manifests/mod/itk.pp create mode 100644 deployment/modules/apache/manifests/mod/ldap.pp create mode 100644 deployment/modules/apache/manifests/mod/mime.pp create mode 100644 deployment/modules/apache/manifests/mod/mime_magic.pp create mode 100644 deployment/modules/apache/manifests/mod/mpm_event.pp create mode 100644 deployment/modules/apache/manifests/mod/negotiation.pp create mode 100644 deployment/modules/apache/manifests/mod/passenger.pp create mode 100644 deployment/modules/apache/manifests/mod/perl.pp create mode 100644 deployment/modules/apache/manifests/mod/php.pp create mode 100644 deployment/modules/apache/manifests/mod/prefork.pp create mode 100644 deployment/modules/apache/manifests/mod/proxy.pp create mode 100644 deployment/modules/apache/manifests/mod/proxy_balancer.pp create mode 100644 deployment/modules/apache/manifests/mod/proxy_html.pp create mode 100644 deployment/modules/apache/manifests/mod/proxy_http.pp create mode 100644 deployment/modules/apache/manifests/mod/python.pp create mode 100644 deployment/modules/apache/manifests/mod/reqtimeout.pp create mode 100644 deployment/modules/apache/manifests/mod/rewrite.pp create mode 100644 deployment/modules/apache/manifests/mod/setenvif.pp create mode 100644 deployment/modules/apache/manifests/mod/ssl.pp create mode 100644 deployment/modules/apache/manifests/mod/status.pp create mode 100644 deployment/modules/apache/manifests/mod/suphp.pp create mode 100644 deployment/modules/apache/manifests/mod/userdir.pp create mode 100644 deployment/modules/apache/manifests/mod/vhost_alias.pp create mode 100644 deployment/modules/apache/manifests/mod/worker.pp create mode 100644 deployment/modules/apache/manifests/mod/wsgi.pp create mode 100644 deployment/modules/apache/manifests/mod/xsendfile.pp create mode 100644 deployment/modules/apache/manifests/namevirtualhost.pp create mode 100644 deployment/modules/apache/manifests/params.pp create mode 100644 deployment/modules/apache/manifests/php.pp create mode 100644 deployment/modules/apache/manifests/proxy.pp create mode 100644 deployment/modules/apache/manifests/python.pp create mode 100644 deployment/modules/apache/manifests/service.pp create mode 100644 deployment/modules/apache/manifests/ssl.pp create mode 100644 deployment/modules/apache/manifests/vhost.pp create mode 100644 deployment/modules/apache/metadata.json create mode 100644 deployment/modules/apache/spec/classes/apache_spec.rb create mode 100644 deployment/modules/apache/spec/classes/dev_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/auth_kerb_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/dav_svn_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/dev_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/dir_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/fcgid_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/info_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/itk_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/passenger_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/perl_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/php_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/prefork_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/proxy_html_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/python_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/ssl_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/suphp_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/worker_spec.rb create mode 100644 deployment/modules/apache/spec/classes/mod/wsgi_spec.rb create mode 100644 deployment/modules/apache/spec/classes/params_spec.rb create mode 100644 deployment/modules/apache/spec/classes/service_spec.rb create mode 100644 deployment/modules/apache/spec/defines/mod_spec.rb create mode 100644 deployment/modules/apache/spec/defines/vhost_spec.rb create mode 100644 deployment/modules/apache/spec/fixtures/modules/site_apache/templates/fake.conf.erb create mode 100644 deployment/modules/apache/spec/spec.opts create mode 100644 deployment/modules/apache/spec/spec_helper.rb create mode 100644 deployment/modules/apache/spec/spec_helper_system.rb create mode 100644 deployment/modules/apache/spec/system/basic_spec.rb create mode 100644 deployment/modules/apache/spec/system/class_spec.rb create mode 100644 deployment/modules/apache/spec/system/default_mods_spec.rb create mode 100644 deployment/modules/apache/spec/system/itk_spec.rb create mode 100644 deployment/modules/apache/spec/system/mod_php_spec.rb create mode 100644 deployment/modules/apache/spec/system/mod_suphp_spec.rb create mode 100644 deployment/modules/apache/spec/system/prefork_worker_spec.rb create mode 100644 deployment/modules/apache/spec/system/service_spec.rb create mode 100644 deployment/modules/apache/spec/system/vhost_spec.rb create mode 100644 deployment/modules/apache/spec/unit/provider/a2mod/gentoo_spec.rb create mode 100644 deployment/modules/apache/templates/httpd.conf.erb create mode 100644 deployment/modules/apache/templates/listen.erb create mode 100644 deployment/modules/apache/templates/mod/alias.conf.erb create mode 100644 deployment/modules/apache/templates/mod/autoindex.conf.erb create mode 100644 deployment/modules/apache/templates/mod/cgid.conf.erb create mode 100644 deployment/modules/apache/templates/mod/dav_fs.conf.erb create mode 100644 deployment/modules/apache/templates/mod/deflate.conf.erb create mode 100644 deployment/modules/apache/templates/mod/dir.conf.erb create mode 100644 deployment/modules/apache/templates/mod/disk_cache.conf.erb create mode 100644 deployment/modules/apache/templates/mod/info.conf.erb create mode 100644 deployment/modules/apache/templates/mod/itk.conf.erb create mode 100644 deployment/modules/apache/templates/mod/ldap.conf.erb create mode 100644 deployment/modules/apache/templates/mod/mime.conf.erb create mode 100644 deployment/modules/apache/templates/mod/mime_magic.conf.erb create mode 100644 deployment/modules/apache/templates/mod/mpm_event.conf.erb create mode 100644 deployment/modules/apache/templates/mod/negotiation.conf.erb create mode 100644 deployment/modules/apache/templates/mod/passenger.conf.erb create mode 100644 deployment/modules/apache/templates/mod/php5.conf.erb create mode 100644 deployment/modules/apache/templates/mod/prefork.conf.erb create mode 100644 deployment/modules/apache/templates/mod/proxy.conf.erb create mode 100644 deployment/modules/apache/templates/mod/proxy_html.conf.erb create mode 100644 deployment/modules/apache/templates/mod/reqtimeout.conf.erb create mode 100644 deployment/modules/apache/templates/mod/setenvif.conf.erb create mode 100644 deployment/modules/apache/templates/mod/ssl.conf.erb create mode 100644 deployment/modules/apache/templates/mod/status.conf.erb create mode 100644 deployment/modules/apache/templates/mod/suphp.conf.erb create mode 100644 deployment/modules/apache/templates/mod/userdir.conf.erb create mode 100644 deployment/modules/apache/templates/mod/worker.conf.erb create mode 100644 deployment/modules/apache/templates/mod/wsgi.conf.erb create mode 100644 deployment/modules/apache/templates/namevirtualhost.erb create mode 100644 deployment/modules/apache/templates/ports_header.erb create mode 100644 deployment/modules/apache/templates/vhost.conf.erb create mode 100644 deployment/modules/apache/templates/vhost/_aliases.erb create mode 100644 deployment/modules/apache/templates/vhost/_block.erb create mode 100644 deployment/modules/apache/templates/vhost/_custom_fragment.erb create mode 100644 deployment/modules/apache/templates/vhost/_directories.erb create mode 100644 deployment/modules/apache/templates/vhost/_itk.erb create mode 100644 deployment/modules/apache/templates/vhost/_proxy.erb create mode 100644 deployment/modules/apache/templates/vhost/_rack.erb create mode 100644 deployment/modules/apache/templates/vhost/_redirect.erb create mode 100644 deployment/modules/apache/templates/vhost/_requestheader.erb create mode 100644 deployment/modules/apache/templates/vhost/_rewrite.erb create mode 100644 deployment/modules/apache/templates/vhost/_scriptalias.erb create mode 100644 deployment/modules/apache/templates/vhost/_serveralias.erb create mode 100644 deployment/modules/apache/templates/vhost/_setenv.erb create mode 100644 deployment/modules/apache/templates/vhost/_ssl.erb create mode 100644 deployment/modules/apache/templates/vhost/_suphp.erb create mode 100644 deployment/modules/apache/templates/vhost/_wsgi.erb create mode 100644 deployment/modules/apache/tests/apache.pp create mode 100644 deployment/modules/apache/tests/dev.pp create mode 100644 deployment/modules/apache/tests/init.pp create mode 100644 deployment/modules/apache/tests/mods.pp create mode 100644 deployment/modules/apache/tests/mods_custom.pp create mode 100644 deployment/modules/apache/tests/php.pp create mode 100644 deployment/modules/apache/tests/vhost.pp create mode 100644 deployment/modules/apache/tests/vhost_directories.pp create mode 100644 deployment/modules/apache/tests/vhost_ip_based.pp create mode 100644 deployment/modules/apache/tests/vhost_ssl.pp create mode 100644 deployment/modules/apache/tests/vhosts_without_listen.pp create mode 100644 deployment/modules/apt/manifests/init.pp create mode 100644 deployment/modules/concat/CHANGELOG create mode 100644 deployment/modules/concat/Gemfile create mode 100644 deployment/modules/concat/LICENSE create mode 100644 deployment/modules/concat/Modulefile create mode 100644 deployment/modules/concat/README create mode 100644 deployment/modules/concat/README.markdown create mode 100644 deployment/modules/concat/Rakefile create mode 100755 deployment/modules/concat/files/concatfragments.sh create mode 100644 deployment/modules/concat/lib/facter/concat_basedir.rb create mode 100644 deployment/modules/concat/manifests/fragment.pp create mode 100644 deployment/modules/concat/manifests/init.pp create mode 100644 deployment/modules/concat/manifests/setup.pp create mode 100644 deployment/modules/concat/metadata.json create mode 100644 deployment/modules/concat/spec/defines/init_spec.rb create mode 100644 deployment/modules/concat/spec/fixtures/manifests/site.pp create mode 100644 deployment/modules/concat/spec/spec_helper.rb create mode 100644 deployment/modules/concat/spec/spec_helper_system.rb create mode 100644 deployment/modules/concat/spec/system/basic_spec.rb create mode 100644 deployment/modules/concat/spec/system/concat_spec.rb create mode 100644 deployment/modules/concat/spec/system/empty_spec.rb create mode 100644 deployment/modules/concat/spec/system/replace_spec.rb create mode 100644 deployment/modules/concat/spec/system/warn_spec.rb create mode 100644 deployment/modules/evap/files/localsettings.py create mode 100644 deployment/modules/evap/manifests/init.pp create mode 100644 deployment/modules/mysql/CHANGELOG create mode 100644 deployment/modules/mysql/Gemfile create mode 100644 deployment/modules/mysql/Gemfile.lock create mode 100644 deployment/modules/mysql/LICENSE create mode 100644 deployment/modules/mysql/Modulefile create mode 100644 deployment/modules/mysql/README.md create mode 100644 deployment/modules/mysql/Rakefile create mode 100644 deployment/modules/mysql/TODO create mode 100644 deployment/modules/mysql/files/mysqltuner.pl create mode 100644 deployment/modules/mysql/lib/puppet/parser/functions/mysql_deepmerge.rb create mode 100644 deployment/modules/mysql/lib/puppet/parser/functions/mysql_password.rb create mode 100644 deployment/modules/mysql/lib/puppet/parser/functions/mysql_strip_hash.rb create mode 100644 deployment/modules/mysql/lib/puppet/provider/database/mysql.rb create mode 100644 deployment/modules/mysql/lib/puppet/provider/database_grant/mysql.rb create mode 100644 deployment/modules/mysql/lib/puppet/provider/database_user/mysql.rb create mode 100644 deployment/modules/mysql/lib/puppet/provider/mysql.rb create mode 100644 deployment/modules/mysql/lib/puppet/provider/mysql_database/mysql.rb create mode 100644 deployment/modules/mysql/lib/puppet/provider/mysql_grant/mysql.rb create mode 100644 deployment/modules/mysql/lib/puppet/provider/mysql_user/mysql.rb create mode 100644 deployment/modules/mysql/lib/puppet/type/database.rb create mode 100644 deployment/modules/mysql/lib/puppet/type/database_grant.rb create mode 100644 deployment/modules/mysql/lib/puppet/type/database_user.rb create mode 100644 deployment/modules/mysql/lib/puppet/type/mysql_database.rb create mode 100644 deployment/modules/mysql/lib/puppet/type/mysql_grant.rb create mode 100644 deployment/modules/mysql/lib/puppet/type/mysql_user.rb create mode 100644 deployment/modules/mysql/manifests/backup.pp create mode 100644 deployment/modules/mysql/manifests/bindings.pp create mode 100644 deployment/modules/mysql/manifests/bindings/java.pp create mode 100644 deployment/modules/mysql/manifests/bindings/perl.pp create mode 100644 deployment/modules/mysql/manifests/bindings/php.pp create mode 100644 deployment/modules/mysql/manifests/bindings/python.pp create mode 100644 deployment/modules/mysql/manifests/bindings/ruby.pp create mode 100644 deployment/modules/mysql/manifests/client.pp create mode 100644 deployment/modules/mysql/manifests/client/install.pp create mode 100644 deployment/modules/mysql/manifests/db.pp create mode 100644 deployment/modules/mysql/manifests/init.pp create mode 100644 deployment/modules/mysql/manifests/params.pp create mode 100644 deployment/modules/mysql/manifests/server.pp create mode 100644 deployment/modules/mysql/manifests/server/account_security.pp create mode 100644 deployment/modules/mysql/manifests/server/backup.pp create mode 100644 deployment/modules/mysql/manifests/server/config.pp create mode 100644 deployment/modules/mysql/manifests/server/install.pp create mode 100644 deployment/modules/mysql/manifests/server/monitor.pp create mode 100644 deployment/modules/mysql/manifests/server/mysqltuner.pp create mode 100644 deployment/modules/mysql/manifests/server/providers.pp create mode 100644 deployment/modules/mysql/manifests/server/root_password.pp create mode 100644 deployment/modules/mysql/manifests/server/service.pp create mode 100644 deployment/modules/mysql/metadata.json create mode 100644 deployment/modules/mysql/spec/classes/mysql_bindings_spec.rb create mode 100644 deployment/modules/mysql/spec/classes/mysql_client_spec.rb create mode 100644 deployment/modules/mysql/spec/classes/mysql_server_account_security_spec.rb create mode 100644 deployment/modules/mysql/spec/classes/mysql_server_backup_spec.rb create mode 100644 deployment/modules/mysql/spec/classes/mysql_server_monitor_spec.rb create mode 100644 deployment/modules/mysql/spec/classes/mysql_server_mysqltuner_spec.rb create mode 100644 deployment/modules/mysql/spec/classes/mysql_server_spec.rb create mode 100644 deployment/modules/mysql/spec/defines/mysql_db_spec.rb create mode 100644 deployment/modules/mysql/spec/spec.opts create mode 100644 deployment/modules/mysql/spec/spec_helper.rb create mode 100644 deployment/modules/mysql/spec/spec_helper_system.rb create mode 100644 deployment/modules/mysql/spec/system/mysql_account_delete_spec.rb create mode 100644 deployment/modules/mysql/spec/system/mysql_backup_spec.rb create mode 100644 deployment/modules/mysql/spec/system/mysql_bindings_spec.rb create mode 100644 deployment/modules/mysql/spec/system/mysql_db_spec.rb create mode 100644 deployment/modules/mysql/spec/system/mysql_server_monitor_spec.rb create mode 100644 deployment/modules/mysql/spec/system/mysql_server_root_password_spec.rb create mode 100644 deployment/modules/mysql/spec/system/mysql_server_spec.rb create mode 100644 deployment/modules/mysql/spec/system/types/mysql_grant_spec.rb create mode 100644 deployment/modules/mysql/spec/system/types/mysql_user_spec.rb create mode 100644 deployment/modules/mysql/spec/unit/mysql_password_spec.rb create mode 100644 deployment/modules/mysql/spec/unit/puppet/functions/mysql_deepmerge_spec.rb create mode 100644 deployment/modules/mysql/spec/unit/puppet/provider/database/mysql_spec.rb create mode 100644 deployment/modules/mysql/spec/unit/puppet/provider/database_grant/mysql_spec.rb create mode 100644 deployment/modules/mysql/spec/unit/puppet/provider/database_user/mysql_spec.rb create mode 100644 deployment/modules/mysql/spec/unit/puppet/provider/mysql_database/mysql_spec.rb create mode 100644 deployment/modules/mysql/spec/unit/puppet/provider/mysql_user/mysql_spec.rb create mode 100644 deployment/modules/mysql/spec/unit/puppet/type/mysql_database_spec.rb create mode 100644 deployment/modules/mysql/spec/unit/puppet/type/mysql_user_spec.rb create mode 100644 deployment/modules/mysql/templates/my.cnf.erb create mode 100644 deployment/modules/mysql/templates/my.cnf.pass.erb create mode 100644 deployment/modules/mysql/templates/my.conf.cnf.erb create mode 100644 deployment/modules/mysql/templates/mysqlbackup.sh.erb create mode 100644 deployment/modules/mysql/tests/backup.pp create mode 100644 deployment/modules/mysql/tests/bindings.pp create mode 100644 deployment/modules/mysql/tests/init.pp create mode 100644 deployment/modules/mysql/tests/java.pp create mode 100644 deployment/modules/mysql/tests/mysql_database.pp create mode 100644 deployment/modules/mysql/tests/mysql_grant.pp create mode 100644 deployment/modules/mysql/tests/mysql_user.pp create mode 100644 deployment/modules/mysql/tests/perl.pp create mode 100644 deployment/modules/mysql/tests/python.pp create mode 100644 deployment/modules/mysql/tests/ruby.pp create mode 100644 deployment/modules/mysql/tests/server.pp create mode 100644 deployment/modules/mysql/tests/server/account_security.pp create mode 100644 deployment/modules/mysql/tests/server/config.pp create mode 100755 deployment/modules/sshd/files/sshd_config create mode 100755 deployment/modules/sshd/manifests/init.pp create mode 100644 deployment/modules/stdlib/CHANGELOG create mode 100644 deployment/modules/stdlib/CONTRIBUTING.md create mode 100644 deployment/modules/stdlib/Gemfile create mode 100644 deployment/modules/stdlib/LICENSE create mode 100644 deployment/modules/stdlib/Modulefile create mode 100644 deployment/modules/stdlib/README.markdown create mode 100644 deployment/modules/stdlib/README_DEVELOPER.markdown create mode 100644 deployment/modules/stdlib/README_SPECS.markdown create mode 100644 deployment/modules/stdlib/RELEASE_PROCESS.markdown create mode 100644 deployment/modules/stdlib/Rakefile create mode 100644 deployment/modules/stdlib/lib/facter/facter_dot_d.rb create mode 100644 deployment/modules/stdlib/lib/facter/pe_version.rb create mode 100644 deployment/modules/stdlib/lib/facter/puppet_vardir.rb create mode 100644 deployment/modules/stdlib/lib/facter/root_home.rb create mode 100644 deployment/modules/stdlib/lib/facter/util/puppet_settings.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/abs.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/any2array.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/bool2num.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/capitalize.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/chomp.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/chop.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/concat.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/count.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/delete.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/delete_at.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/dirname.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/downcase.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/empty.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/flatten.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/floor.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/getparam.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/getvar.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/grep.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/has_key.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/hash.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/is_array.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/is_float.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/is_function_available.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/is_hash.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/is_integer.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/is_string.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/join.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/keys.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/lstrip.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/max.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/member.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/merge.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/min.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/num2bool.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/parsejson.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/pick.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/prefix.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/range.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/reject.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/reverse.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/rstrip.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/shuffle.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/size.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/sort.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/squeeze.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/str2bool.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/strftime.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/strip.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/suffix.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/swapcase.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/time.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/type.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/unique.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/upcase.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/uriescape.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/validate_array.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/validate_cmd.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/validate_re.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/validate_string.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/values.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/values_at.rb create mode 100644 deployment/modules/stdlib/lib/puppet/parser/functions/zip.rb create mode 100644 deployment/modules/stdlib/lib/puppet/provider/file_line/ruby.rb create mode 100644 deployment/modules/stdlib/lib/puppet/type/anchor.rb create mode 100644 deployment/modules/stdlib/lib/puppet/type/file_line.rb create mode 100644 deployment/modules/stdlib/manifests/init.pp create mode 100644 deployment/modules/stdlib/manifests/stages.pp create mode 100644 deployment/modules/stdlib/metadata.json create mode 100644 deployment/modules/stdlib/spec/classes/anchor_spec.rb create mode 100644 deployment/modules/stdlib/spec/fixtures/manifests/site.pp create mode 100644 deployment/modules/stdlib/spec/functions/defined_with_params_spec.rb create mode 100644 deployment/modules/stdlib/spec/functions/ensure_packages_spec.rb create mode 100644 deployment/modules/stdlib/spec/functions/ensure_resource_spec.rb create mode 100644 deployment/modules/stdlib/spec/functions/getparam_spec.rb create mode 100755 deployment/modules/stdlib/spec/monkey_patches/alias_should_to_must.rb create mode 100755 deployment/modules/stdlib/spec/monkey_patches/publicize_methods.rb create mode 100644 deployment/modules/stdlib/spec/spec.opts create mode 100644 deployment/modules/stdlib/spec/spec_helper.rb create mode 100644 deployment/modules/stdlib/spec/unit/facter/pe_required_facts_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/facter/pe_version_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/facter/root_home_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/count_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb create mode 100755 deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb create mode 100644 deployment/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb create mode 100644 deployment/modules/stdlib/spec/watchr.rb create mode 100644 deployment/modules/stdlib/tests/file_line.pp create mode 100644 deployment/modules/stdlib/tests/has_interface_with.pp create mode 100644 deployment/modules/stdlib/tests/has_ip_address.pp create mode 100644 deployment/modules/stdlib/tests/has_ip_network.pp create mode 100644 deployment/modules/stdlib/tests/init.pp create mode 100755 deployment/site.pp diff --git a/Vagrantfile b/Vagrantfile index 06c829a3a..9f1c9dc5c 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -3,87 +3,25 @@ Vagrant.configure("2") do |config| # Base box to build off, and download URL for when it doesn't exist on the user's system already - config.vm.box = "precise32" - config.vm.box_url = "http://files.vagrantup.com/precise32.box" + config.vm.box = "precise64" # Create a forwarded port mapping which allows access to a specific port # within the machine from a port on the host machine. - config.vm.network :forwarded_port, guest: 8000, host: 8000 + config.vm.network :forwarded_port, guest: 80, host: 8000 - # Create a private network, which allows host-only access to the machine - # using a specific IP. - # config.vm.network :private_network, ip: "192.168.33.10" - - # Create a public network, which generally matched to bridged network. - # Bridged networks make the machine appear as another physical device on - # your network. - # config.vm.network :public_network + config.vm.provider :virtualbox do |vb, override| + vb.customize ["modifyvm", :id, "--memory", "1024"] - # Share an additional folder to the guest VM. The first argument is - # the path on the host to the actual folder. The second argument is - # the path on the guest to mount the folder. And the optional third - # argument is a set of non-required options. - #config.vm.synced_folder ".", "~/evap", { + override.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210.box" + end - # Provider-specific configuration so you can fine-tune various - # backing providers for Vagrant. These expose provider-specific options. - # Example for VirtualBox: - # - config.vm.provider :virtualbox do |vb| - # # Don't boot with headless mode - # vb.gui = true - # - # Use VBoxManage to customize the VM. For example to change memory: - vb.customize ["modifyvm", :id, "--memory", "1024"] + config.vm.provider :lxc do |v, override| + override.vm.box_url = "http://bit.ly/vagrant-lxc-precise64-2013-10-23" end - # - # View the documentation for the provider you're using for more - # information on available options. - - # Enable provisioning with Puppet stand alone. Puppet manifests - # are contained in a directory path relative to this Vagrantfile. - # You will need to create the manifests directory and a manifest in - # the file base.pp in the manifests_path directory. - # - # An example Puppet manifest to provision the message of the day: - # - # # group { "puppet": - # # ensure => "present", - # # } - # # - # # File { owner => 0, group => 0, mode => 0644 } - # # - # # file { '/etc/motd': - # # content => "Welcome to your Vagrant-built virtual machine! - # # Managed by Puppet.\n" - # # } - # - # config.vm.provision :puppet do |puppet| - # puppet.manifests_path = "manifests" - # puppet.manifest_file = "init.pp" - # end - - config.vm.provision :shell, :inline => "gem install chef --version 11.4.2 --no-rdoc --no-ri --conservative" - - # Enable provisioning with chef solo, specifying a cookbooks path, roles - # path, and data_bags path (all relative to this Vagrantfile), and adding - # some recipes and/or roles. - # - config.vm.provision :chef_solo do |chef| - chef.cookbooks_path = "cookbooks" - chef.add_recipe "apt" - chef.add_recipe "apache2::mod_wsgi" - chef.add_recipe "build-essential" - #chef.add_recipe "git" # doesn't work so far, maybe here's the solution: https://github.com/opscode-cookbooks/git/pull/16 - chef.add_recipe "python" - chef.add_recipe "vim" - # - # # You may also specify custom JSON attributes: - # chef.json = { :mysql_password => "foo" } + + config.vm.provision :puppet do |puppet| + puppet.module_path = "deployment/modules" + puppet.manifests_path = "deployment" + puppet.manifest_file = "site.pp" end - - - config.vm.provision :shell, :inline => "apt-get install -y libxml2-dev libxslt-dev" - config.vm.provision :shell, :inline => "pip install -r /vagrant/requirements.txt" - #config.vm.provision :shell, :inline => "ls" end diff --git a/deployment/modules/apache/CHANGELOG.md b/deployment/modules/apache/CHANGELOG.md new file mode 100644 index 000000000..c4686ab21 --- /dev/null +++ b/deployment/modules/apache/CHANGELOG.md @@ -0,0 +1,133 @@ +## 2013-09-06 Release 0.9.0 +### Summary: +This release adds more parameters to the base apache class and apache defined +resource to make the module more flexible. It also adds or enhances SuPHP, +WSGI, and Passenger mod support, and support for the ITK mpm module. + +### Backwards-incompatible Changes: +- Remove many default mods that are not normally needed. +- Remove `rewrite_base` `apache::vhost` parameter; did not work anyway. +- Specify dependencies on stdlib >=2.4.0 (this was already the case, but +making explicit) +- Deprecate `a2mod` in favor of the `apache::mod::*` classes and `apache::mod` +defined resource. + +### Features: +- `apache` class + - Add `httpd_dir` parameter to change the location of the configuration + files. + - Add `logroot` parameter to change the logroot + - Add `ports_file` parameter to changes the `ports.conf` file location + - Add `keepalive` parameter to enable persistent connections + - Add `keepalive_timeout` parameter to change the timeout + - Update `default_mods` to be able to take an array of mods to enable. +- `apache::vhost` + - Add `wsgi_daemon_process`, `wsgi_daemon_process_options`, + `wsgi_process_group`, and `wsgi_script_aliases` parameters for per-vhost + WSGI configuration. + - Add `access_log_syslog` parameter to enable syslogging. + - Add `error_log_syslog` parameter to enable syslogging of errors. + - Add `directories` hash parameter. Please see README for documentation. + - Add `sslproxyengine` parameter to enable SSLProxyEngine + - Add `suphp_addhandler`, `suphp_engine`, and `suphp_configpath` for + configuring SuPHP. + - Add `custom_fragment` parameter to allow for arbitrary apache + configuration injection. (Feature pull requests are prefered over using + this, but it is available in a pinch.) +- Add `apache::mod::suphp` class for configuring SuPHP. +- Add `apache::mod::itk` class for configuring ITK mpm module. +- Update `apache::mod::wsgi` class for global WSGI configuration with +`wsgi_socket_prefix` and `wsgi_python_home` parameters. +- Add README.passenger.md to document the `apache::mod::passenger` usage. +Added `passenger_high_performance`, `passenger_pool_idle_time`, +`passenger_max_requests`, `passenger_stat_throttle_rate`, `rack_autodetect`, +and `rails_autodetect` parameters. +- Separate the httpd service resource into a new `apache::service` class for +dependency chaining of `Class['apache'] -> ~> +Class['apache::service']` +- Added `apache::mod::proxy_balancer` class for `apache::balancer` + +### Bugfixes: +- Change dependency to puppetlabs-concat +- Fix ruby 1.9 bug for `a2mod` +- Change servername to be `$::hostname` if there is no `$::fqdn` +- Make `/etc/ssl/certs` the default ssl certs directory for RedHat non-5. +- Make `php` the default php package for RedHat non-5. +- Made `aliases` able to take a single alias hash instead of requiring an +array. + +## 2013-07-26 Release 0.8.1 +### Bugfixes: +- Update `apache::mpm_module` detection for worker/prefork +- Update `apache::mod::cgi` and `apache::mod::cgid` detection for +worker/prefork + +## 2013-07-16 Release 0.8.0 +### Features: +- Add `servername` parameter to `apache` class +- Add `proxy_set` parameter to `apache::balancer` define + +### Bugfixes: +- Fix ordering for multiple `apache::balancer` clusters +- Fix symlinking for sites-available on Debian-based OSs +- Fix dependency ordering for recursive confdir management +- Fix `apache::mod::*` to notify the service on config change +- Documentation updates + +## 2013-07-09 Release 0.7.0 +### Changes: +- Essentially rewrite the module -- too many to list +- `apache::vhost` has many abilities -- see README.md for details +- `apache::mod::*` classes provide httpd mod-loading capabilities +- `apache` base class is much more configurable + +### Bugfixes: +- Many. And many more to come + +## 2013-03-2 Release 0.6.0 +- update travis tests (add more supported versions) +- add access log_parameter +- make purging of vhost dir configurable + +## 2012-08-24 Release 0.4.0 +### Changes: +- `include apache` is now required when using `apache::mod::*` + +### Bugfixes: +- Fix syntax for validate_re +- Fix formatting in vhost template +- Fix spec tests such that they pass + + 2012-05-08 Puppet Labs - 0.0.4 + e62e362 Fix broken tests for ssl, vhost, vhost::* + 42c6363 Changes to match style guide and pass puppet-lint without error + 42bc8ba changed name => path for file resources in order to name namevar by it's name + 72e13de One end too much + 0739641 style guide fixes: 'true' <> true, $operatingsystem needs to be $::operatingsystem, etc. + 273f94d fix tests + a35ede5 (#13860) Make a2enmod/a2dismo commands optional + 98d774e (#13860) Autorequire Package['httpd'] + 05fcec5 (#13073) Add missing puppet spec tests + 541afda (#6899) Remove virtual a2mod definition + 976cb69 (#13072) Move mod python and wsgi package names to params + 323915a (#13060) Add .gitignore to repo + fdf40af (#13060) Remove pkg directory from source tree + fd90015 Add LICENSE file and update the ModuleFile + d3d0d23 Re-enable local php class + d7516c7 Make management of firewalls configurable for vhosts + 60f83ba Explicitly lookup scope of apache_name in templates. + f4d287f (#12581) Add explicit ordering for vdir directory + 88a2ac6 (#11706) puppetlabs-apache depends on puppetlabs-firewall + a776a8b (#11071) Fix to work with latest firewall module + 2b79e8b (#11070) Add support for Scientific Linux + 405b3e9 Fix for a2mod + 57b9048 Commit apache::vhost::redirect Manifest + 8862d01 Commit apache::vhost::proxy Manifest + d5c1fd0 Commit apache::mod::wsgi Manifest + a825ac7 Commit apache::mod::python Manifest + b77062f Commit Templates + 9a51b4a Vhost File Declarations + 6cf7312 Defaults for Parameters + 6a5b11a Ensure installed + f672e46 a2mod fix + 8a56ee9 add pthon support to apache diff --git a/deployment/modules/apache/Gemfile b/deployment/modules/apache/Gemfile new file mode 100644 index 000000000..7c8ea9e2c --- /dev/null +++ b/deployment/modules/apache/Gemfile @@ -0,0 +1,26 @@ +source 'https://rubygems.org' + +group :development, :test do + gem 'rake', :require => false + gem 'rspec-puppet', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'serverspec', :require => false + gem 'rspec-system', :require => false + gem 'rspec-system-puppet', :require => false + gem 'rspec-system-serverspec', :require => false + gem 'puppet-lint', :require => false +end + +if facterversion = ENV['FACTER_GEM_VERSION'] + gem 'facter', facterversion, :require => false +else + gem 'facter', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/deployment/modules/apache/Gemfile.lock b/deployment/modules/apache/Gemfile.lock new file mode 100644 index 000000000..9ca14cf88 --- /dev/null +++ b/deployment/modules/apache/Gemfile.lock @@ -0,0 +1,78 @@ +GEM + remote: https://rubygems.org/ + specs: + builder (3.2.2) + diff-lcs (1.2.4) + facter (1.7.2) + hiera (1.2.1) + json_pure + highline (1.6.19) + json_pure (1.8.0) + kwalify (0.7.2) + metaclass (0.0.1) + mocha (0.14.0) + metaclass (~> 0.0.1) + net-scp (1.1.2) + net-ssh (>= 2.6.5) + net-ssh (2.6.8) + nokogiri (1.5.10) + puppet (3.2.4) + facter (~> 1.6) + hiera (~> 1.0) + rgen (~> 0.6.5) + puppet-lint (0.3.2) + puppetlabs_spec_helper (0.4.1) + mocha (>= 0.10.5) + rake + rspec (>= 2.9.0) + rspec-puppet (>= 0.1.1) + rake (10.1.0) + rbvmomi (1.6.0) + builder + nokogiri (>= 1.4.1) + trollop + rgen (0.6.6) + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.5) + rspec-expectations (2.14.2) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.3) + rspec-puppet (0.1.6) + rspec + rspec-system (2.2.0) + kwalify (~> 0.7.2) + net-scp (~> 1.1) + net-ssh (~> 2.6) + nokogiri (~> 1.5.9) + rbvmomi (~> 1.6) + rspec (~> 2.13) + systemu (~> 2.5) + rspec-system-puppet (2.2.0) + rspec-system (~> 2.0) + rspec-system-serverspec (1.0.0) + rspec-system (~> 2.0) + serverspec (~> 0.6.0) + serverspec (0.6.3) + highline + net-ssh + rspec (~> 2.0) + systemu (2.5.2) + trollop (2.0) + +PLATFORMS + ruby + +DEPENDENCIES + facter + puppet (~> 3.0) + puppet-lint + puppetlabs_spec_helper + rake + rspec-puppet + rspec-system + rspec-system-puppet + rspec-system-serverspec + serverspec diff --git a/deployment/modules/apache/LICENSE b/deployment/modules/apache/LICENSE new file mode 100644 index 000000000..8961ce8a6 --- /dev/null +++ b/deployment/modules/apache/LICENSE @@ -0,0 +1,15 @@ +Copyright (C) 2012 Puppet Labs Inc + +Puppet Labs can be contacted at: info@puppetlabs.com + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/deployment/modules/apache/Modulefile b/deployment/modules/apache/Modulefile new file mode 100644 index 000000000..800ccf550 --- /dev/null +++ b/deployment/modules/apache/Modulefile @@ -0,0 +1,12 @@ +name 'puppetlabs-apache' +version '0.9.0' +source 'git://github.com/puppetlabs/puppetlabs-apache.git' +author 'puppetlabs' +license 'Apache 2.0' +summary 'Puppet module for Apache' +description 'Module for Apache configuration' +project_page 'https://github.com/puppetlabs/puppetlabs-apache' + +## Add dependencies, if any: +dependency 'puppetlabs/stdlib', '>= 2.4.0' +dependency 'puppetlabs/concat', '>= 1.0.0' diff --git a/deployment/modules/apache/README.md b/deployment/modules/apache/README.md new file mode 100644 index 000000000..1e949d10c --- /dev/null +++ b/deployment/modules/apache/README.md @@ -0,0 +1,1168 @@ +#apache + +[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-apache.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-apache) + +####Table of Contents + +1. [Overview - What is the Apache module?](#overview) +2. [Module Description - What does the module do?](#module-description) +3. [Setup - The basics of getting started with Apache](#setup) + * [Beginning with Apache - Installation](#beginning-with-apache) + * [Configure a Virtual Host - Basic options for getting started](#configure-a-virtual-host) +4. [Usage - The classes, defined types, and their parameters available for configuration](#usage) + * [Classes and Defined Types](#classes-and-defined-types) + * [Class: apache](#class-apache) + * [Classes: apache::mod::*](#classes-apachemodname) + * [Defined Type: apache::vhost](#defined-type-apachevhost) + * [Virtual Host Examples - Demonstrations of some configuration options](#virtual-host-examples) +5. [Implementation - An under-the-hood peek at what the module is doing](#implementation) + * [Classes and Defined Types](#classes-and-defined-types) + * [Templates](#templates) +6. [Limitations - OS compatibility, etc.](#limitations) +7. [Development - Guide for contributing to the module](#development) +8. [Release Notes - Notes on the most recent updates to the module](#release-notes) + +##Overview + +The Apache module allows you to set up virtual hosts and manage web services with minimal effort. + +##Module Description + +Apache is a widely-used web server, and this module provides a simplified way of creating configurations to manage your infrastructure. This includes the ability to configure and manage a range of different virtual host setups, as well as a streamlined way to install and configure Apache modules. + +##Setup + +**What Apache affects:** + +* configuration files and directories (created and written to) + * **NOTE**: Configurations that are *not* managed by Puppet will be purged. +* package/service/configuration files for Apache +* Apache modules +* virtual hosts +* listened-to ports + +###Beginning with Apache + +To install Apache with the default parameters + +```puppet + class { 'apache': } +``` + +The defaults are determined by your operating system (e.g. Debian systems have one set of defaults, RedHat systems have another). These defaults will work well in a testing environment, but are not suggested for production. To establish customized parameters + +```puppet + class { 'apache': + default_mods => false, + } +``` + +###Configure a virtual host + +Declaring the `apache` class will create a default virtual host by setting up a vhost on port 80, listening on all interfaces and serving `$apache::docroot`. + +```puppet + class { 'apache': } +``` + +To configure a very basic, name-based virtual host + +```puppet + apache::vhost { 'first.example.com': + port => '80', + docroot => '/var/www/first', + } +``` + +*Note:* The default priority is 15. If nothing matches this priority, the alphabetically first name-based vhost will be used. This is also true if you pass a higher priority and no names match anything else. + +A slightly more complicated example, which moves the docroot owner/group + +```puppet + apache::vhost { 'second.example.com': + port => '80', + docroot => '/var/www/second', + docroot_owner => 'third', + docroot_group => 'third', + } +``` + +To set up a virtual host with SSL and default SSL certificates + +```puppet + apache::vhost { 'ssl.example.com': + port => '443', + docroot => '/var/www/ssl', + ssl => true, + } +``` + +To set up a virtual host with SSL and specific SSL certificates + +```puppet + apache::vhost { 'fourth.example.com': + port => '443', + docroot => '/var/www/fourth', + ssl => true, + ssl_cert => '/etc/ssl/fourth.example.com.cert', + ssl_key => '/etc/ssl/fourth.example.com.key', + } +``` + +To set up a virtual host with wildcard alias for subdomain mapped to same named directory +`http://examle.com.loc => /var/www/example.com` + +```puppet + apache::vhost { 'subdomain.loc': + vhost_name => '*', + port => '80', + virtual_docroot' => '/var/www/%-2+', + docroot => '/var/www', + serveraliases => ['*.loc',], + } +``` + +To set up a virtual host with suPHP + +```puppet + apache::vhost { 'suphp.example.com': + port => '80', + docroot => '/home/appuser/myphpapp', + suphp_addhandler => 'x-httpd-php', + suphp_engine => 'on', + suphp_configpath => '/etc/php5/apache2', + } +``` + +To set up a virtual host with WSGI + +```puppet + apache::vhost { 'wsgi.example.com': + port => '80', + docroot => '/var/www/pythonapp', + wsgi_daemon_process => 'wsgi', + wsgi_daemon_process_options => + { processes => '2', threads => '15', display-name => '%{GROUP}' }, + wsgi_process_group => 'wsgi', + wsgi_script_aliases => { '/' => '/var/www/demo.wsgi' }, + } +``` + +To see a list of all virtual host parameters, [please go here](#defined-type-apachevhost). To see an extensive list of virtual host examples [please look here](#virtual-host-examples). + +##Usage + +###Classes and Defined Types + +This module modifies Apache configuration files and directories and will purge any configuration not managed by Puppet. Configuration of Apache should be managed by Puppet, as non-puppet configuration files can cause unexpected failures. + +It is possible to temporarily disable full Puppet management by setting the `purge_configs` parameter within the base `apache` class to 'false'. This option should only be used as a temporary means of saving and relocating customized configurations. + +####Class: `apache` + +The Apache module's primary class, `apache`, guides the basic setup of Apache on your system. + +You may establish a default vhost in this class, the `vhost` class, or both. You may add additional vhost configurations for specific virtual hosts using a declaration of the `vhost` type. + +**Parameters within `apache`:** + +#####`default_mods` + +Sets up Apache with default settings based on your OS. Defaults to 'true', set to 'false' for customized configuration. + +#####`default_vhost` + +Sets up a default virtual host. Defaults to 'true', set to 'false' to set up [customized virtual hosts](#configure-a-virtual-host). + +#####`default_ssl_vhost` + +Sets up a default SSL virtual host. Defaults to 'false'. + +```puppet + apache::vhost { 'default-ssl': + port => 443, + ssl => true, + docroot => $docroot, + scriptalias => $scriptalias, + serveradmin => $serveradmin, + access_log_file => "ssl_${access_log_file}", + } +``` + +SSL vhosts only respond to HTTPS queries. + +#####`default_ssl_cert` + +The default SSL certification, which is automatically set based on your operating system (`/etc/pki/tls/certs/localhost.crt` for RedHat, `/etc/ssl/certs/ssl-cert-snakeoil.pem` for Debian). This default will work out of the box but must be updated with your specific certificate information before being used in production. + +#####`default_ssl_key` + +The default SSL key, which is automatically set based on your operating system (`/etc/pki/tls/private/localhost.key` for RedHat, `/etc/ssl/private/ssl-cert-snakeoil.key` for Debian). This default will work out of the box but must be updated with your specific certificate information before being used in production. + +#####`default_ssl_chain` + +The default SSL chain, which is automatically set to 'undef'. This default will work out of the box but must be updated with your specific certificate information before being used in production. + +#####`default_ssl_ca` + +The default certificate authority, which is automatically set to 'undef'. This default will work out of the box but must be updated with your specific certificate information before being used in production. + +#####`default_ssl_crl_path` + +The default certificate revocation list path, which is automatically set to 'undef'. This default will work out of the box but must be updated with your specific certificate information before being used in production. + +#####`default_ssl_crl` + +The default certificate revocation list to use, which is automatically set to 'undef'. This default will work out of the box but must be updated with your specific certificate information before being used in production. + +#####`service_enable` + +Determines whether the 'httpd' service is enabled when the machine is booted, meaning Puppet will check the service status to start/stop it. Defaults to 'true', meaning the service is enabled/running. + +#####`serveradmin` + +Sets the server administrator. Defaults to 'root@localhost'. + +#####`servername` + +Sets the servername. Defaults to fqdn provided by facter. + +#####`sendfile` + +Makes Apache use the Linux kernel 'sendfile' to serve static files. Defaults to 'false'. + +#####`error_documents` + +Enables custom error documents. Defaults to 'false'. + +#####`httpd_dir` + +Changes the base location of the configuration directories used for the service. This is useful for specially repackaged HTTPD builds but may have unintended concequences when used in combination with the default distribution packages. Default is based on your OS. + +#####`confd_dir` + +Changes the location of the configuration directory your custom configuration files are placed in. Default is based on your OS. + +#####`vhost_dir` + +Changes the location of the configuration directory your virtual host configuration files are placed in. Default is based on your OS. + +#####`mod_dir` + +Changes the location of the configuration directory your Apache modules configuration files are placed in. Default is based on your OS. + +#####`mpm_module` + +Configures which mpm module is loaded and configured for the httpd process by the `apache::mod::prefork`, `apache::mod::worker` and `apache::mod::itk` classes. Must be set to `false` to explicitly declare `apache::mod::worker`, `apache::mod::worker` or `apache::mod::itk` classes with parameters. Valid values are `worker`, `prefork`, `itk` (Debian), or the boolean `false`. Defaults to `prefork` on RedHat and `worker` on Debian. + +#####`conf_template` + +Setting this allows you to override the template used for the main apache configuration file. This is a potentially risky thing to do as this module has been built around the concept of a minimal configuration file with most of the configuration coming in the form of conf.d/ entries. Defaults to 'apache/httpd.conf.erb'. + +#####`keepalive` + +Setting this allows you to enable persistent connections. + +#####`keepalive_timeout` + +Amount of time the server will wait for subsequent requests on a persistent connection. Defaults to '15'. + +#####`logroot` + +Changes the location of the directory Apache log files are placed in. Defaut is based on your OS. + +#####`ports_file` + +Changes the name of the file containing Apache ports configuration. Default is `${conf_dir}/ports.conf`. + +####Class: `apache::default_mods` + +Installs default Apache modules based on what OS you are running + +```puppet + class { 'apache::default_mods': } +``` + +####Defined Type: `apache::mod` + +Used to enable arbitrary Apache httpd modules for which there is no specific `apache::mod::[name]` class. The `apache::mod` defined type will also install the required packages to enable the module, if any. + +```puppet + apache::mod { 'rewrite': } + apache::mod { 'ldap': } +``` + +####Classes: `apache::mod::[name]` + +There are many `apache::mod::[name]` classes within this module that can be declared using `include`: + +* `alias` +* `auth_basic` +* `auth_kerb` +* `autoindex` +* `cache` +* `cgi` +* `cgid` +* `dav` +* `dav_fs` +* `deflate` +* `dir`* +* `disk_cache` +* `fcgid` +* `info` +* `ldap` +* `mime` +* `mime_magic` +* `mpm_event` +* `negotiation` +* `passenger`* +* `perl` +* `php` (requires [`mpm_module`](#mpm_module) set to `prefork`) +* `prefork`* +* `proxy`* +* `proxy_html` +* `proxy_http` +* `python` +* `reqtimeout` +* `setenvif` +* `ssl`* (see [apache::mod::ssl](#class-apachemodssl) below) +* `status` +* `suphp` +* `userdir`* +* `worker`* +* `wsgi` (see [apache::mod::wsgi](#class-apachemodwsgi) below) +* `xsendfile` + +Modules noted with a * indicate that the module has settings and, thus, a template that includes parameters. These parameters control the module's configuration. Most of the time, these parameters will not require any configuration or attention. + +The modules mentioned above, and other Apache modules that have templates, will cause template files to be dropped along with the mod install, and the module will not work without the template. Any mod without a template will install package but drop no files. + +####Class: `apache::mod::ssl` + +Installs Apache SSL capabilities and utilizes `ssl.conf.erb` template + +```puppet + class { 'apache::mod::ssl': } +``` + +To *use* SSL with a virtual host, you must either set the`default_ssl_vhost` parameter in `apache` to 'true' or set the `ssl` parameter in `apache::vhost` to 'true'. + +####Class: `apache::mod::wsgi` + +```puppet + class { 'apache::mod::wsgi': + wsgi_socket_prefix => "\${APACHE_RUN_DIR}WSGI", + wsgi_python_home => '/path/to/virtenv', + } +``` +####Defined Type: `apache::vhost` + +The Apache module allows a lot of flexibility in the set up and configuration of virtual hosts. This flexibility is due, in part, to `vhost`'s setup as a defined resource type, which allows it to be evaluated multiple times with different parameters. + +The `vhost` defined type allows you to have specialized configurations for virtual hosts that have requirements outside of the defaults. You can set up a default vhost within the base `apache` class as well as set a customized vhost setup as default. Your customized vhost (priority 10) will be privileged over the base class vhost (15). + +If you have a series of specific configurations and do not want a base `apache` class default vhost, make sure to set the base class default host to 'false'. + +```puppet + class { 'apache': + default_vhost => false, + } +``` + +**Parameters within `apache::vhost`:** + +The default values for each parameter will vary based on operating system and type of virtual host. + +#####`access_log` + +Specifies whether `*_access.log` directives should be configured. Valid values are 'true' and 'false'. Defaults to 'true'. + +#####`access_log_file` + +Points to the `*_access.log` file. Defaults to 'undef'. + +#####`access_log_pipe` + +Specifies a pipe to send access log messages to. Defaults to 'undef'. + +#####`access_log_syslog` + +Sends all access log messages to syslog. Defaults to 'undef'. + +#####`access_log_format` + +Specifies either a LogFormat nickname or custom format string for access log. Defaults to 'undef'. + +#####`add_listen` + +Determines whether the vhost creates a listen statement. The default value is 'true'. + +Setting `add_listen` to 'false' stops the vhost from creating a listen statement, and this is important when you combine vhosts that are not passed an `ip` parameter with vhosts that *are* passed the `ip` parameter. + +#####`aliases` + +Passes a list of hashes to the vhost to create `Alias` statements as per the [`mod_alias` documentation](http://httpd.apache.org/docs/current/mod/mod_alias.html). Each hash is expected to be of the form: + +```puppet +aliases => [ { alias => '/alias', path => '/path/to/directory' } ], +``` + +For `Alias` to work, each will need a corresponding `` or `` block. + +**Note:** If `apache::mod::passenger` is loaded and `PassengerHighPerformance true` is set, then `Alias` may have issues honouring the `PassengerEnabled off` statement. See [this article](http://www.conandalton.net/2010/06/passengerenabled-off-not-working.html) for details. + +#####`block` + +Specifies the list of things Apache will block access to. The default is an empty set, '[]'. Currently, the only option is 'scm', which blocks web access to .svn, .git and .bzr directories. To add to this, please see the [Development](#development) section. + +#####`custom_fragment` + +Pass a string of custom configuration directives to be placed at the end of the vhost configuration. + +#####`default_vhost` + +Sets a given `apache::vhost` as the default to serve requests that do not match any other `apache::vhost` definitions. The default value is 'false'. + +#####`directories` + +Passes a list of hashes to the vhost to create `...` directive blocks as per the [Apache core documentation](http://httpd.apache.org/docs/2.2/mod/core.html#directory). The `path` key is required in these hashes. Usage will typically look like: + +```puppet + apache::vhost { 'sample.example.net': + docroot => '/path/to/directory', + directories => [ + { path => '/path/to/directory', => }, + { path => '/path/to/another/directory', => }, + ], + } +``` + +*Note:* At least one directory should match `docroot` parameter, once you start declaring directories `apache::vhost` assumes that all required `` blocks will be declared. + +*Note:* If not defined a single default `` block will be created that matches the `docroot` parameter. + +The directives will be embedded within the `Directory` directive block, missing directives should be undefined and not be added, resulting in their default vaules in Apache. Currently this is the list of supported directives: + +######`addhandlers` + +Sets `AddHandler` directives as per the [Apache Core documentation](http://httpd.apache.org/docs/2.2/mod/mod_mime.html#addhandler). Accepts a list of hashes of the form `{ handler => 'handler-name', extensions => ['extension']}`. Note that `extensions` is a list of extenstions being handled by the handler. +An example: + +```puppet + apache::vhost { 'sample.example.net': + docroot => '/path/to/directory', + directories => [ { path => '/path/to/directory', + addhandlers => [ { handler => 'cgi-script', extensions => ['.cgi']} ], + } ], + } +``` + +######`allow` + +Sets an `Allow` directive as per the [Apache Core documentation](http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#allow). An example: + +```puppet + apache::vhost { 'sample.example.net': + docroot => '/path/to/directory', + directories => [ { path => '/path/to/directory', allow => 'from example.org' } ], + } +``` + +######`allow_override` + +Sets the usage of `.htaccess` files as per the [Apache core documentation](http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride). Should accept in the form of a list or a string. An example: + +```puppet + apache::vhost { 'sample.example.net': + docroot => '/path/to/directory', + directories => [ { path => '/path/to/directory', allow_override => ['AuthConfig', 'Indexes'] } ], + } +``` + +######`deny` + +Sets an `Deny` directive as per the [Apache Core documentation](http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#deny). An example: + +```puppet + apache::vhost { 'sample.example.net': + docroot => '/path/to/directory', + directories => [ { path => '/path/to/directory', deny => 'from example.org' } ], + } +``` + +######`headers` + +Adds lines for `Header` directives as per the [Apache Header documentation](http://httpd.apache.org/docs/2.2/mod/mod_headers.html#header). An example: + +```puppet + apache::vhost { 'sample.example.net': + docroot => '/path/to/directory', + directories => { + path => '/path/to/directory', + headers => 'Set X-Robots-Tag "noindex, noarchive, nosnippet"', + }, + } +``` + +######`options` + +Lists the options for the given `` block + +```puppet + apache::vhost { 'sample.example.net': + docroot => '/path/to/directory', + directories => [ { path => '/path/to/directory', options => ['Indexes','FollowSymLinks','MultiViews'] }], + } +``` + +######`order` +Sets the order of processing `Allow` and `Deny` statements as per [Apache core documentation](http://httpd.apache.org/docs/2.2/mod/mod_authz_host.html#order). An example: + +```puppet + apache::vhost { 'sample.example.net': + docroot => '/path/to/directory', + directories => [ { path => '/path/to/directory', order => 'Allow, Deny' } ], + } +``` + + +######`auth_type` + +Sets the value for `AuthType` as per the [Apache AuthType +documentation](https://httpd.apache.org/docs/2.2/mod/core.html#authtype). + +######`auth_name` + +Sets the value for `AuthName` as per the [Apache AuthName +documentation](https://httpd.apache.org/docs/2.2/mod/core.html#authname). + +######`auth_digest_algorithm` + +Sets the value for `AuthDigestAlgorithm` as per the [Apache +AuthDigestAlgorithm +documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestalgorithm) + +######`auth_digest_domain` + +Sets the value for `AuthDigestDomain` as per the [Apache AuthDigestDomain +documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestdomain). + +######`auth_digest_nonce_lifetime` + +Sets the value for `AuthDigestNonceLifetime` as per the [Apache +AuthDigestNonceLifetime +documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestnoncelifetime) + +######`auth_digest_provider` + +Sets the value for `AuthDigestProvider` as per the [Apache AuthDigestProvider +documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestprovider). + +######`auth_digest_qop` + +Sets the value for `AuthDigestQop` as per the [Apache AuthDigestQop +documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestqop). + +######`auth_digest_shmem_size` + +Sets the value for `AuthAuthDigestShmemSize` as per the [Apache AuthDigestShmemSize +documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_digest.html#authdigestshmemsize). + +######`auth_basic_authoritative` + +Sets the value for `AuthBasicAuthoritative` as per the [Apache +AuthBasicAuthoritative +documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html#authbasicauthoritative). + +######`auth_basic_fake` + +Sets the value for `AuthBasicFake` as per the [Apache AuthBasicFake +documentation](https://httpd.apache.org/docs/trunk/mod/mod_auth_basic.html#authbasicfake). + +######`auth_basic_provider` + +Sets the value for `AuthBasicProvider` as per the [Apache AuthBasicProvider +documentation](https://httpd.apache.org/docs/2.2/mod/mod_auth_basic.html#authbasicprovider). + +######`auth_user_file` + +Sets the value for `AuthUserFile` as per the [Apache AuthUserFile +documentation](https://httpd.apache.org/docs/2.2/mod/mod_authn_file.html#authuserfile). + +######`auth_require` + +Sets the value for `AuthName` as per the [Apache Require +documentation](https://httpd.apache.org/docs/2.2/mod/core.html#require) + + +######`passenger_enabled` + +Sets the value for the `PassengerEnabled` directory to `on` or `off` as per the [Passenger documentation](http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerEnabled). + +```puppet + apache::vhost { 'sample.example.net': + docroot => '/path/to/directory', + directories => [ { path => '/path/to/directory', passenger_enabled => 'off' } ], + } +``` + +**Note:** This directive requires `apache::mod::passenger` to be active, Apache may not start with an unrecognised directive without it. + +**Note:** Be aware that there is an [issue](http://www.conandalton.net/2010/06/passengerenabled-off-not-working.html) using the `PassengerEnabled` directive with the `PassengerHighPerformance` directive. + +######`custom_fragment` + +Pass a string of custom configuration directives to be placed at the end of the +directory configuration. + +#####`docroot` + +Provides the DocumentRoot directive, identifying the directory Apache serves files from. + +#####`docroot_group` + +Sets group access to the docroot directory. Defaults to 'root'. + +#####`docroot_owner` + +Sets individual user access to the docroot directory. Defaults to 'root'. + +#####`error_log` + +Specifies whether `*_error.log` directives should be configured. Defaults to 'true'. + +#####`error_log_file` + +Points to the `*_error.log` file. Defaults to 'undef'. + +#####`error_log_pipe` + +Specifies a pipe to send error log messages to. Defaults to 'undef'. + +#####`error_log_syslog` + +Sends all error log messages to syslog. Defaults to 'undef'. + +#####`ensure` + +Specifies if the vhost file is present or absent. + +#####`ip` + +The IP address the vhost listens on. Defaults to 'undef'. + +#####`ip_based` + +Enables an IP-based vhost. This parameter inhibits the creation of a NameVirtualHost directive, since those are used to funnel requests to name-based vhosts. Defaults to 'false'. + +#####`logroot` + +Specifies the location of the virtual host's logfiles. Defaults to `/var/log//`. + +#####`no_proxy_uris` + +Specifies URLs you do not want to proxy. This parameter is meant to be used in combination with `proxy_dest`. + +#####`options` + +Lists the options for the given virtual host + +```puppet + apache::vhost { 'site.name.fdqn': + … + options => ['Indexes','FollowSymLinks','MultiViews'], + } +``` + +#####`override` + +Sets the overrides for the given virtual host. Accepts an array of AllowOverride arguments. + +#####`port` + +Sets the port the host is configured on. + +#####`priority` + +Sets the relative load-order for Apache httpd VirtualHost configuration files. Defaults to '25'. + +If nothing matches the priority, the first name-based vhost will be used. Likewise, passing a higher priority will cause the alphabetically first name-based vhost to be used if no other names match. + +*Note*: You should not need to use this parameter. However, if you do use it, be aware that the `default_vhost` parameter for `apache::vhost` passes a priority of '15'. + +#####`proxy_dest` + +Specifies the destination address of a proxypass configuration. Defaults to 'undef'. + +#####`proxy_pass` + +Specifies an array of path => uri for a proxypass configuration. Defaults to 'undef'. + +Example: + +```puppet +$proxy_pass = [ + { 'path' => '/a', 'url' => 'http://backend-a/' }, + { 'path' => '/b', 'url' => 'http://backend-b/' }, + { 'path' => '/c', 'url' => 'http://backend-a/c' } +] + +apache::vhost { 'site.name.fdqn': + … + proxy_pass => $proxy_pass, +} +``` + +#####`rack_base_uris` + +Specifies the resource identifiers for a rack configuration. The file paths specified will be listed as rack application roots for passenger/rack in the `_rack.erb` template. Defaults to 'undef'. + +#####`redirect_dest` + +Specifies the address to redirect to. Defaults to 'undef'. + +#####`redirect_source` + +Specifies the source items? that will redirect to the destination specified in `redirect_dest`. If more than one item for redirect is supplied, the source and destination must be the same length, and the items are order-dependent. + +```puppet + apache::vhost { 'site.name.fdqn': + … + redirect_source => ['/images','/downloads'], + redirect_dest => ['http://img.example.com/','http://downloads.example.com/'], + } +``` + +#####`redirect_status` + +Specifies the status to append to the redirect. Defaults to 'undef'. + +```puppet + apache::vhost { 'site.name.fdqn': + … + redirect_status => ['temp','permanent'], + } +``` + +#####`request_headers` + +Specifies additional request headers. + +```puppet + apache::vhost { 'site.name.fdqn': + … + request_headers => [ + 'append MirrorID "mirror 12"', + 'unset MirrorID', + ], + } +``` + +#####`rewrite_base` + +Limits the `rewrite_rule` to the specified base URL. Defaults to 'undef'. + +```puppet + apache::vhost { 'site.name.fdqn': + … + rewrite_rule => '^index\.html$ welcome.html', + rewrite_base => '/blog/', + } +``` + +The above example would limit the index.html -> welcome.html rewrite to only something inside of http://example.com/blog/. + +#####`rewrite_cond` + +Rewrites a URL via `rewrite_rule` based on the truth of specified conditions. For example + +```puppet + apache::vhost { 'site.name.fdqn': + … + rewrite_cond => '%{HTTP_USER_AGENT} ^MSIE', + } +``` + +will rewrite URLs only if the visitor is using IE. Defaults to 'undef'. + +*Note*: At the moment, each vhost is limited to a single list of rewrite conditions. In the future, you will be able to specify multiple `rewrite_cond` and `rewrite_rules` per vhost, so that different conditions get different rewrites. + +#####`rewrite_rule` + +Creates URL rewrite rules. Defaults to 'undef'. This parameter allows you to specify, for example, that anyone trying to access index.html will be served welcome.html. + +```puppet + apache::vhost { 'site.name.fdqn': + … + rewrite_rule => '^index\.html$ welcome.html', + } +``` + +#####`scriptalias` + +Defines a directory of CGI scripts to be aliased to the path '/cgi-bin' + +#####`serveradmin` + +Specifies the email address Apache will display when it renders one of its error pages. + +#####`serveraliases` + +Sets the server aliases of the site. + +#####`servername` + +Sets the primary name of the virtual host. + +#####`setenv` + +Used by HTTPD to set environment variables for vhosts. Defaults to '[]'. + +#####`setenvif` + +Used by HTTPD to conditionally set environment variables for vhosts. Defaults to '[]'. + +#####`ssl` + +Enables SSL for the virtual host. SSL vhosts only respond to HTTPS queries. Valid values are 'true' or 'false'. + +#####`ssl_ca` + +Specifies the certificate authority. + +#####`ssl_cert` + +Specifies the SSL certification. + +#####`ssl_certs_dir` + +Specifies the location of the SSL certification directory. Defaults to `/etc/ssl/certs`. + +#####`ssl_chain` + +Specifies the SSL chain. + +#####`ssl_crl` + +Specifies the certificate revocation list to use. + +#####`ssl_crl_path` + +Specifies the location of the certificate revocation list. + +#####`ssl_key` + +Specifies the SSL key. + +#####`sslproxyengine` + +Specifies whether to use `SSLProxyEngine` or not. Defaults to `false`. + +#####`vhost_name` + +This parameter is for use with name-based virtual hosting. Defaults to '*'. + +#####`itk` + +Hash containing infos to configure itk as per the [ITK documentation](http://mpm-itk.sesse.net/). + +Keys could be: +* user + group +* assignuseridexpr +* assigngroupidexpr +* maxclientvhost +* nice +* limituidrange (Linux 3.5.0 or newer) +* limitgidrange (Linux 3.5.0 or newer) + +Usage will typically look like: + +```puppet + apache::vhost { 'sample.example.net': + docroot => '/path/to/directory', + itk => { + user => 'someuser', + group => 'somegroup', + }, + } +``` + +###Virtual Host Examples + +The Apache module allows you to set up pretty much any configuration of virtual host you might desire. This section will address some common configurations. Please see the [Tests section](https://github.com/puppetlabs/puppetlabs-apache/tree/master/tests) for even more examples. + +Configure a vhost with a server administrator + +```puppet + apache::vhost { 'third.example.com': + port => '80', + docroot => '/var/www/third', + serveradmin => 'admin@example.com', + } +``` + +- - - + +Set up a vhost with aliased servers + +```puppet + apache::vhost { 'sixth.example.com': + serveraliases => [ + 'sixth.example.org', + 'sixth.example.net', + ], + port => '80', + docroot => '/var/www/fifth', + } +``` + +- - - + +Configure a vhost with a cgi-bin + +```puppet + apache::vhost { 'eleventh.example.com': + port => '80', + docroot => '/var/www/eleventh', + scriptalias => '/usr/lib/cgi-bin', + } +``` + +- - - + +Set up a vhost with a rack configuration + +```puppet + apache::vhost { 'fifteenth.example.com': + port => '80', + docroot => '/var/www/fifteenth', + rack_base_uris => ['/rackapp1', '/rackapp2'], + } +``` + +- - - + +Set up a mix of SSL and non-SSL vhosts at the same domain + +```puppet + #The non-ssl vhost + apache::vhost { 'first.example.com non-ssl': + servername => 'first.example.com', + port => '80', + docroot => '/var/www/first', + } + + #The SSL vhost at the same domain + apache::vhost { 'first.example.com ssl': + servername => 'first.example.com', + port => '443', + docroot => '/var/www/first', + ssl => true, + } +``` + +- - - + +Configure a vhost to redirect non-SSL connections to SSL + +```puppet + apache::vhost { 'sixteenth.example.com non-ssl': + servername => 'sixteenth.example.com', + port => '80', + docroot => '/var/www/sixteenth', + redirect_status => 'permanent' + redirect_dest => 'https://sixteenth.example.com/' + } + apache::vhost { 'sixteenth.example.com ssl': + servername => 'sixteenth.example.com', + port => '443', + docroot => '/var/www/sixteenth', + ssl => true, + } +``` + +- - - + +Set up IP-based vhosts on any listen port and have them respond to requests on specific IP addresses. In this example, we will set listening on ports 80 and 81. This is required because the example vhosts are not declared with a port parameter. + +```puppet + apache::listen { '80': } + apache::listen { '81': } +``` + +Then we will set up the IP-based vhosts + +```puppet + apache::vhost { 'first.example.com': + ip => '10.0.0.10', + docroot => '/var/www/first', + ip_based => true, + } + apache::vhost { 'second.example.com': + ip => '10.0.0.11', + docroot => '/var/www/second', + ip_based => true, + } +``` + +- - - + +Configure a mix of name-based and IP-based vhosts. First, we will add two IP-based vhosts on 10.0.0.10, one SSL and one non-SSL + +```puppet + apache::vhost { 'The first IP-based vhost, non-ssl': + servername => 'first.example.com', + ip => '10.0.0.10', + port => '80', + ip_based => true, + docroot => '/var/www/first', + } + apache::vhost { 'The first IP-based vhost, ssl': + servername => 'first.example.com', + ip => '10.0.0.10', + port => '443', + ip_based => true, + docroot => '/var/www/first-ssl', + ssl => true, + } +``` + +Then, we will add two name-based vhosts listening on 10.0.0.20 + +```puppet + apache::vhost { 'second.example.com': + ip => '10.0.0.20', + port => '80', + docroot => '/var/www/second', + } + apache::vhost { 'third.example.com': + ip => '10.0.0.20', + port => '80', + docroot => '/var/www/third', + } +``` + +If you want to add two name-based vhosts so that they will answer on either 10.0.0.10 or 10.0.0.20, you **MUST** declare `add_listen => 'false'` to disable the otherwise automatic 'Listen 80', as it will conflict with the preceding IP-based vhosts. + +```puppet + apache::vhost { 'fourth.example.com': + port => '80', + docroot => '/var/www/fourth', + add_listen => false, + } + apache::vhost { 'fifth.example.com': + port => '80', + docroot => '/var/www/fifth', + add_listen => false, + } +``` + +##Implementation + +###Classes and Defined Types + +####Class: `apache::dev` + +Installs Apache development libraries + +```puppet + class { 'apache::dev': } +``` + +####Defined Type: `apache::listen` + +Controls which ports Apache binds to for listening based on the title: + +```puppet + apache::listen { '80': } + apache::listen { '443': } +``` + +Declaring this defined type will add all `Listen` directives to the `ports.conf` file in the Apache httpd configuration directory. `apache::listen` titles should always take the form of: ``, `:`, or `[]:` + +Apache httpd requires that `Listen` directives must be added for every port. The `apache::vhost` defined type will automatically add `Listen` directives unless the `apache::vhost` is passed `add_listen => false`. + +####Defined Type: `apache::namevirtualhost` + +Enables named-based hosting of a virtual host + +```puppet + class { 'apache::namevirtualhost`: } +``` + +Declaring this defined type will add all `NameVirtualHost` directives to the `ports.conf` file in the Apache https configuration directory. `apache::namevirtualhost` titles should always take the form of: `*`, `*:`, `_default_:`, ``, or `:`. + +####Defined Type: `apache::balancermember` + +Define members of a proxy_balancer set (mod_proxy_balancer). Very useful when using exported resources. + +On every app server you can export a balancermember like this: + +```puppet + @@apache::balancermember { "${::fqdn}-puppet00": + balancer_cluster => 'puppet00', + url => "ajp://${::fqdn}:8009" + options => ['ping=5', 'disablereuse=on', 'retry=5', 'ttl=120'], + } +``` + +And on the proxy itself you create the balancer cluster using the defined type apache::balancer: + +```puppet + apache::balancer { 'puppet00': } +``` + +If you need to use ProxySet in the balncer config you can do as so: + +```puppet + apache::balancer { 'puppet01': + proxy_set => {'stickysession' => 'JSESSIONID'}, + } +``` + +###Templates + +The Apache module relies heavily on templates to enable the `vhost` and `apache::mod` defined types. These templates are built based on Facter facts around your operating system. Unless explicitly called out, most templates are not meant for configuration. + +##Limitations + +This has been tested on Ubuntu Precise, Debian Wheezy, and CentOS 5.8. + +##Development + +### Overview + +Puppet Labs modules on the Puppet Forge are open projects, and community contributions are essential for keeping them great. We can’t access the huge number of platforms and myriad of hardware, software, and deployment configurations that Puppet is intended to serve. + +We want to keep it as easy as possible to contribute changes so that our modules work in your environment. There are a few guidelines that we need contributors to follow so that we can have a chance of keeping on top of things. + +You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing) + +### Running tests + +This project contains tests for both [rspec-puppet](http://rspec-puppet.com/) and [rspec-system](https://github.com/puppetlabs/rspec-system) to verify functionality. For in-depth information please see their respective documentation. + +Quickstart: + + gem install bundler + bundle install + bundle exec rake spec + bundle exec rake spec:system + +##Copyright and License + +Copyright (C) 2012 [Puppet Labs](https://www.puppetlabs.com/) Inc + +Puppet Labs can be contacted at: info@puppetlabs.com + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/deployment/modules/apache/README.passenger.md b/deployment/modules/apache/README.passenger.md new file mode 100644 index 000000000..80dbfe0e1 --- /dev/null +++ b/deployment/modules/apache/README.passenger.md @@ -0,0 +1,89 @@ +# Passenger + +Just enabling the Passenger module is insufficient for the use of Passenger in production. Passenger should be tunable to better fit the environment in which it is run while being aware of the resources it required. + +To this end the Apache passenger module has been modified to apply system wide Passenger tuning declarations to `passenger.conf`. Declarations specific to a virtual host should be passed through when defining a `vhost` (e.g. `rack_base_uris' parameter on the `apache::vhost` class, check `README.md`). + +# Parameters for `apache::mod::passenger` + +The following declarations are supported and can be passed to `apache::mod::passenger` as parameters, for example: + +``` +class {'apache::mod::passenger': + passenger_high_performance => 'on', + rails_autodetect => 'off', +} +``` + +The general form is using the all lower case version of the declaration. + +If you pass a default value to `apache::mod::passenger` it will be ignored and not passed through to the configuration file. + +## passenger_high_performance + +Default is `off`, when turned `on` Passenger runs in a higher performance mode that can be less compatible with other Apache modules. + +http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerHighPerformance + +## passenger_max_pool_size + +Set's the maximum number of Passenger application processes that may simultaneously run. The default value is 6. + +http://www.modrails.com/documentation/Users%20guide%20Apache.html#_passengermaxpoolsize_lt_integer_gt + +## passenger_pool_idle_time + +The maximum number of seconds a Passenger Application process will be allowed to remain idle before being shut down. The default value is 300. + +http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerPoolIdleTime + +## passenger_max_requests + +The maximum number of request a Passenger application will process before being restarted. The default value is 0, which indicates that a process will only shut down if the Pool Idle Time (see above) expires. + +http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerMaxRequests + +## passenger_stat_throttle_rate + +Sets how often Passenger performs file system checks, at most once every _x_ seconds. Default is 0, which means the checks are performed with every request. + +http://www.modrails.com/documentation/Users%20guide%20Apache.html#_passengerstatthrottlerate_lt_integer_gt + +## rack_auto_detect + +Should Passenger automatically detect if the document root of a virtual host is a Rack application. The default is `on` + +http://www.modrails.com/documentation/Users%20guide%20Apache.html#_rackautodetect_lt_on_off_gt + +## rails_auto_detect + +Should Passenger automatically detect if the document root of a virtual host is a Rails application. The default is on. + +http://www.modrails.com/documentation/Users%20guide%20Apache.html#_railsautodetect_lt_on_off_gt + +# Attribution + +The Passenger tuning parameters for the `apache::mod::puppet` Puppet class was modified by Aaron Hicks (hicksa@landcareresearch.co.nz) for work on the NeSI Project and the Tuakiri New Zealand Access Federation as a fork from the PuppetLabs Apache module on GitHub. + +* https://github.com/puppetlabs/puppetlabs-apache +* https://github.com/nesi/puppetlabs-apache +* http://www.nesi.org.nz// +* https://tuakiri.ac.nz/confluence/display/Tuakiri/Home + +# Copyright and License + +Copyright (C) 2012 [Puppet Labs](https://www.puppetlabs.com/) Inc + +Puppet Labs can be contacted at: info@puppetlabs.com + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/deployment/modules/apache/Rakefile b/deployment/modules/apache/Rakefile new file mode 100644 index 000000000..bb60173e5 --- /dev/null +++ b/deployment/modules/apache/Rakefile @@ -0,0 +1,2 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'rspec-system/rake_task' diff --git a/deployment/modules/apache/files/httpd b/deployment/modules/apache/files/httpd new file mode 100644 index 000000000..d65a8d445 --- /dev/null +++ b/deployment/modules/apache/files/httpd @@ -0,0 +1,24 @@ +# Configuration file for the httpd service. + +# +# The default processing model (MPM) is the process-based +# 'prefork' model. A thread-based model, 'worker', is also +# available, but does not work with some modules (such as PHP). +# The service must be stopped before changing this variable. +# +#HTTPD=/usr/sbin/httpd.worker + +# +# To pass additional options (for instance, -D definitions) to the +# httpd binary at startup, set OPTIONS here. +# +#OPTIONS= +#OPTIONS=-DDOWN + +# +# By default, the httpd process is started in the C locale; to +# change the locale in which the server runs, the HTTPD_LANG +# variable can be set. +# +#HTTPD_LANG=C +export SHORTHOST=`hostname -s` diff --git a/deployment/modules/apache/lib/puppet/provider/a2mod.rb b/deployment/modules/apache/lib/puppet/provider/a2mod.rb new file mode 100644 index 000000000..670aca3d0 --- /dev/null +++ b/deployment/modules/apache/lib/puppet/provider/a2mod.rb @@ -0,0 +1,34 @@ +class Puppet::Provider::A2mod < Puppet::Provider + def self.prefetch(mods) + instances.each do |prov| + if mod = mods[prov.name] + mod.provider = prov + end + end + end + + def flush + @property_hash.clear + end + + def properties + if @property_hash.empty? + @property_hash = query || {:ensure => :absent} + @property_hash[:ensure] = :absent if @property_hash.empty? + end + @property_hash.dup + end + + def query + self.class.instances.each do |mod| + if mod.name == self.name or mod.name.downcase == self.name + return mod.properties + end + end + nil + end + + def exists? + properties[:ensure] != :absent + end +end diff --git a/deployment/modules/apache/lib/puppet/provider/a2mod/a2mod.rb b/deployment/modules/apache/lib/puppet/provider/a2mod/a2mod.rb new file mode 100644 index 000000000..e257a579e --- /dev/null +++ b/deployment/modules/apache/lib/puppet/provider/a2mod/a2mod.rb @@ -0,0 +1,35 @@ +require 'puppet/provider/a2mod' + +Puppet::Type.type(:a2mod).provide(:a2mod, :parent => Puppet::Provider::A2mod) do + desc "Manage Apache 2 modules on Debian and Ubuntu" + + optional_commands :encmd => "a2enmod" + optional_commands :discmd => "a2dismod" + commands :apache2ctl => "apache2ctl" + + confine :osfamily => :debian + defaultfor :operatingsystem => [:debian, :ubuntu] + + def self.instances + modules = apache2ctl("-M").lines.collect { |line| + m = line.match(/(\w+)_module \(shared\)$/) + m[1] if m + }.compact + + modules.map do |mod| + new( + :name => mod, + :ensure => :present, + :provider => :a2mod + ) + end + end + + def create + encmd resource[:name] + end + + def destroy + discmd resource[:name] + end +end diff --git a/deployment/modules/apache/lib/puppet/provider/a2mod/gentoo.rb b/deployment/modules/apache/lib/puppet/provider/a2mod/gentoo.rb new file mode 100644 index 000000000..07319dfdc --- /dev/null +++ b/deployment/modules/apache/lib/puppet/provider/a2mod/gentoo.rb @@ -0,0 +1,116 @@ +require 'puppet/util/filetype' +Puppet::Type.type(:a2mod).provide(:gentoo, :parent => Puppet::Provider) do + desc "Manage Apache 2 modules on Gentoo" + + confine :operatingsystem => :gentoo + defaultfor :operatingsystem => :gentoo + + attr_accessor :property_hash + + def create + @property_hash[:ensure] = :present + end + + def exists? + (!(@property_hash[:ensure].nil?) and @property_hash[:ensure] == :present) + end + + def destroy + @property_hash[:ensure] = :absent + end + + def flush + self.class.flush + end + + class << self + attr_reader :conf_file + end + + def self.clear + @mod_resources = [] + @modules = [] + @other_args = "" + end + + def self.initvars + @conf_file = "/etc/conf.d/apache2" + @filetype = Puppet::Util::FileType.filetype(:flat).new(conf_file) + @mod_resources = [] + @modules = [] + @other_args = "" + end + + self.initvars + + # Retrieve an array of all existing modules + def self.modules + if @modules.length <= 0 + # Locate the APACHE_OPTS variable + records = filetype.read.split(/\n/) + apache2_opts = records.grep(/^\s*APACHE2_OPTS=/).first + + # Extract all defines + while apache2_opts.sub!(/-D\s+(\w+)/, '') + @modules << $1.downcase + end + + # Hang on to any remaining options. + if apache2_opts.match(/APACHE2_OPTS="(.+)"/) + @other_args = $1.strip + end + + @modules.sort!.uniq! + end + + @modules + end + + def self.prefetch(resources={}) + # Match resources with existing providers + instances.each do |provider| + if resource = resources[provider.name] + resource.provider = provider + end + end + + # Store all resources using this provider for flushing + resources.each do |name, resource| + @mod_resources << resource + end + end + + def self.instances + modules.map {|mod| new(:name => mod, :provider => :gentoo, :ensure => :present)} + end + + def self.flush + + mod_list = modules + mods_to_remove = @mod_resources.select {|mod| mod.should(:ensure) == :absent}.map {|mod| mod[:name]} + mods_to_add = @mod_resources.select {|mod| mod.should(:ensure) == :present}.map {|mod| mod[:name]} + + mod_list -= mods_to_remove + mod_list += mods_to_add + mod_list.sort!.uniq! + + if modules != mod_list + opts = @other_args + " " + opts << mod_list.map {|mod| "-D #{mod.upcase}"}.join(" ") + opts.strip! + opts.gsub!(/\s+/, ' ') + + apache2_opts = %Q{APACHE2_OPTS="#{opts}"} + Puppet.debug("Writing back \"#{apache2_opts}\" to #{conf_file}") + + records = filetype.read.split(/\n/) + + opts_index = records.find_index {|i| i.match(/^\s*APACHE2_OPTS/)} + records[opts_index] = apache2_opts + + filetype.backup + filetype.write(records.join("\n")) + @modules = mod_list + end + end +end diff --git a/deployment/modules/apache/lib/puppet/provider/a2mod/modfix.rb b/deployment/modules/apache/lib/puppet/provider/a2mod/modfix.rb new file mode 100644 index 000000000..8f35b2e4a --- /dev/null +++ b/deployment/modules/apache/lib/puppet/provider/a2mod/modfix.rb @@ -0,0 +1,12 @@ +Puppet::Type.type(:a2mod).provide :modfix do + desc "Dummy provider for A2mod. + + Fake nil resources when there is no crontab binary available. Allows + puppetd to run on a bootstrapped machine before a Cron package has been + installed. Workaround for: http://projects.puppetlabs.com/issues/2384 + " + + def self.instances + [] + end +end \ No newline at end of file diff --git a/deployment/modules/apache/lib/puppet/provider/a2mod/redhat.rb b/deployment/modules/apache/lib/puppet/provider/a2mod/redhat.rb new file mode 100644 index 000000000..ea5494cb4 --- /dev/null +++ b/deployment/modules/apache/lib/puppet/provider/a2mod/redhat.rb @@ -0,0 +1,60 @@ +require 'puppet/provider/a2mod' + +Puppet::Type.type(:a2mod).provide(:redhat, :parent => Puppet::Provider::A2mod) do + desc "Manage Apache 2 modules on RedHat family OSs" + + commands :apachectl => "apachectl" + + confine :osfamily => :redhat + defaultfor :osfamily => :redhat + + require 'pathname' + + # modpath: Path to default apache modules directory /etc/httpd/mod.d + # modfile: Path to module load configuration file; Default: resides under modpath directory + # libfile: Path to actual apache module library. Added in modfile LoadModule + + attr_accessor :modfile, :libfile + class << self + attr_accessor :modpath + def preinit + @modpath = "/etc/httpd/mod.d" + end + end + + self.preinit + + def create + File.open(modfile,'w') do |f| + f.puts "LoadModule #{resource[:identifier]} #{libfile}" + end + end + + def destroy + File.delete(modfile) + end + + def self.instances + modules = apachectl("-M").lines.collect { |line| + m = line.match(/(\w+)_module \(shared\)$/) + m[1] if m + }.compact + + modules.map do |mod| + new( + :name => mod, + :ensure => :present, + :provider => :redhat + ) + end + end + + def modfile + modfile ||= "#{self.class.modpath}/#{resource[:name]}.load" + end + + # Set libfile path: If absolute path is passed, then maintain it. Else, make it default from 'modules' dir. + def libfile + libfile = Pathname.new(resource[:lib]).absolute? ? resource[:lib] : "modules/#{resource[:lib]}" + end +end diff --git a/deployment/modules/apache/lib/puppet/type/a2mod.rb b/deployment/modules/apache/lib/puppet/type/a2mod.rb new file mode 100644 index 000000000..07a911e5e --- /dev/null +++ b/deployment/modules/apache/lib/puppet/type/a2mod.rb @@ -0,0 +1,30 @@ +Puppet::Type.newtype(:a2mod) do + @doc = "Manage Apache 2 modules" + + ensurable + + newparam(:name) do + Puppet.warning "The a2mod provider is deprecated, please use apache::mod instead" + desc "The name of the module to be managed" + + isnamevar + + end + + newparam(:lib) do + desc "The name of the .so library to be loaded" + + defaultto { "mod_#{@resource[:name]}.so" } + end + + newparam(:identifier) do + desc "Module identifier string used by LoadModule. Default: module-name_module" + + # http://httpd.apache.org/docs/2.2/mod/module-dict.html#ModuleIdentifier + + defaultto { "#{resource[:name]}_module" } + end + + autorequire(:package) { catalog.resource(:package, 'httpd')} + +end diff --git a/deployment/modules/apache/manifests/balancer.pp b/deployment/modules/apache/manifests/balancer.pp new file mode 100644 index 000000000..1e4130fa3 --- /dev/null +++ b/deployment/modules/apache/manifests/balancer.pp @@ -0,0 +1,80 @@ +# == Define Resource Type: apache::balancer +# +# This type will create an apache balancer cluster file inside the conf.d +# directory. Each balancer cluster needs one or more balancer members (that can +# be declared with the apache::balancermember defined resource type). Using +# storeconfigs, you can export the apache::balancermember resources on all +# balancer members, and then collect them on a single apache load balancer +# server. +# +# === Requirement/Dependencies: +# +# Currently requires the puppetlabs/concat module on the Puppet Forge and uses +# storeconfigs on the Puppet Master to export/collect resources from all +# balancer members. +# +# === Parameters +# +# [*name*] +# The namevar of the defined resource type is the balancer clusters name. +# This name is also used in the name of the conf.d file +# +# [*proxy_set*] +# Hash, default empty. If given, each key-value pair will be used as a ProxySet +# line in the configuration. +# +# [*collect_exported*] +# Boolean, default 'true'. True means 'collect exported @@balancermember +# resources' (for the case when every balancermember node exports itself), +# false means 'rely on the existing declared balancermember resources' (for the +# case when you know the full set of balancermembers in advance and use +# apache::balancermember with array arguments, which allows you to deploy +# everything in 1 run) +# +# +# === Examples +# +# Exporting the resource for a balancer member: +# +# apache::balancer { 'puppet00': } +# +define apache::balancer ( + $proxy_set = {}, + $collect_exported = true, +) { + include concat::setup + include apache::mod::proxy_balancer + + $target = "${::apache::params::confd_dir}/balancer_${name}.conf" + + concat { $target: + owner => '0', + group => '0', + mode => '0644', + notify => Service['httpd'], + } + + concat::fragment { "00-${name}-header": + target => $target, + order => '01', + content => "\n", + } + + if $collect_exported { + Apache::Balancermember <<| balancer_cluster == $name |>> + } + # else: the resources have been created and they introduced their + # concat fragments. We don't have to do anything about them. + + concat::fragment { "01-${name}-proxyset": + target => $target, + order => '19', + content => inline_template("<% proxy_set.each do |key, value| %> Proxyset <%= key %>=<%= value %>\n<% end %>"), + } + + concat::fragment { "01-${name}-footer": + target => $target, + order => '20', + content => "\n", + } +} diff --git a/deployment/modules/apache/manifests/balancermember.pp b/deployment/modules/apache/manifests/balancermember.pp new file mode 100644 index 000000000..c48cb1ebb --- /dev/null +++ b/deployment/modules/apache/manifests/balancermember.pp @@ -0,0 +1,52 @@ +# == Define Resource Type: apache::balancermember +# +# This type will setup a balancer member inside a listening service +# configuration block in /etc/apache/apache.cfg on the load balancer. +# currently it only has the ability to specify the instance name, url and an +# array of options. More features can be added as needed. The best way to +# implement this is to export this resource for all apache balancer member +# servers, and then collect them on the main apache load balancer. +# +# === Requirement/Dependencies: +# +# Currently requires the puppetlabs/concat module on the Puppet Forge and +# uses storeconfigs on the Puppet Master to export/collect resources +# from all balancer members. +# +# === Parameters +# +# [*name*] +# The title of the resource is arbitrary and only utilized in the concat +# fragment name. +# +# [*balancer_cluster*] +# The apache service's instance name (or, the title of the apache::balancer +# resource). This must match up with a declared apache::balancer resource. +# +# [*url*] +# The url used to contact the balancer member server. +# +# [*options*] +# An array of options to be specified after the url. +# +# === Examples +# +# Exporting the resource for a balancer member: +# +# @@apache::balancermember { 'apache': +# balancer_cluster => 'puppet00', +# url => "ajp://${::fqdn}:8009" +# options => ['ping=5', 'disablereuse=on', 'retry=5', 'ttl=120'], +# } +# +define apache::balancermember( + $balancer_cluster, + $url = "http://${::fqdn}/", + $options = [], +) { + + concat::fragment { "BalancerMember ${url}": + target => "${::apache::params::confd_dir}/balancer_${balancer_cluster}.conf", + content => inline_template(" BalancerMember ${url} <%= @options.join ' ' %>\n"), + } +} diff --git a/deployment/modules/apache/manifests/default_mods.pp b/deployment/modules/apache/manifests/default_mods.pp new file mode 100644 index 000000000..3d4b22c7e --- /dev/null +++ b/deployment/modules/apache/manifests/default_mods.pp @@ -0,0 +1,73 @@ +class apache::default_mods ( + $all = true, + $mods = undef, +) { + # These are modules required to run the default configuration. + # They are not configurable at this time, so we just include + # them to make sure it works. + case $::osfamily { + 'redhat': { + apache::mod { 'log_config': } + } + default: {} + } + apache::mod { 'authz_host': } + + # The rest of the modules only get loaded if we want all modules enabled + if $all { + case $::osfamily { + 'debian': { + include apache::mod::reqtimeout + } + 'redhat': { + include apache::mod::cache + include apache::mod::mime_magic + include apache::mod::vhost_alias + apache::mod { 'actions': } + apache::mod { 'auth_digest': } + apache::mod { 'authn_alias': } + apache::mod { 'authn_anon': } + apache::mod { 'authn_dbm': } + apache::mod { 'authn_default': } + apache::mod { 'authz_dbm': } + apache::mod { 'authz_owner': } + apache::mod { 'expires': } + apache::mod { 'ext_filter': } + apache::mod { 'include': } + apache::mod { 'logio': } + apache::mod { 'rewrite': } + apache::mod { 'speling': } + apache::mod { 'substitute': } + apache::mod { 'suexec': } + apache::mod { 'usertrack': } + apache::mod { 'version': } + } + default: {} + } + case $apache::mpm_module { + 'prefork': { + include apache::mod::cgi + } + 'worker': { + include apache::mod::cgid + } + } + include apache::mod::alias + include apache::mod::autoindex + include apache::mod::dav + include apache::mod::dav_fs + include apache::mod::deflate + include apache::mod::dir + include apache::mod::mime + include apache::mod::negotiation + include apache::mod::setenvif + apache::mod { 'auth_basic': } + apache::mod { 'authn_file': } + apache::mod { 'authz_default': } + apache::mod { 'authz_groupfile': } + apache::mod { 'authz_user': } + apache::mod { 'env': } + } elsif $mods { + apache::default_mods::load { $mods: } + } +} diff --git a/deployment/modules/apache/manifests/default_mods/load.pp b/deployment/modules/apache/manifests/default_mods/load.pp new file mode 100644 index 000000000..ae2f76e64 --- /dev/null +++ b/deployment/modules/apache/manifests/default_mods/load.pp @@ -0,0 +1,8 @@ +# private define +define apache::default_mods::load ($module = $title) { + if defined("apache::mod::${module}") { + include "apache::mod::${module}" + } else { + apache::mod { $module: } + } +} diff --git a/deployment/modules/apache/manifests/dev.pp b/deployment/modules/apache/manifests/dev.pp new file mode 100644 index 000000000..ea86adae4 --- /dev/null +++ b/deployment/modules/apache/manifests/dev.pp @@ -0,0 +1,8 @@ +class apache::dev { + include apache::params + $packages = $apache::params::dev_packages + package { $packages: + ensure => present, + require => Package['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/init.pp b/deployment/modules/apache/manifests/init.pp new file mode 100644 index 000000000..d0cb3148a --- /dev/null +++ b/deployment/modules/apache/manifests/init.pp @@ -0,0 +1,258 @@ +# Class: apache +# +# This class installs Apache +# +# Parameters: +# +# Actions: +# - Install Apache +# - Manage Apache service +# +# Requires: +# +# Sample Usage: +# +class apache ( + $default_mods = true, + $default_vhost = true, + $default_ssl_vhost = false, + $default_ssl_cert = $apache::params::default_ssl_cert, + $default_ssl_key = $apache::params::default_ssl_key, + $default_ssl_chain = undef, + $default_ssl_ca = undef, + $default_ssl_crl_path = undef, + $default_ssl_crl = undef, + $service_enable = true, + $purge_configs = true, + $purge_vdir = false, + $serveradmin = 'root@localhost', + $sendfile = false, + $error_documents = false, + $httpd_dir = $apache::params::httpd_dir, + $confd_dir = $apache::params::confd_dir, + $vhost_dir = $apache::params::vhost_dir, + $vhost_enable_dir = $apache::params::vhost_enable_dir, + $mod_dir = $apache::params::mod_dir, + $mod_enable_dir = $apache::params::mod_enable_dir, + $mpm_module = $apache::params::mpm_module, + $conf_template = $apache::params::conf_template, + $servername = $apache::params::servername, + $user = $apache::params::user, + $group = $apache::params::group, + $keepalive = $apache::params::keepalive, + $keepalive_timeout = $apache::params::keepalive_timeout, + $logroot = $apache::params::logroot, + $ports_file = $apache::params::ports_file, +) inherits apache::params { + + package { 'httpd': + ensure => installed, + name => $apache::params::apache_name, + notify => Class['Apache::Service'], + } + + validate_bool($default_vhost) + # true/false is sufficient for both ensure and enable + validate_bool($service_enable) + if $mpm_module { + validate_re($mpm_module, '(prefork|worker|itk)') + } + + # declare the web server user and group + # Note: requiring the package means the package ought to create them and not puppet + group { $group: + ensure => present, + require => Package['httpd'] + } + + user { $user: + ensure => present, + gid => $group, + require => Package['httpd'], + } + + class { 'apache::service': + service_enable => $service_enable, + } + + # Deprecated backwards-compatibility + if $purge_vdir { + warning('Class[\'apache\'] parameter purge_vdir is deprecated in favor of purge_configs') + $purge_confd = $purge_vdir + } else { + $purge_confd = $purge_configs + } + + Exec { + path => '/bin:/sbin:/usr/bin:/usr/sbin', + } + + exec { "mkdir ${confd_dir}": + creates => $confd_dir, + require => Package['httpd'], + } + file { $confd_dir: + ensure => directory, + recurse => true, + purge => $purge_confd, + notify => Class['Apache::Service'], + require => Package['httpd'], + } + + if ! defined(File[$mod_dir]) { + exec { "mkdir ${mod_dir}": + creates => $mod_dir, + require => Package['httpd'], + } + file { $mod_dir: + ensure => directory, + recurse => true, + purge => $purge_configs, + notify => Class['Apache::Service'], + require => Package['httpd'], + } + } + + if $mod_enable_dir and ! defined(File[$mod_enable_dir]) { + $mod_load_dir = $mod_enable_dir + exec { "mkdir ${mod_enable_dir}": + creates => $mod_enable_dir, + require => Package['httpd'], + } + file { $mod_enable_dir: + ensure => directory, + recurse => true, + purge => $purge_configs, + notify => Class['Apache::Service'], + require => Package['httpd'], + } + } else { + $mod_load_dir = $mod_dir + } + + if ! defined(File[$vhost_dir]) { + exec { "mkdir ${vhost_dir}": + creates => $vhost_dir, + require => Package['httpd'], + } + file { $vhost_dir: + ensure => directory, + recurse => true, + purge => $purge_configs, + notify => Class['Apache::Service'], + require => Package['httpd'], + } + } + + if $vhost_enable_dir and ! defined(File[$vhost_enable_dir]) { + $vhost_load_dir = $vhost_enable_dir + exec { "mkdir ${vhost_load_dir}": + creates => $vhost_load_dir, + require => Package['httpd'], + } + file { $vhost_enable_dir: + ensure => directory, + recurse => true, + purge => $purge_configs, + notify => Class['Apache::Service'], + require => Package['httpd'], + } + } else { + $vhost_load_dir = $vhost_dir + } + + concat { $ports_file: + owner => 'root', + group => 'root', + mode => '0644', + notify => Class['Apache::Service'], + require => Package['httpd'], + } + concat::fragment { 'Apache ports header': + target => $ports_file, + content => template('apache/ports_header.erb') + } + + if $apache::params::conf_dir and $apache::params::conf_file { + case $::osfamily { + 'debian': { + $docroot = '/var/www' + $pidfile = '${APACHE_PID_FILE}' + $error_log = 'error.log' + $error_documents_path = '/usr/share/apache2/error' + $scriptalias = '/usr/lib/cgi-bin' + $access_log_file = 'access.log' + } + 'redhat': { + $docroot = '/var/www/html' + $pidfile = 'run/httpd.pid' + $error_log = 'error_log' + $error_documents_path = '/var/www/error' + $scriptalias = '/var/www/cgi-bin' + $access_log_file = 'access_log' + } + default: { + fail("Unsupported osfamily ${::osfamily}") + } + } + # Template uses: + # - $httpd_dir + # - $pidfile + # - $user + # - $group + # - $logroot + # - $error_log + # - $sendfile + # - $mod_dir + # - $ports_file + # - $confd_dir + # - $vhost_dir + # - $error_documents + # - $error_documents_path + # - $keepalive + # - $keepalive_timeout + file { "${apache::params::conf_dir}/${apache::params::conf_file}": + ensure => file, + content => template($conf_template), + notify => Class['Apache::Service'], + require => Package['httpd'], + } + + # preserve back-wards compatibility to the times when default_mods was + # only a boolean value. Now it can be an array (too) + if is_array($default_mods) { + class { 'apache::default_mods': + all => false, + mods => $default_mods, + } + } else { + class { 'apache::default_mods': + all => $default_mods, + } + } + if $mpm_module { + class { "apache::mod::${mpm_module}": } + } + if $default_vhost { + apache::vhost { 'default': + port => 80, + docroot => $docroot, + scriptalias => $scriptalias, + serveradmin => $serveradmin, + access_log_file => $access_log_file, + priority => '15', + } + } + if $default_ssl_vhost { + apache::vhost { 'default-ssl': + port => 443, + ssl => true, + docroot => $docroot, + scriptalias => $scriptalias, + serveradmin => $serveradmin, + access_log_file => "ssl_${access_log_file}", + priority => '15', + } + } + } +} diff --git a/deployment/modules/apache/manifests/listen.pp b/deployment/modules/apache/manifests/listen.pp new file mode 100644 index 000000000..57982ba26 --- /dev/null +++ b/deployment/modules/apache/manifests/listen.pp @@ -0,0 +1,10 @@ +define apache::listen { + $listen_addr_port = $name + include apache::params + + # Template uses: $listen_addr_port + concat::fragment { "Listen ${listen_addr_port}": + target => $apache::params::ports_file, + content => template('apache/listen.erb'), + } +} diff --git a/deployment/modules/apache/manifests/mod.pp b/deployment/modules/apache/manifests/mod.pp new file mode 100644 index 000000000..ea9cc3c87 --- /dev/null +++ b/deployment/modules/apache/manifests/mod.pp @@ -0,0 +1,93 @@ +define apache::mod ( + $package = undef, + $lib = undef +) { + if ! defined(Class['apache']) { + fail('You must include the apache base class before using any apache defined resources') + } + + $mod = $name + #include apache #This creates duplicate resources in rspec-puppet + $lib_path = $apache::params::lib_path + $mod_dir = $apache::mod_dir + + # Determine if we have special lib + $mod_libs = $apache::params::mod_libs + $mod_lib = $mod_libs[$mod] # 2.6 compatibility hack + if $lib { + $lib_REAL = $lib + } elsif $mod_lib { + $lib_REAL = $mod_lib + } else { + $lib_REAL = "mod_${mod}.so" + } + + # Determine if we have a package + $mod_packages = $apache::params::mod_packages + $mod_package = $mod_packages[$mod] # 2.6 compatibility hack + if $package { + $package_REAL = $package + } elsif "${mod_package}" { + $package_REAL = $mod_package + } + if $package_REAL { + # $package_REAL may be an array + package { $package_REAL: + ensure => present, + require => Package['httpd'], + before => File["${mod_dir}/${mod}.load"], + } + } + + file { "${mod}.load": + ensure => file, + path => "${mod_dir}/${mod}.load", + owner => 'root', + group => 'root', + mode => '0644', + content => "LoadModule ${mod}_module ${lib_path}/${lib_REAL}\n", + require => [ + Package['httpd'], + Exec["mkdir ${mod_dir}"], + ], + before => File[$mod_dir], + notify => Service['httpd'], + } + + if $::osfamily == 'Debian' { + $enable_dir = $apache::mod_enable_dir + file{ "${mod}.load symlink": + ensure => link, + path => "${enable_dir}/${mod}.load", + target => "${mod_dir}/${mod}.load", + owner => 'root', + group => 'root', + mode => '0644', + require => [ + File["${mod}.load"], + Exec["mkdir ${enable_dir}"], + ], + before => File[$enable_dir], + notify => Service['httpd'], + } + # Each module may have a .conf file as well, which should be + # defined in the class apache::mod::module + # Some modules do not require this file. + if defined(File["${mod}.conf"]) { + file{ "${mod}.conf symlink": + ensure => link, + path => "${enable_dir}/${mod}.conf", + target => "${mod_dir}/${mod}.conf", + owner => 'root', + group => 'root', + mode => '0644', + require => [ + File["${mod}.conf"], + Exec["mkdir ${enable_dir}"], + ], + before => File[$enable_dir], + notify => Service['httpd'], + } + } + } +} diff --git a/deployment/modules/apache/manifests/mod/alias.pp b/deployment/modules/apache/manifests/mod/alias.pp new file mode 100644 index 000000000..2af73725b --- /dev/null +++ b/deployment/modules/apache/manifests/mod/alias.pp @@ -0,0 +1,16 @@ +class apache::mod::alias { + $icons_path = $::osfamily ? { + 'debian' => '/usr/share/apache2/icons', + 'redhat' => '/var/www/icons', + } + apache::mod { 'alias': } + # Template uses $icons_path + file { 'alias.conf': + ensure => file, + path => "${apache::mod_dir}/alias.conf", + content => template('apache/mod/alias.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/auth_basic.pp b/deployment/modules/apache/manifests/mod/auth_basic.pp new file mode 100644 index 000000000..8c613eef7 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/auth_basic.pp @@ -0,0 +1,3 @@ +class apache::mod::auth_basic { + apache::mod { 'auth_basic': } +} diff --git a/deployment/modules/apache/manifests/mod/auth_kerb.pp b/deployment/modules/apache/manifests/mod/auth_kerb.pp new file mode 100644 index 000000000..76c2de5b7 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/auth_kerb.pp @@ -0,0 +1,5 @@ +class apache::mod::auth_kerb { + apache::mod { 'auth_kerb': } +} + + diff --git a/deployment/modules/apache/manifests/mod/autoindex.pp b/deployment/modules/apache/manifests/mod/autoindex.pp new file mode 100644 index 000000000..85b4278ef --- /dev/null +++ b/deployment/modules/apache/manifests/mod/autoindex.pp @@ -0,0 +1,12 @@ +class apache::mod::autoindex { + apache::mod { 'autoindex': } + # Template uses no variables + file { 'autoindex.conf': + ensure => file, + path => "${apache::mod_dir}/autoindex.conf", + content => template('apache/mod/autoindex.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/cache.pp b/deployment/modules/apache/manifests/mod/cache.pp new file mode 100644 index 000000000..26d71bd06 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/cache.pp @@ -0,0 +1,3 @@ +class apache::mod::cache { + apache::mod { 'cache': } +} diff --git a/deployment/modules/apache/manifests/mod/cgi.pp b/deployment/modules/apache/manifests/mod/cgi.pp new file mode 100644 index 000000000..2ad368a0e --- /dev/null +++ b/deployment/modules/apache/manifests/mod/cgi.pp @@ -0,0 +1,4 @@ +class apache::mod::cgi { + Class['apache::mod::prefork'] -> Class['apache::mod::cgi'] + apache::mod { 'cgi': } +} diff --git a/deployment/modules/apache/manifests/mod/cgid.pp b/deployment/modules/apache/manifests/mod/cgid.pp new file mode 100644 index 000000000..1a0a08249 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/cgid.pp @@ -0,0 +1,22 @@ +class apache::mod::cgid { + Class['apache::mod::worker'] -> Class['apache::mod::cgid'] + + # Debian specifies it's cgid sock path, but RedHat uses the default value + # with no config file + $cgisock_path = $::osfamily ? { + 'debian' => '${APACHE_RUN_DIR}/cgisock', + default => undef, + } + apache::mod { 'cgid': } + if $cgisock_path { + # Template uses $cgisock_path + file { 'cgid.conf': + ensure => file, + path => "${apache::mod_dir}/cgid.conf", + content => template('apache/mod/cgid.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } + } +} diff --git a/deployment/modules/apache/manifests/mod/dav.pp b/deployment/modules/apache/manifests/mod/dav.pp new file mode 100644 index 000000000..06aa087e3 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/dav.pp @@ -0,0 +1,3 @@ +class apache::mod::dav { + apache::mod { 'dav': } +} diff --git a/deployment/modules/apache/manifests/mod/dav_fs.pp b/deployment/modules/apache/manifests/mod/dav_fs.pp new file mode 100644 index 000000000..ab78408f7 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/dav_fs.pp @@ -0,0 +1,19 @@ +class apache::mod::dav_fs { + $dav_lock = $::osfamily ? { + 'debian' => '${APACHE_LOCK_DIR}/DAVLock', + default => '/var/lib/dav/lockdb', + } + + Class['apache::mod::dav'] -> Class['apache::mod::dav_fs'] + apache::mod { 'dav_fs': } + + # Template uses: $dav_lock + file { 'dav_fs.conf': + ensure => file, + path => "${apache::mod_dir}/dav_fs.conf", + content => template('apache/mod/dav_fs.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/dav_svn.pp b/deployment/modules/apache/manifests/mod/dav_svn.pp new file mode 100644 index 000000000..76e0d885e --- /dev/null +++ b/deployment/modules/apache/manifests/mod/dav_svn.pp @@ -0,0 +1,4 @@ +class apache::mod::dav_svn { + include apache::mod::dav + apache::mod { 'dav_svn': } +} diff --git a/deployment/modules/apache/manifests/mod/deflate.pp b/deployment/modules/apache/manifests/mod/deflate.pp new file mode 100644 index 000000000..97d1fdd8a --- /dev/null +++ b/deployment/modules/apache/manifests/mod/deflate.pp @@ -0,0 +1,12 @@ +class apache::mod::deflate { + apache::mod { 'deflate': } + # Template uses no variables + file { 'deflate.conf': + ensure => file, + path => "${apache::mod_dir}/deflate.conf", + content => template('apache/mod/deflate.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/dev.pp b/deployment/modules/apache/manifests/mod/dev.pp new file mode 100644 index 000000000..b5d146fbe --- /dev/null +++ b/deployment/modules/apache/manifests/mod/dev.pp @@ -0,0 +1,5 @@ +class apache::mod::dev { + # Development packages are not apache modules + warning('apache::mod::dev is deprecated; please use apache::dev') + include apache::dev +} diff --git a/deployment/modules/apache/manifests/mod/dir.pp b/deployment/modules/apache/manifests/mod/dir.pp new file mode 100644 index 000000000..39543e116 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/dir.pp @@ -0,0 +1,21 @@ +# Note: this sets the global DirectoryIndex directive, it may be necessary to consider being able to modify the apache::vhost to declare DirectoryIndex statements in a vhost configuration +# Parameters: +# - $indexes provides a string for the DirectoryIndex directive http://httpd.apache.org/docs/current/mod/mod_dir.html#directoryindex +class apache::mod::dir ( + $dir = 'public_html', + $indexes = ['index.html','index.html.var','index.cgi','index.pl','index.php','index.xhtml'], +) { + validate_array($indexes) + apache::mod { 'dir': } + + # Template uses + # - $indexes + file { 'dir.conf': + ensure => file, + path => "${apache::mod_dir}/dir.conf", + content => template('apache/mod/dir.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/disk_cache.pp b/deployment/modules/apache/manifests/mod/disk_cache.pp new file mode 100644 index 000000000..dd3e0f093 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/disk_cache.pp @@ -0,0 +1,19 @@ +class apache::mod::disk_cache { + $cache_root = $::osfamily ? { + 'debian' => '/var/cache/apache2/mod_disk_cache', + 'redhat' => '/var/cache/mod_proxy', + } + Class['apache::mod::proxy'] -> Class['apache::mod::disk_cache'] + Class['apache::mod::cache'] -> Class['apache::mod::disk_cache'] + + apache::mod { 'disk_cache': } + # Template uses $cache_proxy + file { 'disk_cache.conf': + ensure => file, + path => "${apache::mod_dir}/disk_cache.conf", + content => template('apache/mod/disk_cache.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/fcgid.pp b/deployment/modules/apache/manifests/mod/fcgid.pp new file mode 100644 index 000000000..4c777701e --- /dev/null +++ b/deployment/modules/apache/manifests/mod/fcgid.pp @@ -0,0 +1,3 @@ +class apache::mod::fcgid { + apache::mod { 'fcgid': } +} diff --git a/deployment/modules/apache/manifests/mod/headers.pp b/deployment/modules/apache/manifests/mod/headers.pp new file mode 100644 index 000000000..5ff9887b1 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/headers.pp @@ -0,0 +1,3 @@ +class apache::mod::headers { + apache::mod { 'headers': } +} \ No newline at end of file diff --git a/deployment/modules/apache/manifests/mod/info.pp b/deployment/modules/apache/manifests/mod/info.pp new file mode 100644 index 000000000..b76e1efb2 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/info.pp @@ -0,0 +1,14 @@ +class apache::mod::info ( + $allow_from = ['127.0.0.1','::1'], +){ + apache::mod { 'info': } + # Template uses $allow_from + file { 'info.conf': + ensure => file, + path => "${apache::mod_dir}/info.conf", + content => template('apache/mod/info.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/itk.pp b/deployment/modules/apache/manifests/mod/itk.pp new file mode 100644 index 000000000..a2f4b5c70 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/itk.pp @@ -0,0 +1,53 @@ +class apache::mod::itk ( + $startservers = '8', + $minspareservers = '5', + $maxspareservers = '20', + $serverlimit = '256', + $maxclients = '256', + $maxrequestsperchild = '4000', +) { + if defined(Class['apache::mod::prefork']) { + fail('May not include both apache::mod::itk and apache::mod::prefork on the same node') + } + if defined(Class['apache::mod::worker']) { + fail('May not include both apache::mod::itk and apache::mod::worker on the same node') + } + File { + owner => 'root', + group => $apache::params::root_group, + mode => '0644', + } + + # Template uses: + # - $startservers + # - $minspareservers + # - $maxspareservers + # - $serverlimit + # - $maxclients + # - $maxrequestsperchild + file { "${apache::mod_dir}/itk.conf": + ensure => file, + content => template('apache/mod/itk.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } + + case $::osfamily { + 'debian' : { + file { "${apache::mod_enable_dir}/itk.conf": + ensure => link, + target => "${apache::mod_dir}/itk.conf", + require => Exec["mkdir ${apache::mod_enable_dir}"], + before => File[$apache::mod_enable_dir], + notify => Service['httpd'], + } + package { 'apache2-mpm-itk': + ensure => present, + } + } + default: { + fail("Unsupported osfamily ${::osfamily}") + } + } +} diff --git a/deployment/modules/apache/manifests/mod/ldap.pp b/deployment/modules/apache/manifests/mod/ldap.pp new file mode 100644 index 000000000..097622c51 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/ldap.pp @@ -0,0 +1,12 @@ +class apache::mod::ldap { + apache::mod { 'ldap': } + # Template uses no variables + file { 'ldap.conf': + ensure => file, + path => "${apache::mod_dir}/ldap.conf", + content => template('apache/mod/ldap.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/mime.pp b/deployment/modules/apache/manifests/mod/mime.pp new file mode 100644 index 000000000..ba62ebc63 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/mime.pp @@ -0,0 +1,12 @@ +class apache::mod::mime { + apache::mod { 'mime': } + # Template uses no variables + file { 'mime.conf': + ensure => file, + path => "${apache::mod_dir}/mime.conf", + content => template('apache/mod/mime.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/mime_magic.pp b/deployment/modules/apache/manifests/mod/mime_magic.pp new file mode 100644 index 000000000..c0ff0a7f6 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/mime_magic.pp @@ -0,0 +1,12 @@ +class apache::mod::mime_magic { + apache::mod { 'mime_magic': } + # Template uses no variables + file { 'mime_magic.conf': + ensure => file, + path => "${apache::mod_dir}/mime_magic.conf", + content => template('apache/mod/mime_magic.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/mpm_event.pp b/deployment/modules/apache/manifests/mod/mpm_event.pp new file mode 100644 index 000000000..92e558e17 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/mpm_event.pp @@ -0,0 +1,11 @@ +class apache::mod::mpm_event { + # Template uses no variables + file { 'mpm_event.conf': + ensure => file, + path => "${apache::mod_dir}/mpm_event.conf", + content => template('apache/mod/mpm_event.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/negotiation.pp b/deployment/modules/apache/manifests/mod/negotiation.pp new file mode 100644 index 000000000..e10c4921d --- /dev/null +++ b/deployment/modules/apache/manifests/mod/negotiation.pp @@ -0,0 +1,12 @@ +class apache::mod::negotiation { + apache::mod { 'negotiation': } + # Template uses no variables + file { 'negotiation.conf': + ensure => file, + path => "${apache::mod_dir}/negotiation.conf", + content => template('apache/mod/negotiation.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/passenger.pp b/deployment/modules/apache/manifests/mod/passenger.pp new file mode 100644 index 000000000..a002d1368 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/passenger.pp @@ -0,0 +1,30 @@ +class apache::mod::passenger ( + $passenger_high_performance = undef, + $passenger_pool_idle_time = undef, + $passenger_max_requests = undef, + $passenger_stat_throttle_rate = undef, + $rack_autodetect = undef, + $rails_autodetect = undef, + $passenger_root = $apache::params::passenger_root, + $passenger_ruby = $apache::params::passenger_ruby, + $passenger_max_pool_size = undef, +) { + apache::mod { 'passenger': } + # Template uses: + # - $passenger_root + # - $passenger_ruby + # - $passenger_max_pool_size + # - $passenger_high_performance + # - $passenger_max_requests + # - $passenger_stat_throttle_rate + # - $rack_autodetect + # - $rails_autodetect + file { 'passenger.conf': + ensure => file, + path => "${apache::mod_dir}/passenger.conf", + content => template('apache/mod/passenger.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/perl.pp b/deployment/modules/apache/manifests/mod/perl.pp new file mode 100644 index 000000000..65832a034 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/perl.pp @@ -0,0 +1,3 @@ +class apache::mod::perl { + apache::mod { 'perl': } +} diff --git a/deployment/modules/apache/manifests/mod/php.pp b/deployment/modules/apache/manifests/mod/php.pp new file mode 100644 index 000000000..f232753aa --- /dev/null +++ b/deployment/modules/apache/manifests/mod/php.pp @@ -0,0 +1,17 @@ +class apache::mod::php { + if ! defined(Class['apache::mod::prefork']) { + fail('apache::mod::php requires apache::mod::prefork; please enable mpm_module => \'prefork\' on Class[\'apache\']') + } + apache::mod { 'php5': } + file { 'php5.conf': + ensure => file, + path => "${apache::mod_dir}/php5.conf", + content => template('apache/mod/php5.conf.erb'), + require => [ + Class['apache::mod::prefork'], + Exec["mkdir ${apache::mod_dir}"], + ], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/prefork.pp b/deployment/modules/apache/manifests/mod/prefork.pp new file mode 100644 index 000000000..5c6a7def9 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/prefork.pp @@ -0,0 +1,63 @@ +class apache::mod::prefork ( + $startservers = '8', + $minspareservers = '5', + $maxspareservers = '20', + $serverlimit = '256', + $maxclients = '256', + $maxrequestsperchild = '4000', +) { + if defined(Class['apache::mod::itk']) { + fail('May not include both apache::mod::itk and apache::mod::prefork on the same node') + } + if defined(Class['apache::mod::worker']) { + fail('May not include both apache::mod::worker and apache::mod::prefork on the same node') + } + File { + owner => 'root', + group => 'root', + mode => '0644', + } + + # Template uses: + # - $startservers + # - $minspareservers + # - $maxspareservers + # - $serverlimit + # - $maxclients + # - $maxrequestsperchild + file { "${apache::mod_dir}/prefork.conf": + ensure => file, + content => template('apache/mod/prefork.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } + + case $::osfamily { + 'redhat': { + file_line { '/etc/sysconfig/httpd prefork enable': + ensure => present, + path => '/etc/sysconfig/httpd', + line => '#HTTPD=/usr/sbin/httpd.worker', + match => '#?HTTPD=/usr/sbin/httpd.worker', + require => Package['httpd'], + notify => Service['httpd'], + } + } + 'debian': { + file { "${apache::mod_enable_dir}/prefork.conf": + ensure => link, + target => "${apache::mod_dir}/prefork.conf", + require => Exec["mkdir ${apache::mod_enable_dir}"], + before => File[$apache::mod_enable_dir], + notify => Service['httpd'], + } + package { 'apache2-mpm-prefork': + ensure => present, + } + } + default: { + fail("Unsupported osfamily ${::osfamily}") + } + } +} diff --git a/deployment/modules/apache/manifests/mod/proxy.pp b/deployment/modules/apache/manifests/mod/proxy.pp new file mode 100644 index 000000000..71b766bcb --- /dev/null +++ b/deployment/modules/apache/manifests/mod/proxy.pp @@ -0,0 +1,15 @@ +class apache::mod::proxy ( + $proxy_requests = 'Off', + $allow_from = ['127.0.0.1','::1'], +) { + apache::mod { 'proxy': } + # Template uses $proxy_requests + file { 'proxy.conf': + ensure => file, + path => "${apache::mod_dir}/proxy.conf", + content => template('apache/mod/proxy.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/proxy_balancer.pp b/deployment/modules/apache/manifests/mod/proxy_balancer.pp new file mode 100644 index 000000000..51d8e031d --- /dev/null +++ b/deployment/modules/apache/manifests/mod/proxy_balancer.pp @@ -0,0 +1,5 @@ +class apache::mod::proxy_balancer { + Class['apache::mod::proxy'] -> Class['apache::mod::proxy_balancer'] + Class['apache::mod::proxy_http'] -> Class['apache::mod::proxy_balancer'] + apache::mod { 'proxy_balancer': } +} diff --git a/deployment/modules/apache/manifests/mod/proxy_html.pp b/deployment/modules/apache/manifests/mod/proxy_html.pp new file mode 100644 index 000000000..ab2575731 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/proxy_html.pp @@ -0,0 +1,25 @@ +class apache::mod::proxy_html { + Class['apache::mod::proxy'] -> Class['apache::mod::proxy_html'] + Class['apache::mod::proxy_http'] -> Class['apache::mod::proxy_html'] + apache::mod { 'proxy_html': } + case $::osfamily { + 'RedHat': { + apache::mod { 'xml2enc': } + } + 'Debian': { + $proxy_html_loadfiles = $apache::params::distrelease ? { + '6' => '/usr/lib/libxml2.so.2', + default => "/usr/lib/${::hardwaremodel}-linux-gnu/libxml2.so.2", + } + } + } + # Template uses $icons_path + file { 'proxy_html.conf': + ensure => file, + path => "${apache::mod_dir}/proxy_html.conf", + content => template('apache/mod/proxy_html.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/proxy_http.pp b/deployment/modules/apache/manifests/mod/proxy_http.pp new file mode 100644 index 000000000..5b83df2c5 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/proxy_http.pp @@ -0,0 +1,4 @@ +class apache::mod::proxy_http { + Class['apache::mod::proxy'] -> Class['apache::mod::proxy_http'] + apache::mod { 'proxy_http': } +} diff --git a/deployment/modules/apache/manifests/mod/python.pp b/deployment/modules/apache/manifests/mod/python.pp new file mode 100644 index 000000000..8158b7e8a --- /dev/null +++ b/deployment/modules/apache/manifests/mod/python.pp @@ -0,0 +1,5 @@ +class apache::mod::python { + apache::mod { 'python': } +} + + diff --git a/deployment/modules/apache/manifests/mod/reqtimeout.pp b/deployment/modules/apache/manifests/mod/reqtimeout.pp new file mode 100644 index 000000000..b763b3785 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/reqtimeout.pp @@ -0,0 +1,12 @@ +class apache::mod::reqtimeout { + apache::mod { 'reqtimeout': } + # Template uses no variables + file { 'reqtimeout.conf': + ensure => file, + path => "${apache::mod_dir}/reqtimeout.conf", + content => template('apache/mod/reqtimeout.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/rewrite.pp b/deployment/modules/apache/manifests/mod/rewrite.pp new file mode 100644 index 000000000..147faab99 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/rewrite.pp @@ -0,0 +1,4 @@ +class apache::mod::rewrite { + include apache::params + apache::mod { 'rewrite': } +} diff --git a/deployment/modules/apache/manifests/mod/setenvif.pp b/deployment/modules/apache/manifests/mod/setenvif.pp new file mode 100644 index 000000000..1b60edde8 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/setenvif.pp @@ -0,0 +1,12 @@ +class apache::mod::setenvif { + apache::mod { 'setenvif': } + # Template uses no variables + file { 'setenvif.conf': + ensure => file, + path => "${apache::mod_dir}/setenvif.conf", + content => template('apache/mod/setenvif.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/ssl.pp b/deployment/modules/apache/manifests/mod/ssl.pp new file mode 100644 index 000000000..ba183e1dd --- /dev/null +++ b/deployment/modules/apache/manifests/mod/ssl.pp @@ -0,0 +1,23 @@ +class apache::mod::ssl ( + $ssl_compression = false, +) { + $session_cache = $::osfamily ? { + 'debian' => '${APACHE_RUN_DIR}/ssl_scache(512000)', + 'redhat' => '/var/cache/mod_ssl/scache(512000)', + } + $ssl_mutex = $::osfamily ? { + 'debian' => 'file:${APACHE_RUN_DIR}/ssl_mutex', + 'redhat' => 'default', + } + apache::mod { 'ssl': } + + # Template uses $ssl_compression, $session_cache, $ssl_mutex + file { 'ssl.conf': + ensure => file, + path => "${apache::mod_dir}/ssl.conf", + content => template('apache/mod/ssl.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/status.pp b/deployment/modules/apache/manifests/mod/status.pp new file mode 100644 index 000000000..084d84eea --- /dev/null +++ b/deployment/modules/apache/manifests/mod/status.pp @@ -0,0 +1,12 @@ +class apache::mod::status { + apache::mod { 'status': } + # Template uses no variables + file { 'status.conf': + ensure => file, + path => "${apache::mod_dir}/status.conf", + content => template('apache/mod/status.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/suphp.pp b/deployment/modules/apache/manifests/mod/suphp.pp new file mode 100644 index 000000000..26473cf2e --- /dev/null +++ b/deployment/modules/apache/manifests/mod/suphp.pp @@ -0,0 +1,14 @@ +class apache::mod::suphp ( +){ + apache::mod { 'suphp': } + + file {'suphp.conf': + ensure => file, + path => "${apache::mod_dir}/suphp.conf", + content => template('apache/mod/suphp.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'] + } +} + diff --git a/deployment/modules/apache/manifests/mod/userdir.pp b/deployment/modules/apache/manifests/mod/userdir.pp new file mode 100644 index 000000000..69f4044fd --- /dev/null +++ b/deployment/modules/apache/manifests/mod/userdir.pp @@ -0,0 +1,17 @@ +class apache::mod::userdir ( + $home = '/home', + $dir = 'public_html', + $disable_root = true, +) { + apache::mod { 'userdir': } + + # Template uses $home, $dir, $disable_root + file { 'userdir.conf': + ensure => file, + path => "${apache::mod_dir}/userdir.conf", + content => template('apache/mod/userdir.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } +} diff --git a/deployment/modules/apache/manifests/mod/vhost_alias.pp b/deployment/modules/apache/manifests/mod/vhost_alias.pp new file mode 100644 index 000000000..ec40447a3 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/vhost_alias.pp @@ -0,0 +1,3 @@ +class apache::mod::vhost_alias { + apache::mod { 'vhost_alias': } +} diff --git a/deployment/modules/apache/manifests/mod/worker.pp b/deployment/modules/apache/manifests/mod/worker.pp new file mode 100644 index 000000000..3966ed23d --- /dev/null +++ b/deployment/modules/apache/manifests/mod/worker.pp @@ -0,0 +1,64 @@ +class apache::mod::worker ( + $startservers = '2', + $maxclients = '150', + $minsparethreads = '25', + $maxsparethreads = '75', + $threadsperchild = '25', + $maxrequestsperchild = '0', + $serverlimit = '25', +) { + if defined(Class['apache::mod::itk']) { + fail('May not include both apache::mod::worker and apache::mod::itk on the same node') + } + if defined(Class['apache::mod::prefork']) { + fail('May not include both apache::mod::worker and apache::mod::prefork on the same node') + } + File { + owner => 'root', + group => 'root', + mode => '0644', + } + + # Template uses: + # - $startservers + # - $maxclients + # - $minsparethreads + # - $maxsparethreads + # - $threadsperchild + # - $maxrequestsperchild + # - $serverlimit + file { "${apache::mod_dir}/worker.conf": + ensure => file, + content => template('apache/mod/worker.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'], + } + + case $::osfamily { + 'redhat': { + file_line { '/etc/sysconfig/httpd worker enable': + ensure => present, + path => '/etc/sysconfig/httpd', + line => 'HTTPD=/usr/sbin/httpd.worker', + match => '#?HTTPD=/usr/sbin/httpd.worker', + notify => Service['httpd'], + } + } + 'debian': { + file { "${apache::mod_enable_dir}/worker.conf": + ensure => link, + target => "${apache::mod_dir}/worker.conf", + require => Exec["mkdir ${apache::mod_enable_dir}"], + before => File[$apache::mod_enable_dir], + notify => Service['httpd'], + } + package { 'apache2-mpm-worker': + ensure => present, + } + } + default: { + fail("Unsupported osfamily ${::osfamily}") + } + } +} diff --git a/deployment/modules/apache/manifests/mod/wsgi.pp b/deployment/modules/apache/manifests/mod/wsgi.pp new file mode 100644 index 000000000..ff12fbf24 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/wsgi.pp @@ -0,0 +1,19 @@ +class apache::mod::wsgi ( + $wsgi_socket_prefix = undef, + $wsgi_python_home = undef, +){ + apache::mod { 'wsgi': } + + # Template uses: + # - $wsgi_socket_prefix + # - $wsgi_python_home + file {'wsgi.conf': + ensure => file, + path => "${apache::mod_dir}/wsgi.conf", + content => template('apache/mod/wsgi.conf.erb'), + require => Exec["mkdir ${apache::mod_dir}"], + before => File[$apache::mod_dir], + notify => Service['httpd'] + } +} + diff --git a/deployment/modules/apache/manifests/mod/xsendfile.pp b/deployment/modules/apache/manifests/mod/xsendfile.pp new file mode 100644 index 000000000..571501a03 --- /dev/null +++ b/deployment/modules/apache/manifests/mod/xsendfile.pp @@ -0,0 +1,4 @@ +class apache::mod::xsendfile { + include apache::params + apache::mod { 'xsendfile': } +} diff --git a/deployment/modules/apache/manifests/namevirtualhost.pp b/deployment/modules/apache/manifests/namevirtualhost.pp new file mode 100644 index 000000000..edbbfe4cf --- /dev/null +++ b/deployment/modules/apache/manifests/namevirtualhost.pp @@ -0,0 +1,10 @@ +define apache::namevirtualhost { + $addr_port = $name + include apache::params + + # Template uses: $addr_port + concat::fragment { "NameVirtualHost ${addr_port}": + target => $apache::params::ports_file, + content => template('apache/namevirtualhost.erb'), + } +} diff --git a/deployment/modules/apache/manifests/params.pp b/deployment/modules/apache/manifests/params.pp new file mode 100644 index 000000000..7bf4a5fa3 --- /dev/null +++ b/deployment/modules/apache/manifests/params.pp @@ -0,0 +1,132 @@ +# Class: apache::params +# +# This class manages Apache parameters +# +# Parameters: +# - The $user that Apache runs as +# - The $group that Apache runs as +# - The $apache_name is the name of the package and service on the relevant +# distribution +# - The $php_package is the name of the package that provided PHP +# - The $ssl_package is the name of the Apache SSL package +# - The $apache_dev is the name of the Apache development libraries package +# - The $conf_contents is the contents of the Apache configuration file +# +# Actions: +# +# Requires: +# +# Sample Usage: +# +class apache::params { + # This will be 5 or 6 on RedHat, 6 or wheezy on Debian, 12 or quantal on Ubuntu, 3 on Amazon, etc. + $osr_array = split($::operatingsystemrelease,'[\/\.]') + $distrelease = $osr_array[0] + if ! $distrelease { + fail("Class['apache::params']: Unparsable \$::operatingsystemrelease: ${::operatingsystemrelease}") + } + + if($::fqdn) { + $servername = $::fqdn + } else { + $servername = $::hostname + } + + if $::osfamily == 'RedHat' or $::operatingsystem == 'amazon' { + $user = 'apache' + $group = 'apache' + $apache_name = 'httpd' + $httpd_dir = '/etc/httpd' + $conf_dir = "${httpd_dir}/conf" + $confd_dir = "${httpd_dir}/conf.d" + $mod_dir = "${httpd_dir}/conf.d" + $vhost_dir = "${httpd_dir}/conf.d" + $conf_file = 'httpd.conf' + $ports_file = "${conf_dir}/ports.conf" + $logroot = '/var/log/httpd' + $lib_path = 'modules' + $mpm_module = 'prefork' + $dev_packages = 'httpd-devel' + $default_ssl_cert = '/etc/pki/tls/certs/localhost.crt' + $default_ssl_key = '/etc/pki/tls/private/localhost.key' + $ssl_certs_dir = $distrelease ? { + '5' => '/etc/pki/tls/certs', + default => '/etc/ssl/certs', + } + $passenger_root = '/usr/share/rubygems/gems/passenger-3.0.17' + $passenger_ruby = '/usr/bin/ruby' + $suphp_addhandler = 'php5-script' + $suphp_engine = 'off' + $suphp_configpath = undef + $mod_packages = { + 'auth_kerb' => 'mod_auth_kerb', + 'fcgid' => 'mod_fcgid', + 'passenger' => 'mod_passenger', + 'perl' => 'mod_perl', + 'php5' => $distrelease ? { + '5' => 'php53', + default => 'php', + }, + 'proxy_html' => 'mod_proxy_html', + 'python' => 'mod_python', + 'shibboleth' => 'shibboleth', + 'ssl' => 'mod_ssl', + 'wsgi' => 'mod_wsgi', + 'dav_svn' => 'mod_dav_svn', + 'suphp' => 'mod_suphp', + 'xsendfile' => 'mod_xsendfile', + } + $mod_libs = { + 'php5' => 'libphp5.so', + } + $conf_template = 'apache/httpd.conf.erb' + $keepalive = 'Off' + $keepalive_timeout = 15 + } elsif $::osfamily == 'Debian' { + $user = 'www-data' + $group = 'www-data' + $apache_name = 'apache2' + $httpd_dir = '/etc/apache2' + $conf_dir = $httpd_dir + $confd_dir = "${httpd_dir}/conf.d" + $mod_dir = "${httpd_dir}/mods-available" + $mod_enable_dir = "${httpd_dir}/mods-enabled" + $vhost_dir = "${httpd_dir}/sites-available" + $vhost_enable_dir = "${httpd_dir}/sites-enabled" + $conf_file = 'apache2.conf' + $ports_file = "${conf_dir}/ports.conf" + $logroot = '/var/log/apache2' + $lib_path = '/usr/lib/apache2/modules' + $mpm_module = 'worker' + $dev_packages = ['libaprutil1-dev', 'libapr1-dev', 'apache2-prefork-dev'] + $default_ssl_cert = '/etc/ssl/certs/ssl-cert-snakeoil.pem' + $default_ssl_key = '/etc/ssl/private/ssl-cert-snakeoil.key' + $ssl_certs_dir = '/etc/ssl/certs' + $passenger_root = '/usr' + $passenger_ruby = '/usr/bin/ruby' + $suphp_addhandler = 'x-httpd-php' + $suphp_engine = 'off' + $suphp_configpath = '/etc/php5/apache2' + $mod_packages = { + 'auth_kerb' => 'libapache2-mod-auth-kerb', + 'fcgid' => 'libapache2-mod-fcgid', + 'passenger' => 'libapache2-mod-passenger', + 'perl' => 'libapache2-mod-perl2', + 'php5' => 'libapache2-mod-php5', + 'proxy_html' => 'libapache2-mod-proxy-html', + 'python' => 'libapache2-mod-python', + 'wsgi' => 'libapache2-mod-wsgi', + 'dav_svn' => 'libapache2-svn', + 'suphp' => 'libapache2-mod-suphp', + 'xsendfile' => 'libapache2-mod-xsendfile', + } + $mod_libs = { + 'php5' => 'libphp5.so', + } + $conf_template = 'apache/httpd.conf.erb' + $keepalive = 'Off' + $keepalive_timeout = 15 + } else { + fail("Class['apache::params']: Unsupported osfamily: ${::osfamily}") + } +} diff --git a/deployment/modules/apache/manifests/php.pp b/deployment/modules/apache/manifests/php.pp new file mode 100644 index 000000000..feb903e7b --- /dev/null +++ b/deployment/modules/apache/manifests/php.pp @@ -0,0 +1,18 @@ +# Class: apache::php +# +# This class installs PHP for Apache +# +# Parameters: +# - $php_package +# +# Actions: +# - Install Apache PHP package +# +# Requires: +# +# Sample Usage: +# +class apache::php { + warning('apache::php is deprecated; please use apache::mod::php') + include apache::mod::php +} diff --git a/deployment/modules/apache/manifests/proxy.pp b/deployment/modules/apache/manifests/proxy.pp new file mode 100644 index 000000000..0f4fde540 --- /dev/null +++ b/deployment/modules/apache/manifests/proxy.pp @@ -0,0 +1,15 @@ +# Class: apache::proxy +# +# This class enabled the proxy module for Apache +# +# Actions: +# - Enables Apache Proxy module +# +# Requires: +# +# Sample Usage: +# +class apache::proxy { + warning('apache::proxy is deprecated; please use apache::mod::proxy') + include apache::mod::proxy +} diff --git a/deployment/modules/apache/manifests/python.pp b/deployment/modules/apache/manifests/python.pp new file mode 100644 index 000000000..99ef28987 --- /dev/null +++ b/deployment/modules/apache/manifests/python.pp @@ -0,0 +1,18 @@ +# Class: apache::python +# +# This class installs Python for Apache +# +# Parameters: +# - $php_package +# +# Actions: +# - Install Apache Python package +# +# Requires: +# +# Sample Usage: +# +class apache::python { + warning('apache::python is deprecated; please use apache::mod::python') + include apache::mod::python +} diff --git a/deployment/modules/apache/manifests/service.pp b/deployment/modules/apache/manifests/service.pp new file mode 100644 index 000000000..e93b4a2a4 --- /dev/null +++ b/deployment/modules/apache/manifests/service.pp @@ -0,0 +1,29 @@ +# Class: apache::service +# +# Manages the Apache daemon +# +# Parameters: +# +# Actions: +# - Manage Apache service +# +# Requires: +# +# Sample Usage: +# +# sometype { 'foo': +# notify => Class['apache::service], +# } +# +# +class apache::service ( + $service_enable = true, +) { + validate_bool($service_enable) + + service { 'httpd': + ensure => $service_enable, + name => $apache::apache_name, + enable => $service_enable, + } +} diff --git a/deployment/modules/apache/manifests/ssl.pp b/deployment/modules/apache/manifests/ssl.pp new file mode 100644 index 000000000..21662e168 --- /dev/null +++ b/deployment/modules/apache/manifests/ssl.pp @@ -0,0 +1,18 @@ +# Class: apache::ssl +# +# This class installs Apache SSL capabilities +# +# Parameters: +# - The $ssl_package name from the apache::params class +# +# Actions: +# - Install Apache SSL capabilities +# +# Requires: +# +# Sample Usage: +# +class apache::ssl { + warning('apache::ssl is deprecated; please use apache::mod::ssl') + include apache::mod::ssl +} diff --git a/deployment/modules/apache/manifests/vhost.pp b/deployment/modules/apache/manifests/vhost.pp new file mode 100644 index 000000000..1f6fb1f24 --- /dev/null +++ b/deployment/modules/apache/manifests/vhost.pp @@ -0,0 +1,413 @@ +# Definition: apache::vhost +# +# This class installs Apache Virtual Hosts +# +# Parameters: +# - The $port to configure the host on +# - The $docroot provides the DocumentRoot variable +# - The $virtual_docroot provides VirtualDocumentationRoot variable +# - The $serveradmin will specify an email address for Apache that it will +# display when it renders one of it's error pages +# - The $ssl option is set true or false to enable SSL for this Virtual Host +# - The $priority of the site +# - The $servername is the primary name of the virtual host +# - The $serveraliases of the site +# - The $options for the given vhost +# - The $override for the given vhost (list of AllowOverride arguments) +# - The $vhost_name for name based virtualhosting, defaulting to * +# - The $logroot specifies the location of the virtual hosts logfiles, default +# to /var/log// +# - The $access_log specifies if *_access.log directives should be configured. +# - The $ensure specifies if vhost file is present or absent. +# - The $request_headers is a list of RequestHeader statement strings as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader +# - $aliases is a list of Alias hashes for mod_alias as per http://httpd.apache.org/docs/current/mod/mod_alias.html +# each statement is a hash in the form of { alias => '/alias', path => '/real/path/to/directory' } +# - $directories is a lost of hashes for creating statements as per http://httpd.apache.org/docs/2.2/mod/core.html#directory +# each statement is a hash in the form of { path => '/path/to/directory', => } +# see README.md for list of supported directives. +# +# Actions: +# - Install Apache Virtual Hosts +# +# Requires: +# - The apache class +# +# Sample Usage: +# +# # Simple vhost definition: +# apache::vhost { 'site.name.fqdn': +# port => '80', +# docroot => '/path/to/docroot', +# } +# +# # SSL vhost with non-SSL rewrite: +# apache::vhost { 'site.name.fqdn': +# port => '443', +# ssl => true, +# docroot => '/path/to/docroot', +# } +# apache::vhost { 'site.name.fqdn': +# port => '80', +# rewrite_cond => '%{HTTPS} off', +# rewrite_rule => '(.*) https://%{HTTPS_HOST}%{REQUEST_URI}', +# } +# apache::vhost { 'site.name.fqdn': +# port => '80', +# docroot => '/path/to/other_docroot', +# custom_fragment => template("${module_name}/my_fragment.erb"), +# } +# +define apache::vhost( + $docroot, + $virtual_docroot = false, + $port = undef, + $ip = undef, + $ip_based = false, + $add_listen = true, + $docroot_owner = 'root', + $docroot_group = 'root', + $serveradmin = false, + $ssl = false, + $ssl_cert = $apache::default_ssl_cert, + $ssl_key = $apache::default_ssl_key, + $ssl_chain = $apache::default_ssl_chain, + $ssl_ca = $apache::default_ssl_ca, + $ssl_crl_path = $apache::default_ssl_crl_path, + $ssl_crl = $apache::default_ssl_crl, + $ssl_certs_dir = $apache::params::ssl_certs_dir, + $priority = undef, + $default_vhost = false, + $servername = $name, + $serveraliases = [], + $options = ['Indexes','FollowSymLinks','MultiViews'], + $override = ['None'], + $vhost_name = '*', + $logroot = $apache::logroot, + $access_log = true, + $access_log_file = undef, + $access_log_pipe = undef, + $access_log_syslog = undef, + $access_log_format = undef, + $aliases = undef, + $directories = undef, + $error_log = true, + $error_log_file = undef, + $error_log_pipe = undef, + $error_log_syslog = undef, + $scriptalias = undef, + $proxy_dest = undef, + $proxy_pass = undef, + $sslproxyengine = false, + $suphp_addhandler = $apache::params::suphp_addhandler, + $suphp_engine = $apache::params::suphp_engine, + $suphp_configpath = $apache::params::suphp_configpath, + $no_proxy_uris = [], + $redirect_source = '/', + $redirect_dest = undef, + $redirect_status = undef, + $rack_base_uris = undef, + $request_headers = undef, + $rewrite_rule = undef, + $rewrite_cond = undef, + $setenv = [], + $setenvif = [], + $block = [], + $ensure = 'present', + $wsgi_daemon_process = undef, + $wsgi_daemon_process_options = undef, + $wsgi_process_group = undef, + $wsgi_script_aliases = undef, + $custom_fragment = undef, + $itk = undef + ) { + # The base class must be included first because it is used by parameter defaults + if ! defined(Class['apache']) { + fail('You must include the apache base class before using any apache defined resources') + } + $apache_name = $apache::params::apache_name + + validate_re($ensure, '^(present|absent)$', + "${ensure} is not supported for ensure. + Allowed values are 'present' and 'absent'.") + validate_re($suphp_engine, '^(on|off)$', + "${suphp_engine} is not supported for suphp_engine. + Allowed values are 'on' and 'off'.") + validate_bool($ip_based) + validate_bool($access_log) + validate_bool($error_log) + validate_bool($ssl) + validate_bool($default_vhost) + validate_bool($sslproxyengine) + if $wsgi_script_aliases { + validate_hash($wsgi_script_aliases) + } + if $wsgi_daemon_process_options { + validate_hash($wsgi_daemon_process_options) + } + if $itk { + validate_hash($itk) + } + + if $access_log_file and $access_log_pipe { + fail("Apache::Vhost[${name}]: 'access_log_file' and 'access_log_pipe' cannot be defined at the same time") + } + + if $error_log_file and $error_log_pipe { + fail("Apache::Vhost[${name}]: 'error_log_file' and 'error_log_pipe' cannot be defined at the same time") + } + + if $ssl { + include apache::mod::ssl + } + + if $virtual_docroot { + include apache::mod::vhost_alias + } + + # This ensures that the docroot exists + # But enables it to be specified across multiple vhost resources + if ! defined(File[$docroot]) { + file { $docroot: + ensure => directory, + owner => $docroot_owner, + group => $docroot_group, + require => Package['httpd'], + } + } + + # Same as above, but for logroot + if ! defined(File[$logroot]) { + file { $logroot: + ensure => directory, + require => Package['httpd'], + } + } + + + # Is apache::mod::passenger enabled (or apache::mod['passenger']) + $passenger_enabled = defined(Apache::Mod['passenger']) + + # Define log file names + if $access_log_file { + $access_log_destination = "${logroot}/${access_log_file}" + } elsif $access_log_pipe { + $access_log_destination = "\"${access_log_pipe}\"" + } elsif $access_log_syslog { + $access_log_destination = "${access_log_syslog}" + } else { + if $ssl { + $access_log_destination = "${logroot}/${servername}_access_ssl.log" + } else { + $access_log_destination = "${logroot}/${servername}_access.log" + } + } + + if $error_log_file { + $error_log_destination = "${logroot}/${error_log_file}" + } elsif $error_log_pipe { + $error_log_destination = "\"${error_log_pipe}\"" + } elsif $error_log_syslog { + $error_log_destination = "${error_log_syslog}" + } else { + if $ssl { + $error_log_destination = "${logroot}/${servername}_error_ssl.log" + } else { + $error_log_destination = "${logroot}/${servername}_error.log" + } + } + + # Set access log format + if $access_log_format { + $_access_log_format = "\"${access_log_format}\"" + } else { + $_access_log_format = 'combined' + } + + + if $ip { + if $port { + $listen_addr_port = "${ip}:${port}" + $nvh_addr_port = "${ip}:${port}" + } else { + $nvh_addr_port = $ip + if ! $servername and ! $ip_based { + fail("Apache::Vhost[${name}]: must pass 'ip' and/or 'port' parameters for name-based vhosts") + } + } + } else { + if $port { + $listen_addr_port = $port + $nvh_addr_port = "${vhost_name}:${port}" + } else { + $nvh_addr_port = $name + if ! $servername { + fail("Apache::Vhost[${name}]: must pass 'ip' and/or 'port' parameters, and/or 'servername' parameter") + } + } + } + if $add_listen { + if $ip and defined(Apache::Listen[$port]) { + fail("Apache::Vhost[${name}]: Mixing IP and non-IP Listen directives is not possible; check the add_listen parameter of the apache::vhost define to disable this") + } + if ! defined(Apache::Listen[$listen_addr_port]) and $listen_addr_port { + apache::listen { $listen_addr_port: } + } + } + if ! $ip_based { + if ! defined(Apache::Namevirtualhost[$nvh_addr_port]) { + apache::namevirtualhost { $nvh_addr_port: } + } + } + + # Load mod_rewrite if needed and not yet loaded + if $rewrite_rule { + if ! defined(Apache::Mod['rewrite']) { + apache::mod { 'rewrite': } + } + } + + # Load mod_alias if needed and not yet loaded + if $scriptalias or ($redirect_source and $redirect_dest) { + if ! defined(Class['apache::mod::alias']) { + include apache::mod::alias + } + } + + # Load mod_proxy if needed and not yet loaded + if ($proxy_dest or $proxy_pass) { + if ! defined(Class['apache::mod::proxy']) { + include apache::mod::proxy + } + } + + # Load mod_passenger if needed and not yet loaded + if $rack_base_uris { + if ! defined(Class['apache::mod::passenger']) { + include apache::mod::passenger + } + } + + # Configure the defaultness of a vhost + if $priority { + $priority_real = $priority + } elsif $default_vhost { + $priority_real = '10' + } else { + $priority_real = '25' + } + + # Check if mod_headers is required to process $request_headers + if $request_headers { + if ! defined(Class['apache::mod::headers']) { + include apache::mod::headers + } + } + + ## Apache include does not always work with spaces in the filename + $filename = regsubst($name, ' ', '_', 'G') + + ## Create a default directory list if none defined + if $directories { + $_directories = $directories + } else { + $_directories = [ { + provider => 'directory', + path => $docroot, + options => $options, + allow_override => $override, + order => 'allow,deny', + allow => 'from all', + } ] + } + + # Template uses: + # - $nvh_addr_port + # - $servername + # - $serveradmin + # - $docroot + # - $virtual_docroot + # - $options + # - $override + # - $logroot + # - $name + # - $aliases + # - $_directories + # - $access_log + # - $access_log_destination + # - $_access_log_format + # - $error_log + # - $error_log_destination + # - $custom_fragment + # block fragment: + # - $block + # directories fragment: + # - $passenger_enabled + # - $directories (a list of key-value hashes is expected) + # proxy fragment: + # - $proxy_dest + # - $no_proxy_uris + # rack fragment: + # - $rack_base_uris + # redirect fragment: + # - $redirect_source + # - $redirect_dest + # - $redirect_status + # requestheader fragment: + # - $request_headers + # rewrite fragment: + # - $rewrite_rule + # - $rewrite_cond + # scriptalias fragment: + # - $scriptalias + # - $ssl + # serveralias fragment: + # - $serveraliases + # setenv fragment: + # - $setenv + # - $setenvif + # ssl fragment: + # - $ssl + # - $ssl_cert + # - $ssl_key + # - $ssl_chain + # - $ssl_certs_dir + # - $ssl_ca + # - $ssl_crl + # - $ssl_crl_path + # suphp fragment: + # - $suphp_addhandler + # - $suphp_engine + # - $suphp_configpath + # wsgi fragment: + # - $wsgi_daemon_process + # - $wsgi_process_group + # - $wsgi_script_aliases + file { "${priority_real}-${filename}.conf": + ensure => $ensure, + path => "${apache::vhost_dir}/${priority_real}-${filename}.conf", + content => template('apache/vhost.conf.erb'), + owner => 'root', + group => 'root', + mode => '0644', + require => [ + Package['httpd'], + File[$docroot], + File[$logroot], + ], + notify => Service['httpd'], + } + if $::osfamily == 'Debian' { + $vhost_enable_dir = $apache::vhost_enable_dir + file{ "${priority_real}-${filename}.conf symlink": + ensure => link, + path => "${vhost_enable_dir}/${priority_real}-${filename}.conf", + target => "${apache::vhost_dir}/${priority_real}-${filename}.conf", + owner => 'root', + group => 'root', + mode => '0644', + require => File["${priority_real}-${filename}.conf"], + notify => Service['httpd'], + } + } +} + diff --git a/deployment/modules/apache/metadata.json b/deployment/modules/apache/metadata.json new file mode 100644 index 000000000..ce4c2be86 --- /dev/null +++ b/deployment/modules/apache/metadata.json @@ -0,0 +1,234 @@ +{ + "name": "puppetlabs-apache", + "version": "0.9.0", + "summary": "Puppet module for Apache", + "author": "puppetlabs", + "description": "Module for Apache configuration", + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": "\u003e\u003d 2.4.0" + }, + { + "name": "puppetlabs/concat", + "version_requirement": "\u003e\u003d 1.0.0" + } + ], + "types": [ + { + "parameters": [ + { + "name": "name", + "doc": "The name of the module to be managed" + }, + { + "name": "lib", + "doc": "The name of the .so library to be loaded" + }, + { + "name": "identifier", + "doc": "Module identifier string used by LoadModule. Default: module-name_module" + } + ], + "providers": [ + { + "name": "gentoo", + "doc": "Manage Apache 2 modules on Gentoo" + }, + { + "name": "modfix", + "doc": "Dummy provider for A2mod.\n\n Fake nil resources when there is no crontab binary available. Allows\n puppetd to run on a bootstrapped machine before a Cron package has been\n installed. Workaround for: http://projects.puppetlabs.com/issues/2384\n " + }, + { + "name": "redhat", + "doc": "Manage Apache 2 modules on RedHat family OSs" + }, + { + "name": "a2mod", + "doc": "Manage Apache 2 modules on Debian and Ubuntu" + } + ], + "name": "a2mod", + "doc": "Manage Apache 2 modules" + } + ], + "checksums": { + ".bundle/config": "b898efea5e8783d6593fcdabec67e925", + ".fixtures.yml": "b67781fff881cf708d92df4851cf0e70", + ".nodeset.yml": "f2b857f9fc7a701ff118e28591c12925", + ".travis.yml": "d0bd592680200f18b2ef4088c2569701", + "CHANGELOG.md": "483202a1f4f08294d798c0685c518108", + "Gemfile": "c1cd7b0477f1a99e0156a471aac6cd58", + "Gemfile.lock": "74613ef355389b668fc4b51a0f9eac39", + "LICENSE": "b3f8a01d8699078d82e8c3c992307517", + "Modulefile": "fef4b236b7d7885250ca64dbe6074e0a", + "README.md": "d3cb59220928734b6d41a6f3a0302c64", + "README.passenger.md": "9007ae9e57138bed0c01ae58607ec2aa", + "Rakefile": "0428ea3759a4692c91604396c406a9c1", + "files/httpd": "295f5e924afe6f752d29327e73fe6d0a", + "lib/puppet/provider/a2mod.rb": "03ed73d680787dd126ea37a03be0b236", + "lib/puppet/provider/a2mod/a2mod.rb": "d986d8e8373f3f31c97359381c180628", + "lib/puppet/provider/a2mod/gentoo.rb": "2492d446adbb68f678e86a75eb7ff3bd", + "lib/puppet/provider/a2mod/modfix.rb": "b689a1c83c9ccd8590399c67f3e588e5", + "lib/puppet/provider/a2mod/redhat.rb": "c39b80e75e7d0666def31c2a6cdedb0b", + "lib/puppet/type/a2mod.rb": "9042ccc045bfeecca28bebb834114f05", + "manifests/balancer.pp": "c635b2d2dec8b5972509960152e169a3", + "manifests/balancermember.pp": "8afe51921a42545402fa457820162ae2", + "manifests/default_mods.pp": "8493f16440d3eb7b9d392049dfef680b", + "manifests/default_mods/load.pp": "b3f21b3186216795dd18ee051f01e3c2", + "manifests/dev.pp": "606c3cbe27f32b61cfcbd15fb211890c", + "manifests/init.pp": "b0d1433c1848ee81f18d528fcdf5abec", + "manifests/listen.pp": "5efc62bd75a0a9a9565b12bd8cb2a9e4", + "manifests/mod.pp": "fc66b79d9086d8d296c372d605d31890", + "manifests/mod/alias.pp": "f5d65ca4755f5464b32c5f95fd42a052", + "manifests/mod/auth_basic.pp": "47ff846317d52d2161c6d09cac05f7f8", + "manifests/mod/auth_kerb.pp": "7876ffdca25396285a26afae8dd030eb", + "manifests/mod/autoindex.pp": "1b07e7737b4b27f977f80c289172a55b", + "manifests/mod/cache.pp": "51b4826a72090da8e463bc007695f05b", + "manifests/mod/cgi.pp": "8c9265733584e188196fe69fd3b9fdd7", + "manifests/mod/cgid.pp": "63bd38d692ec78f351a6f234f29c2f16", + "manifests/mod/dav.pp": "f0228b06b7101864f7c943b541e570d2", + "manifests/mod/dav_fs.pp": "93fce4f45e7a85e9d6eb2b745390eaba", + "manifests/mod/dav_svn.pp": "85a9a3efe5cce6096d89cf29195e6dc1", + "manifests/mod/deflate.pp": "f317ddf1cbfee52945d0433a3b25c728", + "manifests/mod/dev.pp": "d6a001af402d8e82e952c8243c5e5321", + "manifests/mod/dir.pp": "f3c3e6a21653ebda12f35b4b140e68d5", + "manifests/mod/disk_cache.pp": "da3b7f47ce079f20db2d20e2d6539c11", + "manifests/mod/fcgid.pp": "d03eb1add8f2cef603331dde96f1f7fd", + "manifests/mod/headers.pp": "224438518465d09c951eb00dbaf8123c", + "manifests/mod/info.pp": "9a45dd07a2681dc1fef9204de3f42bd9", + "manifests/mod/itk.pp": "852588a26f2635979abf24fd33f1a9ff", + "manifests/mod/ldap.pp": "f5033ee5197938d402854d8ffa9fb1d3", + "manifests/mod/mime.pp": "c9ff4215f9308fd729e96a8d76d3fe1d", + "manifests/mod/mime_magic.pp": "9c3a73f877de39c1db2178b827c4a86d", + "manifests/mod/mpm_event.pp": "c1540d87cfb2b4a4631c4cc5d3e191f5", + "manifests/mod/negotiation.pp": "9f5d70e4c961175a78a049fedaac85c9", + "manifests/mod/passenger.pp": "29fca0851862aaaa836acf25718c08cc", + "manifests/mod/perl.pp": "72195ad624f68e2c0009074d118bf8e4", + "manifests/mod/php.pp": "247915331ce4ee815a0c032897a83157", + "manifests/mod/prefork.pp": "2eb8a29fa3a81b4b8ade96989ef06742", + "manifests/mod/proxy.pp": "e0e9f9963f720501d9b53ab9fb35f256", + "manifests/mod/proxy_balancer.pp": "c71c8ae1eb91d29ec26e19899db2bfec", + "manifests/mod/proxy_html.pp": "25cbac9bc2553bc3a18ede060a1a14fd", + "manifests/mod/proxy_http.pp": "773d0fbb934440a24b3bc87517faa4d4", + "manifests/mod/python.pp": "0b22df3d0e9a39ce948212e18329155f", + "manifests/mod/reqtimeout.pp": "2ff860e05de7352d4a1bcd57c0ee08f0", + "manifests/mod/rewrite.pp": "165fdccc8acc61e5fb088d9917861a3c", + "manifests/mod/setenvif.pp": "32098aaab01723cae4c44d2fff8114ea", + "manifests/mod/ssl.pp": "80ee4f522104719f07aa2be33d320973", + "manifests/mod/status.pp": "1619d96a0d9b9534145209c98c683cbe", + "manifests/mod/suphp.pp": "c42d20b057007eff1a75595fc3fe7adf", + "manifests/mod/userdir.pp": "7166fee20a3e5b97d61dfae18fb745c9", + "manifests/mod/vhost_alias.pp": "ea2d06875ed4f47ba65da0f7169e529e", + "manifests/mod/worker.pp": "36bdeaa252d3ba3c14296bbcf2acb9b0", + "manifests/mod/wsgi.pp": "092d35c267e671444d42e2243606bc99", + "manifests/mod/xsendfile.pp": "ebe6241729f1b0d8125043a1f34caa54", + "manifests/namevirtualhost.pp": "27bb9faa95147fcd15ec2aa0a95bc3af", + "manifests/params.pp": "525b2ac104a0a4922f6be584bc5c6e9d", + "manifests/php.pp": "a4478838b4cf9b0525b04db150cf55b8", + "manifests/proxy.pp": "54e7657920b580546f3bef3980f2fd03", + "manifests/python.pp": "2edb06e8119b67a5a62fb24fb280d3e5", + "manifests/service.pp": "8e5145ad7866adb9b1f26494559ba6a7", + "manifests/ssl.pp": "7f944d1c103a59ebd04d02e68af69f7a", + "manifests/vhost.pp": "2242685bed5db4a4fa08ebfe1f836084", + "spec/classes/apache_spec.rb": "dbeb82d859d03037b86c754d2e9437b9", + "spec/classes/dev_spec.rb": "ecc212316f7801f427fa4c30ca65e259", + "spec/classes/mod/auth_kerb_spec.rb": "70e2d94d84724a1b54aff6a9dede1ca6", + "spec/classes/mod/dav_svn_spec.rb": "6b014a30e017a6cf30bdc4221e4a15b9", + "spec/classes/mod/dev_spec.rb": "27a9d92460a3e62842b5e64f7154f893", + "spec/classes/mod/dir_spec.rb": "e462dbea87eb1211e496f60e40538370", + "spec/classes/mod/fcgid_spec.rb": "3bd6c0638347b763a88e44d5d7216cb0", + "spec/classes/mod/info_spec.rb": "3921a934a1d41c6e1cce328a45b3cc1d", + "spec/classes/mod/itk_spec.rb": "e9edc7ebebeda4cea0bf896c597c2267", + "spec/classes/mod/passenger_spec.rb": "959b0a3235999e5201980871ea2b862a", + "spec/classes/mod/perl_spec.rb": "0ba258605762d1fa25398a08e90157e4", + "spec/classes/mod/php_spec.rb": "c4050e546d010f0dcb5a8bd580b5f3ed", + "spec/classes/mod/prefork_spec.rb": "0f7de99f1fb58670f11fde4f7280e99e", + "spec/classes/mod/proxy_html_spec.rb": "bf313b5dfdd2c9f3054f4b791c32a84c", + "spec/classes/mod/python_spec.rb": "2b8079e833cbe6313435a72d9fc00cb9", + "spec/classes/mod/ssl_spec.rb": "53b8ecefa9ce0af2562d8183c063167d", + "spec/classes/mod/suphp_spec.rb": "1da3f6561f19d8c7f2a71655fa7772ea", + "spec/classes/mod/worker_spec.rb": "f3324663e5f93d1b73911276bd984e79", + "spec/classes/mod/wsgi_spec.rb": "c41bc8e4cc95a87d1448e06b7d8001eb", + "spec/classes/params_spec.rb": "9b1984a3e8a485ff128512833400dfbd", + "spec/classes/service_spec.rb": "3448d0a4256bd806902c45f2c13bf5a6", + "spec/defines/mod_spec.rb": "d82643d472be88a65cd202381099ed6f", + "spec/defines/vhost_spec.rb": "4535046a2cf7d7f9745020b92503f2e4", + "spec/fixtures/modules/site_apache/templates/fake.conf.erb": "6b0431dd0b9a0bf803eb0684300c2cff", + "spec/spec.opts": "c407193b3d9028941ef59edd114f5968", + "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc", + "spec/spec_helper_system.rb": "c54584d03120766bac28221597920d3d", + "spec/system/basic_spec.rb": "73bab7cf3eb0554b7d7801613c4b483e", + "spec/system/class_spec.rb": "ada9b7ebb090d6b4e62db22b3c82b330", + "spec/system/default_mods_spec.rb": "b57b9deb89c3905a7a7d9ca9e573f62f", + "spec/system/itk_spec.rb": "cbce8cac9e311b2cfce48eb2369ced7b", + "spec/system/mod_php_spec.rb": "9bc01054af24b981fa1c49ac723469fc", + "spec/system/mod_suphp_spec.rb": "9d38045b3dcb052153e7c08164301c13", + "spec/system/prefork_worker_spec.rb": "d7b05867fd73464971919fd4393b3719", + "spec/system/service_spec.rb": "3cd71e4e40790e1624487fd233f18a07", + "spec/system/vhost_spec.rb": "2e3c1fa5ab5a6e4f8513c68904e52269", + "spec/unit/provider/a2mod/gentoo_spec.rb": "24ad9db4f6ba0b4fc7ed77b509b4244c", + "templates/httpd.conf.erb": "154af1419ad44722c9f33bd1eb9a9637", + "templates/listen.erb": "6286aa08f9e28caee54b1e1ee031b9d6", + "templates/mod/alias.conf.erb": "669fc0a80839be3a81e2f4d4150c3ad6", + "templates/mod/autoindex.conf.erb": "2421a3c6df32c7e38c2a7a22afdf5728", + "templates/mod/cgid.conf.erb": "3d4e24001b50eb16561e45f5a8237b32", + "templates/mod/dav_fs.conf.erb": "fdf1f8cff4708a282ef491d60868d1d7", + "templates/mod/deflate.conf.erb": "44d54f557a5612be8da04c49dd6da862", + "templates/mod/dir.conf.erb": "2485da78a2506c14bf51dde38dd03360", + "templates/mod/disk_cache.conf.erb": "7d3e7a5ee3bd7b6a839924b06a60667f", + "templates/mod/info.conf.erb": "bb48951beaeaf582d1a1023cb661ac32", + "templates/mod/itk.conf.erb": "eff84b78e4f2f8c5c3a2e9fc4b8aad16", + "templates/mod/ldap.conf.erb": "a8a33f645497e0dbcec363c98be43795", + "templates/mod/mime.conf.erb": "2fa646fe615e44d137a5d629f868c107", + "templates/mod/mime_magic.conf.erb": "8a4f61bd7539871cb507cc95f5dbd205", + "templates/mod/mpm_event.conf.erb": "80097a19d063a4f973465d9ef5c0c0bf", + "templates/mod/negotiation.conf.erb": "47284b5580b986a6ba32580b6ffb9fd7", + "templates/mod/passenger.conf.erb": "6e0c2d796b5e67aa366eadc53c963a5e", + "templates/mod/php5.conf.erb": "49e2d214790835c141fcaf6d74b5a96d", + "templates/mod/prefork.conf.erb": "f9ec5a7eaea78a19b04fa69f8acd8a84", + "templates/mod/proxy.conf.erb": "ae1cd187ffbd5cc9b74f8711e313e96b", + "templates/mod/proxy_html.conf.erb": "67546d56f2d6bb1860338257e3ac9d29", + "templates/mod/reqtimeout.conf.erb": "81c51851ab7ee7942bef389dc7c0e985", + "templates/mod/setenvif.conf.erb": "c7ede4173da1915b7ec088201f030c28", + "templates/mod/ssl.conf.erb": "2567261763976c62a4388abb62ae1e03", + "templates/mod/status.conf.erb": "da061291068f8e20cf33812373319c40", + "templates/mod/suphp.conf.erb": "05bb7b3ea23976b032ce405bfd4edd18", + "templates/mod/userdir.conf.erb": "e5a7a7229dbf0de07bc034dd3d108ea2", + "templates/mod/worker.conf.erb": "9661e7a59eaefb9f17d4c2680c0d243d", + "templates/mod/wsgi.conf.erb": "7e098b0013f6e64e935bf244f7efcd67", + "templates/namevirtualhost.erb": "fbfca19a639e18e6c477e191344ac8ae", + "templates/ports_header.erb": "afe35cb5747574b700ebaa0f0b3a626e", + "templates/vhost.conf.erb": "bc0f0bae3b149c8b78d9127714f2d28c", + "templates/vhost/_aliases.erb": "319183dd74f4b231747fffa7b4a939f3", + "templates/vhost/_block.erb": "7cb56db9254729b54e8d30686c4f3b1a", + "templates/vhost/_custom_fragment.erb": "67a4475275ec9208e6421b047b9ed7f4", + "templates/vhost/_directories.erb": "5131331896f3839221e1231e28b6e509", + "templates/vhost/_itk.erb": "db5b12d7236dbc19b62ce13625d9d60e", + "templates/vhost/_proxy.erb": "8faa613a00584432f99956f4b0ac1fbd", + "templates/vhost/_rack.erb": "ebe187c1bdc81eec9c8e0d9026120b18", + "templates/vhost/_redirect.erb": "0e2eed04e30240fbbd6c4ef7db6b7058", + "templates/vhost/_requestheader.erb": "db1b0cdda069ae809b5b83b0871ef991", + "templates/vhost/_rewrite.erb": "dcf423c014bdb222bcf15314a2f3a41f", + "templates/vhost/_scriptalias.erb": "0373372000ca3198594f32ac637a9462", + "templates/vhost/_serveralias.erb": "2ef30c2152b9284463588f408f7f371f", + "templates/vhost/_setenv.erb": "da6778b324857234c8441ef346d08969", + "templates/vhost/_ssl.erb": "5451565f3c34abdd50024af607ed9dc1", + "templates/vhost/_suphp.erb": "6ea2553a4c4284d41b435fa2f4f4edc7", + "templates/vhost/_wsgi.erb": "3bbab1e5757dfb584504f05354275f81", + "tests/apache.pp": "819cf9116ffd349e6757e1926d11ca2f", + "tests/dev.pp": "4cf15c1fecea3ca86009f182b402c7ab", + "tests/init.pp": "4eac4a7ef68499854c54a78879e25535", + "tests/mods.pp": "0085911ba562b7e56ad8d793099c9240", + "tests/mods_custom.pp": "9afd068edce0538b5c55a3bc19f9c24a", + "tests/php.pp": "ce7bb9eef69d32b42a32ce32d9653625", + "tests/vhost.pp": "70ce947e12f9b344a24f95a08e622c6c", + "tests/vhost_directories.pp": "b79a3bcf72474ce4e3b75f6a70cbf272", + "tests/vhost_ip_based.pp": "7d9f7b6976de7488ab6ff0a6e647fc73", + "tests/vhost_ssl.pp": "9f3716bc15a9a6760f1d6cc3bf8ce8ac", + "tests/vhosts_without_listen.pp": "a6692104056a56517b4365bcc816e7f4" + }, + "source": "git://github.com/puppetlabs/puppetlabs-apache.git", + "project_page": "https://github.com/puppetlabs/puppetlabs-apache", + "license": "Apache 2.0" +} \ No newline at end of file diff --git a/deployment/modules/apache/spec/classes/apache_spec.rb b/deployment/modules/apache/spec/classes/apache_spec.rb new file mode 100644 index 000000000..7e7a87bb7 --- /dev/null +++ b/deployment/modules/apache/spec/classes/apache_spec.rb @@ -0,0 +1,292 @@ +require 'spec_helper' + +describe 'apache', :type => :class do + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_package("httpd").with( + 'notify' => 'Class[Apache::Service]' + ) + } + it { should contain_user("www-data") } + it { should contain_group("www-data") } + it { should contain_class("apache::service") } + it { should contain_file("/etc/apache2/sites-enabled").with( + 'ensure' => 'directory', + 'recurse' => 'true', + 'purge' => 'true', + 'notify' => 'Class[Apache::Service]', + 'require' => 'Package[httpd]' + ) + } + it { should contain_file("/etc/apache2/mods-enabled").with( + 'ensure' => 'directory', + 'recurse' => 'true', + 'purge' => 'true', + 'notify' => 'Class[Apache::Service]', + 'require' => 'Package[httpd]' + ) + } + it { should contain_file("/etc/apache2/mods-available").with( + 'ensure' => 'directory', + 'recurse' => 'true', + 'purge' => 'true', + 'notify' => 'Class[Apache::Service]', + 'require' => 'Package[httpd]' + ) + } + it { should contain_concat("/etc/apache2/ports.conf").with( + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'notify' => 'Class[Apache::Service]' + ) + } + # Assert that load files are placed and symlinked for these mods, but no conf file. + [ + 'auth_basic', + 'authn_file', + 'authz_default', + 'authz_groupfile', + 'authz_host', + 'authz_user', + 'dav', + 'env' + ].each do |modname| + it { should contain_file("#{modname}.load").with( + 'path' => "/etc/apache2/mods-available/#{modname}.load", + 'ensure' => 'file' + ) } + it { should contain_file("#{modname}.load symlink").with( + 'path' => "/etc/apache2/mods-enabled/#{modname}.load", + 'ensure' => 'link', + 'target' => "/etc/apache2/mods-available/#{modname}.load" + ) } + it { should_not contain_file("#{modname}.conf") } + it { should_not contain_file("#{modname}.conf symlink") } + end + + # Assert that both load files and conf files are placed and symlinked for these mods + [ + 'alias', + 'autoindex', + 'dav_fs', + 'deflate', + 'dir', + 'mime', + 'negotiation', + 'setenvif', + ].each do |modname| + it { should contain_file("#{modname}.load").with( + 'path' => "/etc/apache2/mods-available/#{modname}.load", + 'ensure' => 'file' + ) } + it { should contain_file("#{modname}.load symlink").with( + 'path' => "/etc/apache2/mods-enabled/#{modname}.load", + 'ensure' => 'link', + 'target' => "/etc/apache2/mods-available/#{modname}.load" + ) } + it { should contain_file("#{modname}.conf").with( + 'path' => "/etc/apache2/mods-available/#{modname}.conf", + 'ensure' => 'file' + ) } + it { should contain_file("#{modname}.conf symlink").with( + 'path' => "/etc/apache2/mods-enabled/#{modname}.conf", + 'ensure' => 'link', + 'target' => "/etc/apache2/mods-available/#{modname}.conf" + ) } + end + end + context "on a RedHat 5 OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '5', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_package("httpd").with( + 'notify' => 'Class[Apache::Service]' + ) + } + it { should contain_user("apache") } + it { should contain_group("apache") } + it { should contain_class("apache::service") } + it { should contain_file("/etc/httpd/conf.d").with( + 'ensure' => 'directory', + 'recurse' => 'true', + 'purge' => 'true', + 'notify' => 'Class[Apache::Service]', + 'require' => 'Package[httpd]' + ) + } + it { should contain_concat("/etc/httpd/conf/ports.conf").with( + 'owner' => 'root', + 'group' => 'root', + 'mode' => '0644', + 'notify' => 'Class[Apache::Service]' + ) + } + describe "Alternate confd/mod/vhosts directory" do + let :params do + { + :vhost_dir => '/etc/httpd/site.d', + :confd_dir => '/etc/httpd/conf.d', + :mod_dir => '/etc/httpd/mod.d', + } + end + + ['mod.d','site.d','conf.d'].each do |dir| + it { should contain_file("/etc/httpd/#{dir}").with( + 'ensure' => 'directory', + 'recurse' => 'true', + 'purge' => 'true', + 'notify' => 'Class[Apache::Service]', + 'require' => 'Package[httpd]' + ) } + end + + # Assert that load files are placed for these mods, but no conf file. + [ + 'auth_basic', + 'authn_file', + 'authz_default', + 'authz_groupfile', + 'authz_host', + 'authz_user', + 'dav', + 'env', + ].each do |modname| + it { should contain_file("#{modname}.load").with_path( + "/etc/httpd/mod.d/#{modname}.load" + ) } + it { should_not contain_file("#{modname}.conf").with_path( + "/etc/httpd/mod.d/#{modname}.conf" + ) } + end + + # Assert that both load files and conf files are placed for these mods + [ + 'alias', + 'autoindex', + 'dav_fs', + 'deflate', + 'dir', + 'mime', + 'negotiation', + 'setenvif', + ].each do |modname| + it { should contain_file("#{modname}.load").with_path( + "/etc/httpd/mod.d/#{modname}.load" + ) } + it { should contain_file("#{modname}.conf").with_path( + "/etc/httpd/mod.d/#{modname}.conf" + ) } + end + + it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include /etc/httpd/conf\.d/\*\.conf$} } + it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include /etc/httpd/site\.d/\*\.conf$} } + it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include /etc/httpd/mod\.d/\*\.conf$} } + it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Include /etc/httpd/mod\.d/\*\.load$} } + end + + describe "Alternate conf.d directory" do + let :params do + { :confd_dir => '/etc/httpd/special_conf.d' } + end + + it { should contain_file("/etc/httpd/special_conf.d").with( + 'ensure' => 'directory', + 'recurse' => 'true', + 'purge' => 'true', + 'notify' => 'Class[Apache::Service]', + 'require' => 'Package[httpd]' + ) } + end + + describe "Alternate mpm_modules" do + context "when declaring mpm_module is false" do + let :params do + { :mpm_module => false } + end + it 'should not declare mpm modules' do + should_not contain_class('apache::mod::itk') + should_not contain_class('apache::mod::prefork') + should_not contain_class('apache::mod::worker') + end + end + context "when declaring mpm_module => prefork" do + let :params do + { :mpm_module => 'prefork' } + end + it { should contain_class('apache::mod::prefork') } + it { should_not contain_class('apache::mod::itk') } + it { should_not contain_class('apache::mod::worker') } + end + context "when declaring mpm_module => worker" do + let :params do + { :mpm_module => 'worker' } + end + it { should contain_class('apache::mod::worker') } + it { should_not contain_class('apache::mod::itk') } + it { should_not contain_class('apache::mod::prefork') } + end + context "when declaring mpm_module => breakme" do + let :params do + { :mpm_module => 'breakme' } + end + it { expect { should contain_class('apache::params') }.to raise_error Puppet::Error, /does not match/ } + end + end + + describe "different templates for httpd.conf" do + context "with default" do + let :params do + { :conf_template => 'apache/httpd.conf.erb' } + end + it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^# Security\n} } + end + context "with non-default" do + let :params do + { :conf_template => 'site_apache/fake.conf.erb' } + end + it { should contain_file("/etc/httpd/conf/httpd.conf").with_content %r{^Fake template for rspec.$} } + end + end + + describe "default mods" do + context "without" do + let :params do + { :default_mods => false } + end + + it { should contain_apache__mod('authz_host') } + it { should_not contain_apache__mod('env') } + end + context "custom" do + let :params do + { :default_mods => [ + 'info', + 'alias', + 'mime', + 'env', + 'setenv', + 'expires', + ]} + end + + it { should contain_apache__mod('authz_host') } + it { should contain_apache__mod('env') } + it { should contain_class('apache::mod::info') } + it { should contain_class('apache::mod::mime') } + end + end + end +end diff --git a/deployment/modules/apache/spec/classes/dev_spec.rb b/deployment/modules/apache/spec/classes/dev_spec.rb new file mode 100644 index 000000000..8bdf1200b --- /dev/null +++ b/deployment/modules/apache/spec/classes/dev_spec.rb @@ -0,0 +1,26 @@ +require 'spec_helper' + +describe 'apache::dev', :type => :class do + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + } + end + it { should include_class("apache::params") } + it { should contain_package("libaprutil1-dev") } + it { should contain_package("libapr1-dev") } + it { should contain_package("apache2-prefork-dev") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + } + end + it { should include_class("apache::params") } + it { should contain_package("httpd-devel") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/auth_kerb_spec.rb b/deployment/modules/apache/spec/classes/mod/auth_kerb_spec.rb new file mode 100644 index 000000000..c4aa8a67f --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/auth_kerb_spec.rb @@ -0,0 +1,29 @@ +describe 'apache::mod::auth_kerb', :type => :class do + let :pre_condition do + 'include apache' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod("auth_kerb") } + it { should contain_package("libapache2-mod-auth-kerb") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod("auth_kerb") } + it { should contain_package("mod_auth_kerb") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/dav_svn_spec.rb b/deployment/modules/apache/spec/classes/mod/dav_svn_spec.rb new file mode 100644 index 000000000..4d293b37d --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/dav_svn_spec.rb @@ -0,0 +1,29 @@ +describe 'apache::mod::dav_svn', :type => :class do + let :pre_condition do + 'include apache' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('dav_svn') } + it { should contain_package("libapache2-svn") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('dav_svn') } + it { should contain_package("mod_dav_svn") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/dev_spec.rb b/deployment/modules/apache/spec/classes/mod/dev_spec.rb new file mode 100644 index 000000000..4d8876853 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/dev_spec.rb @@ -0,0 +1,27 @@ +describe 'apache::dev', :type => :class do + let :pre_condition do + 'include apache' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should contain_package("libaprutil1-dev") } + it { should contain_package("libapr1-dev") } + it { should contain_package("apache2-prefork-dev") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should contain_package("httpd-devel") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/dir_spec.rb b/deployment/modules/apache/spec/classes/mod/dir_spec.rb new file mode 100644 index 000000000..ec94b2899 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/dir_spec.rb @@ -0,0 +1,61 @@ +describe 'apache::mod::dir', :type => :class do + let :pre_condition do + 'class { "apache": + default_mods => false, + }' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + context "passing no parameters" do + it { should include_class("apache::params") } + it { should contain_apache__mod('dir') } + it { should contain_file('dir.conf').with_content(/^DirectoryIndex /) } + it { should contain_file('dir.conf').with_content(/ index\.html /) } + it { should contain_file('dir.conf').with_content(/ index\.html\.var /) } + it { should contain_file('dir.conf').with_content(/ index\.cgi /) } + it { should contain_file('dir.conf').with_content(/ index\.pl /) } + it { should contain_file('dir.conf').with_content(/ index\.php /) } + it { should contain_file('dir.conf').with_content(/ index\.xhtml$/) } + end + context "passing indexes => ['example.txt','fearsome.aspx']" do + let :params do + {:indexes => ['example.txt','fearsome.aspx']} + end + it { should contain_file('dir.conf').with_content(/ example\.txt /) } + it { should contain_file('dir.conf').with_content(/ fearsome\.aspx$/) } + end + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + context "passing no parameters" do + it { should include_class("apache::params") } + it { should contain_apache__mod('dir') } + it { should contain_file('dir.conf').with_content(/^DirectoryIndex /) } + it { should contain_file('dir.conf').with_content(/ index\.html /) } + it { should contain_file('dir.conf').with_content(/ index\.html\.var /) } + it { should contain_file('dir.conf').with_content(/ index\.cgi /) } + it { should contain_file('dir.conf').with_content(/ index\.pl /) } + it { should contain_file('dir.conf').with_content(/ index\.php /) } + it { should contain_file('dir.conf').with_content(/ index\.xhtml$/) } + end + context "passing indexes => ['example.txt','fearsome.aspx']" do + let :params do + {:indexes => ['example.txt','fearsome.aspx']} + end + it { should contain_file('dir.conf').with_content(/ example\.txt /) } + it { should contain_file('dir.conf').with_content(/ fearsome\.aspx$/) } + end + end +end \ No newline at end of file diff --git a/deployment/modules/apache/spec/classes/mod/fcgid_spec.rb b/deployment/modules/apache/spec/classes/mod/fcgid_spec.rb new file mode 100644 index 000000000..be444c849 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/fcgid_spec.rb @@ -0,0 +1,29 @@ +describe 'apache::mod::fcgid', :type => :class do + let :pre_condition do + 'include apache' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('fcgid') } + it { should contain_package("libapache2-mod-fcgid") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('fcgid') } + it { should contain_package("mod_fcgid") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/info_spec.rb b/deployment/modules/apache/spec/classes/mod/info_spec.rb new file mode 100644 index 000000000..a057bf1dd --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/info_spec.rb @@ -0,0 +1,81 @@ +# This function is called inside the OS specific contexts +def general_info_specs + it { should contain_apache__mod("info") } + + it do + should contain_file("info.conf").with_content( + "\n"\ + " SetHandler server-info\n"\ + " Order deny,allow\n"\ + " Deny from all\n"\ + " Allow from 127.0.0.1 ::1\n"\ + "\n" + ) + end +end + +describe 'apache::mod::info', :type => :class do + let :pre_condition do + 'include apache' + end + + context "On a Debian OS with default params" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + + # Load the more generic tests for this context + general_info_specs() + + it { should contain_file("info.conf").with({ + :ensure => 'file', + :path => '/etc/apache2/mods-available/info.conf', + } ) } + it { should contain_file("info.conf symlink").with({ + :ensure => 'link', + :path => '/etc/apache2/mods-enabled/info.conf', + } ) } + end + + context "on a RedHat OS with default params" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + + # Load the more generic tests for this context + general_info_specs() + + it { should contain_file("info.conf").with_path("/etc/httpd/conf.d/info.conf") } + end + + context "with $allow_from => ['10.10.10.10','11.11.11.11']" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + let :params do + { :allow_from => ['10.10.10.10','11.11.11.11'] } + end + it do + should contain_file("info.conf").with_content( + "\n"\ + " SetHandler server-info\n"\ + " Order deny,allow\n"\ + " Deny from all\n"\ + " Allow from 10.10.10.10 11.11.11.11\n"\ + "\n" + ) + end + end +end diff --git a/deployment/modules/apache/spec/classes/mod/itk_spec.rb b/deployment/modules/apache/spec/classes/mod/itk_spec.rb new file mode 100644 index 000000000..7a0f7615c --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/itk_spec.rb @@ -0,0 +1,19 @@ +describe 'apache::mod::itk', :type => :class do + let :pre_condition do + 'class { "apache": mpm_module => false, }' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should_not contain_apache__mod('itk') } + it { should contain_file("/etc/apache2/mods-available/itk.conf").with_ensure('file') } + it { should contain_file("/etc/apache2/mods-enabled/itk.conf").with_ensure('link') } + it { should contain_package("apache2-mpm-itk") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/passenger_spec.rb b/deployment/modules/apache/spec/classes/mod/passenger_spec.rb new file mode 100644 index 000000000..2e5212f94 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/passenger_spec.rb @@ -0,0 +1,94 @@ +describe 'apache::mod::passenger', :type => :class do + let :pre_condition do + 'include apache' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('passenger') } + it { should contain_package("libapache2-mod-passenger") } + it { should contain_file('passenger.conf').with({ + 'path' => '/etc/apache2/mods-available/passenger.conf', + }) } + it { should contain_file('passenger.conf').with_content(/^ PassengerRoot \/usr$/) } + it { should contain_file('passenger.conf').with_content(/^ PassengerRuby \/usr\/bin\/ruby$/) } + describe "with passenger_high_performance => true" do + let :params do + { :passenger_high_performance => 'true' } + end + it { should contain_file('passenger.conf').with_content(/^ PassengerHighPerformance true$/) } + end + describe "with passenger_pool_idle_time => 1200" do + let :params do + { :passenger_pool_idle_time => 1200 } + end + it { should contain_file('passenger.conf').with_content(/^ PassengerPoolIdleTime 1200$/) } + end + describe "with passenger_max_requests => 20" do + let :params do + { :passenger_max_requests => 20 } + end + it { should contain_file('passenger.conf').with_content(/^ PassengerMaxRequests 20$/) } + end + describe "with passenger_stat_throttle_rate => 10" do + let :params do + { :passenger_stat_throttle_rate => 10 } + end + it { should contain_file('passenger.conf').with_content(/^ PassengerStatThrottleRate 10$/) } + end + describe "with passenger_max_pool_size => 16" do + let :params do + { :passenger_max_pool_size => 16 } + end + it { should contain_file('passenger.conf').with_content(/^ PassengerMaxPoolSize 16$/) } + end + describe "with rack_autodetect => true" do + let :params do + { :rack_autodetect => true } + end + it { should contain_file('passenger.conf').with_content(/^ RackAutoDetect true$/) } + end + describe "with rails_autodetect => true" do + let :params do + { :rails_autodetect => true } + end + it { should contain_file('passenger.conf').with_content(/^ RailsAutoDetect true$/) } + end + describe "with passenger_root => '/usr/lib/example'" do + let :params do + { :passenger_root => '/usr/lib/example' } + end + it { should contain_file('passenger.conf').with_content(/^ PassengerRoot \/usr\/lib\/example$/) } + end + describe "with passenger_ruby => /user/lib/example/ruby" do + let :params do + { :passenger_ruby => '/user/lib/example/ruby' } + end + it { should contain_file('passenger.conf').with_content(/^ PassengerRuby \/user\/lib\/example\/ruby$/) } + end + + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('passenger') } + it { should contain_package("mod_passenger") } + it { should contain_file('passenger.conf').with({ + 'path' => '/etc/httpd/conf.d/passenger.conf', + }) } + it { should contain_file('passenger.conf').with_content(/^ PassengerRoot \/usr\/share\/rubygems\/gems\/passenger-3.0.17$/) } + it { should contain_file('passenger.conf').with_content(/^ PassengerRuby \/usr\/bin\/ruby$/) } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/perl_spec.rb b/deployment/modules/apache/spec/classes/mod/perl_spec.rb new file mode 100644 index 000000000..0f76abbd9 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/perl_spec.rb @@ -0,0 +1,29 @@ +describe 'apache::mod::perl', :type => :class do + let :pre_condition do + 'include apache' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('perl') } + it { should contain_package("libapache2-mod-perl2") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('perl') } + it { should contain_package("mod_perl") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/php_spec.rb b/deployment/modules/apache/spec/classes/mod/php_spec.rb new file mode 100644 index 000000000..6bcfc432d --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/php_spec.rb @@ -0,0 +1,61 @@ +describe 'apache::mod::php', :type => :class do + describe "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + context "with mpm_module => prefork" do + let :pre_condition do + 'class { "apache": mpm_module => prefork, }' + end + it { should include_class("apache::params") } + it { should contain_apache__mod('php5') } + it { should contain_package("libapache2-mod-php5") } + it { should contain_file("php5.load").with( + :content => "LoadModule php5_module /usr/lib/apache2/modules/libphp5.so\n" + ) } + end + context 'with mpm_module => worker' do + let :pre_condition do + 'class { "apache": mpm_module => worker, }' + end + it 'should raise an error' do + expect { subject.should contain_apache__mod('php5') }.to raise_error Puppet::Error, /mpm_module => 'prefork'/ + end + end + end + describe "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + context "with default params" do + let :pre_condition do + 'class { "apache": }' + end + it { should include_class("apache::params") } + it { should contain_apache__mod('php5') } + it { should contain_package("php") } + it { should contain_file("php5.load").with( + :content => "LoadModule php5_module modules/libphp5.so\n" + ) } + end + context "with mpm_module => prefork" do + let :pre_condition do + 'class { "apache": mpm_module => prefork, }' + end + it { should include_class("apache::params") } + it { should contain_apache__mod('php5') } + it { should contain_package("php") } + it { should contain_file("php5.load").with( + :content => "LoadModule php5_module modules/libphp5.so\n" + ) } + end + end +end diff --git a/deployment/modules/apache/spec/classes/mod/prefork_spec.rb b/deployment/modules/apache/spec/classes/mod/prefork_spec.rb new file mode 100644 index 000000000..fa34a20c8 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/prefork_spec.rb @@ -0,0 +1,35 @@ +describe 'apache::mod::prefork', :type => :class do + let :pre_condition do + 'class { "apache": mpm_module => false, }' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should_not contain_apache__mod('prefork') } + it { should contain_file("/etc/apache2/mods-available/prefork.conf").with_ensure('file') } + it { should contain_file("/etc/apache2/mods-enabled/prefork.conf").with_ensure('link') } + it { should contain_package("apache2-mpm-prefork") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should_not contain_apache__mod('prefork') } + it { should contain_file("/etc/httpd/conf.d/prefork.conf").with_ensure('file') } + it { should contain_file_line("/etc/sysconfig/httpd prefork enable").with({ + 'require' => 'Package[httpd]', + }) + } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/proxy_html_spec.rb b/deployment/modules/apache/spec/classes/mod/proxy_html_spec.rb new file mode 100644 index 000000000..c257fe746 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/proxy_html_spec.rb @@ -0,0 +1,33 @@ +describe 'apache::mod::proxy_html', :type => :class do + let :pre_condition do + [ + 'include apache', + 'include apache::mod::proxy', + 'include apache::mod::proxy_http', + ] + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('proxy_html') } + it { should contain_package("libapache2-mod-proxy-html") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('proxy_html') } + it { should contain_package("mod_proxy_html") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/python_spec.rb b/deployment/modules/apache/spec/classes/mod/python_spec.rb new file mode 100644 index 000000000..09e8cc2f9 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/python_spec.rb @@ -0,0 +1,29 @@ +describe 'apache::mod::python', :type => :class do + let :pre_condition do + 'include apache' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod("python") } + it { should contain_package("libapache2-mod-python") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod("python") } + it { should contain_package("mod_python") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/ssl_spec.rb b/deployment/modules/apache/spec/classes/mod/ssl_spec.rb new file mode 100644 index 000000000..9444d89b4 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/ssl_spec.rb @@ -0,0 +1,41 @@ +describe 'apache::mod::ssl', :type => :class do + let :pre_condition do + 'include apache' + end + context 'on an unsupported OS' do + let :facts do + { + :osfamily => 'Magic', + :operatingsystemrelease => '0', + :concat_basedir => '/dne', + } + end + it { expect { should raise_error(Puppet::Error, "Unsupported operatingsystem:") } } + end + + context 'on a RedHat OS' do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class('apache::params') } + it { should contain_apache__mod('ssl') } + it { should contain_package('mod_ssl') } + end + + context 'on a Debian OS' do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class('apache::params') } + it { should contain_apache__mod('ssl') } + it { should_not contain_package('libapache2-mod-ssl') } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/suphp_spec.rb b/deployment/modules/apache/spec/classes/mod/suphp_spec.rb new file mode 100644 index 000000000..2d6517c33 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/suphp_spec.rb @@ -0,0 +1,27 @@ +describe 'apache::mod::suphp', :type => :class do + let :pre_condition do + 'include apache' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_package("libapache2-mod-suphp") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_package("mod_suphp") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/worker_spec.rb b/deployment/modules/apache/spec/classes/mod/worker_spec.rb new file mode 100644 index 000000000..7d5543275 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/worker_spec.rb @@ -0,0 +1,32 @@ +describe 'apache::mod::worker', :type => :class do + let :pre_condition do + 'class { "apache": mpm_module => false, }' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should_not contain_apache__mod('worker') } + it { should contain_file("/etc/apache2/mods-available/worker.conf").with_ensure('file') } + it { should contain_file("/etc/apache2/mods-enabled/worker.conf").with_ensure('link') } + it { should contain_package("apache2-mpm-worker") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should_not contain_apache__mod('worker') } + it { should contain_file("/etc/httpd/conf.d/worker.conf").with_ensure('file') } + it { should contain_file_line("/etc/sysconfig/httpd worker enable") } + end +end diff --git a/deployment/modules/apache/spec/classes/mod/wsgi_spec.rb b/deployment/modules/apache/spec/classes/mod/wsgi_spec.rb new file mode 100644 index 000000000..30ef523e4 --- /dev/null +++ b/deployment/modules/apache/spec/classes/mod/wsgi_spec.rb @@ -0,0 +1,42 @@ +describe 'apache::mod::wsgi', :type => :class do + let :pre_condition do + 'include apache' + end + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('wsgi') } + it { should contain_package("libapache2-mod-wsgi") } + end + context "on a RedHat OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should include_class("apache::params") } + it { should contain_apache__mod('wsgi') } + it { should contain_package("mod_wsgi") } + + describe "with custom WSGISocketPrefix" do + let :params do + { :wsgi_socket_prefix => 'run/wsgi' } + end + it {should contain_file('wsgi.conf').with_content(/^ WSGISocketPrefix run\/wsgi$/)} + end + describe "with custom WSGIPythonHome" do + let :params do + { :wsgi_python_home => '/path/to/virtenv' } + end + it {should contain_file('wsgi.conf').with_content(/^ WSGIPythonHome \/path\/to\/virtenv$/)} + end + end +end diff --git a/deployment/modules/apache/spec/classes/params_spec.rb b/deployment/modules/apache/spec/classes/params_spec.rb new file mode 100644 index 000000000..39e16b6f3 --- /dev/null +++ b/deployment/modules/apache/spec/classes/params_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe 'apache::params', :type => :class do + context "On a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should contain_apache__params } + + # There are 4 resources in this class currently + # there should not be any more resources because it is a params class + # The resources are class[apache::params], class[main], class[settings], stage[main] + it "Should not contain any resources" do + subject.resources.size.should == 4 + end + end +end diff --git a/deployment/modules/apache/spec/classes/service_spec.rb b/deployment/modules/apache/spec/classes/service_spec.rb new file mode 100644 index 000000000..745b100b5 --- /dev/null +++ b/deployment/modules/apache/spec/classes/service_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper' + +describe 'apache::service', :type => :class do + context "on a Debian OS" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + it { should contain_service("httpd").with( + 'ensure' => 'true', + 'enable' => 'true' + ) + } + + context "with $service_enable => true" do + let (:params) {{ :service_enable => true }} + it { should contain_service("httpd").with( + 'ensure' => 'true', + 'enable' => 'true' + ) + } + end + + context "with $service_enable => false" do + let (:params) {{ :service_enable => false }} + it { should contain_service("httpd").with( + 'ensure' => 'false', + 'enable' => 'false' + ) + } + end + + context "$service_enable must be a bool" do + let (:params) {{ :service_enable => 'not-a-boolean' }} + + it 'should fail' do + expect { + should include_class('apache::service') + }.to raise_error(Puppet::Error, /is not a boolean/) + end + end + end + + + context "on a RedHat 5 OS" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '5', + :concat_basedir => '/dne', + } + end + it { should contain_service("httpd").with( + 'ensure' => 'true', + 'enable' => 'true' + ) + } + end +end diff --git a/deployment/modules/apache/spec/defines/mod_spec.rb b/deployment/modules/apache/spec/defines/mod_spec.rb new file mode 100644 index 000000000..77c8dfd91 --- /dev/null +++ b/deployment/modules/apache/spec/defines/mod_spec.rb @@ -0,0 +1,79 @@ +require 'spec_helper' + +describe 'apache::mod', :type => :define do + let :pre_condition do + 'include apache' + end + context "on a RedHat osfamily" do + let :facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + + describe "for non-special modules" do + let :title do + 'spec_m' + end + it { should include_class("apache::params") } + it "should manage the module load file" do + should contain_file('spec_m.load').with({ + :path => '/etc/httpd/conf.d/spec_m.load', + :content => "LoadModule spec_m_module modules/mod_spec_m.so\n", + :owner => 'root', + :group => 'root', + :mode => '0644', + } ) + end + end + + describe "with shibboleth module and package param passed" do + # name/title for the apache::mod define + let :title do + 'xsendfile' + end + # parameters + let(:params) { {:package => 'mod_xsendfile'} } + + it { should include_class("apache::params") } + it { should contain_package('mod_xsendfile') } + end + end + + context "on a Debian osfamily" do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + + describe "for non-special modules" do + let :title do + 'spec_m' + end + it { should include_class("apache::params") } + it "should manage the module load file" do + should contain_file('spec_m.load').with({ + :path => '/etc/apache2/mods-available/spec_m.load', + :content => "LoadModule spec_m_module /usr/lib/apache2/modules/mod_spec_m.so\n", + :owner => 'root', + :group => 'root', + :mode => '0644', + } ) + end + it "should link the module load file" do + should contain_file('spec_m.load symlink').with({ + :path => '/etc/apache2/mods-enabled/spec_m.load', + :target => '/etc/apache2/mods-available/spec_m.load', + :owner => 'root', + :group => 'root', + :mode => '0644', + } ) + end + end + end +end diff --git a/deployment/modules/apache/spec/defines/vhost_spec.rb b/deployment/modules/apache/spec/defines/vhost_spec.rb new file mode 100644 index 000000000..a2a377707 --- /dev/null +++ b/deployment/modules/apache/spec/defines/vhost_spec.rb @@ -0,0 +1,658 @@ +require 'spec_helper' + +describe 'apache::vhost', :type => :define do + let :pre_condition do + 'class { "apache": default_vhost => false, }' + end + let :title do + 'rspec.example.com' + end + let :default_params do + { + :docroot => '/rspec/docroot', + :port => '84', + } + end + describe 'os-dependent items' do + context "on RedHat based systems" do + let :default_facts do + { + :osfamily => 'RedHat', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + let :params do default_params end + let :facts do default_facts end + it { should include_class("apache") } + it { should include_class("apache::params") } + end + context "on Debian based systems" do + let :default_facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + let :params do default_params end + let :facts do default_facts end + it { should include_class("apache") } + it { should include_class("apache::params") } + it { should contain_file("25-rspec.example.com.conf").with( + :ensure => 'present', + :path => '/etc/apache2/sites-available/25-rspec.example.com.conf' + ) } + it { should contain_file("25-rspec.example.com.conf symlink").with( + :ensure => 'link', + :path => '/etc/apache2/sites-enabled/25-rspec.example.com.conf', + :target => '/etc/apache2/sites-available/25-rspec.example.com.conf' + ) } + end + end + describe 'os-independent items' do + let :facts do + { + :osfamily => 'Debian', + :operatingsystemrelease => '6', + :concat_basedir => '/dne', + } + end + describe 'basic assumptions' do + let :params do default_params end + it { should include_class("apache") } + it { should include_class("apache::params") } + it { should contain_apache__listen(params[:port]) } + it { should contain_apache__namevirtualhost("*:#{params[:port]}") } + end + + context ".conf content" do + [ + { + :title => 'should contain docroot', + :attr => 'docroot', + :value => '/not/default', + :match => [' DocumentRoot /not/default',' '], + }, + { + :title => 'should set a port', + :attr => 'port', + :value => '8080', + :match => '', + }, + { + :title => 'should set an ip', + :attr => 'ip', + :value => '10.0.0.1', + :match => '', + }, + { + :title => 'should set a serveradmin', + :attr => 'serveradmin', + :value => 'test@test.com', + :match => ' ServerAdmin test@test.com' + }, + { + :title => 'should enable ssl', + :attr => 'ssl', + :value => true, + :match => ' SSLEngine on', + }, + { + :title => 'should set a servername', + :attr => 'servername', + :value => 'param.test', + :match => ' ServerName param.test', + }, + { + :title => 'should accept server aliases', + :attr => 'serveraliases', + :value => ['one.com','two.com'], + :match => [' ServerAlias one.com',' ServerAlias two.com'], + }, + { + :title => 'should accept setenv', + :attr => 'setenv', + :value => ['TEST1 one','TEST2 two'], + :match => [' SetEnv TEST1 one',' SetEnv TEST2 two'], + }, + { + :title => 'should accept setenvif', + :attr => 'setenvif', + ## These are bugged in rspec-puppet; the $1 is droped + #:value => ['Host "^([^\.]*)\.website\.com$" CLIENT_NAME=$1'], + #:match => [' SetEnvIf Host "^([^\.]*)\.website\.com$" CLIENT_NAME=$1'], + :value => ['Host "^test\.com$" VHOST_ACCESS=test'], + :match => [' SetEnvIf Host "^test\.com$" VHOST_ACCESS=test'], + }, + { + :title => 'should accept options', + :attr => 'options', + :value => ['Fake','Options'], + :match => ' Options Fake Options', + }, + { + :title => 'should accept overrides', + :attr => 'override', + :value => ['Fake', 'Override'], + :match => ' AllowOverride Fake Override', + }, + { + :title => 'should accept logroot', + :attr => 'logroot', + :value => '/fake/log', + :match => [/CustomLog \/fake\/log\//,/ErrorLog \/fake\/log\//], + }, + { + :title => 'should accept pipe destination for access log', + :attr => 'access_log_pipe', + :value => '| /bin/fake/logging', + :match => /CustomLog "| \/bin\/fake\/logging" combined$/, + }, + { + :title => 'should accept pipe destination for error log', + :attr => 'error_log_pipe', + :value => '| /bin/fake/logging', + :match => /ErrorLog "| \/bin\/fake\/logging" combined$/, + }, + { + :title => 'should accept syslog destination for access log', + :attr => 'access_log_syslog', + :value => 'syslog:local1', + :match => /CustomLog syslog:local1 combined$/, + }, + { + :title => 'should accept syslog destination for error log', + :attr => 'error_log_syslog', + :value => 'syslog', + :match => /ErrorLog syslog$/, + }, + { + :title => 'should accept custom format for access logs', + :attr => 'access_log_format', + :value => '%h %{X-Forwarded-For}i %l %u %t \"%r\" %s %b \"%{Referer}i\" \"%{User-agent}i\" \"Host: %{Host}i\" %T %D', + :match => /CustomLog \/var\/log\/.+_access\.log "%h %\{X-Forwarded-For\}i %l %u %t \\"%r\\" %s %b \\"%\{Referer\}i\\" \\"%\{User-agent\}i\\" \\"Host: %\{Host\}i\\" %T %D"$/, + }, + { + :title => 'should contain access logs', + :attr => 'access_log', + :value => true, + :match => /CustomLog \/var\/log\/.+_access\.log combined$/, + }, + { + :title => 'should not contain access logs', + :attr => 'access_log', + :value => false, + :notmatch => /CustomLog \/var\/log\/.+_access\.log combined$/, + }, + { + :title => 'should contain error logs', + :attr => 'error_log', + :value => true, + :match => /ErrorLog.+$/, + }, + { + :title => 'should not contain error logs', + :attr => 'error_log', + :value => false, + :notmatch => /ErrorLog.+$/, + }, + { + :title => 'should accept scriptaliases', + :attr => 'scriptalias', + :value => '/usr/scripts', + :match => ' ScriptAlias /cgi-bin/ "/usr/scripts/"', + }, + { + :title => 'should accept proxy destinations', + :attr => 'proxy_dest', + :value => 'http://fake.com', + :match => [ + ' ProxyPass / http://fake.com/', + ' ProxyPassReverse / http://fake.com/', + ], + :notmatch => /ProxyPass .+!$/, + }, + { + :title => 'should accept proxy_pass hash', + :attr => 'proxy_pass', + :value => { 'path' => '/path-a', 'url' => 'http://fake.com/a/' }, + :match => [ + ' ProxyPass /path-a http://fake.com/a/', + ' ProxyPassReverse /path-a http://fake.com/a/', + ], + :notmatch => /ProxyPass .+!$/, + }, + { + :title => 'should accept proxy_pass array of hash', + :attr => 'proxy_pass', + :value => [ + { 'path' => '/path-a', 'url' => 'http://fake.com/a/' }, + { 'path' => '/path-b', 'url' => 'http://fake.com/b/' }, + ], + :match => [ + ' ProxyPass /path-a http://fake.com/a/', + ' ProxyPassReverse /path-a http://fake.com/a/', + ' ProxyPass /path-b http://fake.com/b/', + ' ProxyPassReverse /path-b http://fake.com/b/', + ], + :notmatch => /ProxyPass .+!$/, + }, + { + :title => 'should enable rack', + :attr => 'rack_base_uris', + :value => ['/rack1','/rack2'], + :match => [' RackBaseURI /rack1',' RackBaseURI /rack2'], + }, + { + :title => 'should accept request headers', + :attr => 'request_headers', + :value => ['append something', 'unset something_else'], + :match => [ + ' RequestHeader append something', + ' RequestHeader unset something_else', + ], + }, + { + :title => 'should accept rewrite rules', + :attr => 'rewrite_rule', + :value => 'not a real rule', + :match => ' RewriteRule not a real rule', + }, + { + :title => 'should block scm', + :attr => 'block', + :value => 'scm', + :match => ' ', + }, + { + :title => 'should accept a custom fragment', + :attr => 'custom_fragment', + :value => " Some custom fragment line\n That spans multiple lines", + :match => [ + ' Some custom fragment line', + ' That spans multiple lines', + '', + ], + }, + { + :title => 'should accept an array of alias hashes', + :attr => 'aliases', + :value => [ { 'alias' => '/', 'path' => '/var/www'} ], + :match => ' Alias / /var/www', + }, + { + :title => 'should accept an alias hash', + :attr => 'aliases', + :value => { 'alias' => '/', 'path' => '/var/www'}, + :match => ' Alias / /var/www', + }, + { + :title => 'should accept multiple aliases', + :attr => 'aliases', + :value => [ + { 'alias' => '/', 'path' => '/var/www'}, + { 'alias' => '/cgi-bin', 'path' => '/var/www/cgi-bin'}, + { 'alias' => '/css', 'path' => '/opt/someapp/css'}, + ], + :match => [ + ' Alias / /var/www', + ' Alias /cgi-bin /var/www/cgi-bin', + ' Alias /css /opt/someapp/css' + ], + }, + { + :title => 'should accept a suPHP_Engine', + :attr => 'suphp_engine', + :value => 'on', + :match => ' suPHP_Engine on', + }, + { + :title => 'should accept a wsgi script alias', + :attr => 'wsgi_script_aliases', + :value => { '/' => '/var/www/myapp.wsgi'}, + :match => ' WSGIScriptAlias / /var/www/myapp.wsgi', + }, + { + :title => 'should accept multiple wsgi aliases', + :attr => 'wsgi_script_aliases', + :value => { + '/wiki' => '/usr/local/wsgi/scripts/mywiki.wsgi', + '/blog' => '/usr/local/wsgi/scripts/myblog.wsgi', + '/' => '/usr/local/wsgi/scripts/myapp.wsgi', + }, + :match => [ + ' WSGIScriptAlias /wiki /usr/local/wsgi/scripts/mywiki.wsgi', + ' WSGIScriptAlias /blog /usr/local/wsgi/scripts/myblog.wsgi', + ' WSGIScriptAlias / /usr/local/wsgi/scripts/myapp.wsgi' + ], + }, + { + :title => 'should accept a directory', + :attr => 'directories', + :value => { 'path' => '/opt/app' }, + :notmatch => ' ', + :match => [ + ' ', + ' AllowOverride None', + ' Order allow,deny', + ' Allow from all', + ' ', + ], + }, + { + :title => 'should accept directory directives hash', + :attr => 'directories', + :value => { + 'path' => '/opt/app', + 'headers' => 'Set X-Robots-Tag "noindex, noarchive, nosnippet"', + 'allow' => 'from rspec.org', + 'allow_override' => 'Lol', + 'deny' => 'from google.com', + 'options' => '-MultiViews', + 'order' => 'deny,yned', + 'passenger_enabled' => 'onf', + }, + :match => [ + ' ', + ' Header Set X-Robots-Tag "noindex, noarchive, nosnippet"', + ' Allow from rspec.org', + ' AllowOverride Lol', + ' Deny from google.com', + ' Options -MultiViews', + ' Order deny,yned', + ' PassengerEnabled onf', + ' ', + ], + }, + { + :title => 'should accept directory directives with arrays and hashes', + :attr => 'directories', + :value => [ + { + 'path' => '/opt/app1', + 'allow' => 'from rspec.org', + 'allow_override' => ['AuthConfig','Indexes'], + 'deny' => 'from google.com', + 'options' => ['-MultiViews','+MultiViews'], + 'order' => ['deny','yned'], + 'passenger_enabled' => 'onf', + }, + { + 'path' => '/opt/app2', + 'addhandlers' => { + 'handler' => 'cgi-script', + 'extensions' => '.cgi', + }, + }, + ], + :match => [ + ' ', + ' Allow from rspec.org', + ' AllowOverride AuthConfig Indexes', + ' Deny from google.com', + ' Options -MultiViews +MultiViews', + ' Order deny,yned', + ' PassengerEnabled onf', + ' ', + ' ', + ' AllowOverride None', + ' Order allow,deny', + ' Allow from all', + ' AddHandler cgi-script .cgi', + ' ', + ], + }, + { + :title => 'should accept multiple directories', + :attr => 'directories', + :value => [ + { 'path' => '/opt/app' }, + { 'path' => '/var/www' }, + { 'path' => '/rspec/docroot'} + ], + :match => [ + ' ', + ' ', + ' ', + ], + }, + { + :title => 'should contain virtual_docroot', + :attr => 'virtual_docroot', + :value => '/not/default', + :match => [ + ' VirtualDocumentRoot /not/default', + ], + }, + ].each do |param| + describe "when #{param[:attr]} is #{param[:value]}" do + let :params do default_params.merge({ param[:attr].to_sym => param[:value] }) end + + it { should contain_file("25-#{title}.conf").with_mode('0644') } + it param[:title] do + lines = subject.resource('file', "25-#{title}.conf").send(:parameters)[:content].split("\n") + (Array(param[:match]).collect { |x| (lines.grep x).first }.length).should == Array(param[:match]).length + (Array(param[:notmatch]).collect { |x| lines.grep x }.flatten).should be_empty + end + end + end + end + + context 'attribute resources' do + describe 'when access_log_file and access_log_pipe are specified' do + let :params do default_params.merge({ + :access_log_file => 'fake.log', + :access_log_pipe => '| /bin/fake', + }) end + it 'should cause a failure' do + expect {should raise_error(Puppet::Error, 'Apache::Vhost[${name}]: \'access_log_file\' and \'access_log_pipe\' cannot be defined at the same time') } + end + end + describe 'when error_log_file and error_log_pipe are specified' do + let :params do default_params.merge({ + :error_log_file => 'fake.log', + :error_log_pipe => '| /bin/fake', + }) end + it 'should cause a failure' do + expect { should raise_error(Puppet::Error, 'Apache::Vhost[${name}]: \'error_log_file\' and \'error_log_pipe\' cannot be defined at the same time') } + end + end + describe 'when docroot owner is specified' do + let :params do default_params.merge({ + :docroot_owner => 'testuser', + :docroot_group => 'testgroup', + }) end + it 'should set vhost ownership' do + should contain_file(params[:docroot]).with({ + :ensure => :directory, + :owner => 'testuser', + :group => 'testgroup', + }) + end + end + + describe 'when wsgi_daemon_process and wsgi_daemon_process_options are specified' do + let :params do default_params.merge({ + :wsgi_daemon_process => 'example.org', + :wsgi_daemon_process_options => { 'processes' => '2', 'threads' => '15' }, + }) end + it 'should set wsgi_daemon_process_options' do + should contain_file("25-#{title}.conf").with_content( + /^ WSGIDaemonProcess example.org processes=2 threads=15$/ + ) + end + end + + describe 'when rewrite_rule and rewrite_cond are specified' do + let :params do default_params.merge({ + :rewrite_cond => '%{HTTPS} off', + :rewrite_rule => '(.*) https://%{HTTPS_HOST}%{REQUEST_URI}', + }) end + it 'should set RewriteCond' do + should contain_file("25-#{title}.conf").with_content( + /^ RewriteCond %\{HTTPS\} off$/ + ) + end + end + + describe 'when suphp_engine is on and suphp_configpath is specified' do + let :params do default_params.merge({ + :suphp_engine => 'on', + :suphp_configpath => '/etc/php5/apache2', + }) end + it 'should set suphp_configpath' do + should contain_file("25-#{title}.conf").with_content( + /^ suPHP_ConfigPath \/etc\/php5\/apache2$/ + ) + end + end + + describe 'when suphp_engine is on and suphp_addhandler is specified' do + let :params do default_params.merge({ + :suphp_engine => 'on', + :suphp_addhandler => 'x-httpd-php', + }) end + it 'should set suphp_addhandler' do + should contain_file("25-#{title}.conf").with_content( + /^ suPHP_AddHandler x-httpd-php/ + ) + end + end + + describe 'priority/default settings' do + describe 'when neither priority/default is specified' do + let :params do default_params end + it { should contain_file("25-#{title}.conf").with_path( + /25-#{title}.conf/ + ) } + end + describe 'when both priority/default_vhost is specified' do + let :params do + default_params.merge({ + :priority => 15, + :default_vhost => true, + }) + end + it { should contain_file("15-#{title}.conf").with_path( + /15-#{title}.conf/ + ) } + end + describe 'when only priority is specified' do + let :params do + default_params.merge({ :priority => 14, }) + end + it { should contain_file("14-#{title}.conf").with_path( + /14-#{title}.conf/ + ) } + end + describe 'when only default is specified' do + let :params do + default_params.merge({ :default_vhost => true, }) + end + it { should contain_file("10-#{title}.conf").with_path( + /10-#{title}.conf/ + ) } + end + end + + describe 'various ip/port combos' do + describe 'when ip_based is true' do + let :params do default_params.merge({ :ip_based => true }) end + it 'should not specify a NameVirtualHost' do + should contain_apache__listen(params[:port]) + should_not contain_apache__namevirtualhost("*:#{params[:port]}") + end + end + + describe 'when ip_based is default' do + let :params do default_params end + it 'should specify a NameVirtualHost' do + should contain_apache__listen(params[:port]) + should contain_apache__namevirtualhost("*:#{params[:port]}") + end + end + + describe 'when an ip is set' do + let :params do default_params.merge({ :ip => '10.0.0.1' }) end + it 'should specify a NameVirtualHost for the ip' do + should_not contain_apache__listen(params[:port]) + should contain_apache__listen("10.0.0.1:#{params[:port]}") + should contain_apache__namevirtualhost("10.0.0.1:#{params[:port]}") + end + end + + describe 'an ip_based vhost without a port' do + let :params do + { + :docroot => '/fake', + :ip => '10.0.0.1', + :ip_based => true, + } + end + it 'should specify a NameVirtualHost for the ip' do + should_not contain_apache__listen(params[:ip]) + should_not contain_apache__namevirtualhost(params[:ip]) + should contain_file("25-#{title}.conf").with_content %r{} + end + end + end + + describe 'redirect rules' do + describe 'without lockstep arrays' do + let :params do + default_params.merge({ + :redirect_source => [ + '/login', + '/logout', + ], + :redirect_dest => [ + 'http://10.0.0.10/login', + 'http://10.0.0.10/logout', + ], + :redirect_status => [ + 'permanent', + '', + ], + }) + end + + it { should contain_file("25-#{title}.conf").with_content %r{ Redirect permanent /login http://10\.0\.0\.10/login} } + it { should contain_file("25-#{title}.conf").with_content %r{ Redirect /logout http://10\.0\.0\.10/logout} } + end + describe 'without a status' do + let :params do + default_params.merge({ + :redirect_source => [ + '/login', + '/logout', + ], + :redirect_dest => [ + 'http://10.0.0.10/login', + 'http://10.0.0.10/logout', + ], + }) + end + + it { should contain_file("25-#{title}.conf").with_content %r{ Redirect /login http://10\.0\.0\.10/login} } + it { should contain_file("25-#{title}.conf").with_content %r{ Redirect /logout http://10\.0\.0\.10/logout} } + end + describe 'with a single status and dest' do + let :params do + default_params.merge({ + :redirect_source => [ + '/login', + '/logout', + ], + :redirect_dest => 'http://10.0.0.10/test', + :redirect_status => 'permanent', + }) + end + + it { should contain_file("25-#{title}.conf").with_content %r{ Redirect permanent /login http://10\.0\.0\.10/test} } + it { should contain_file("25-#{title}.conf").with_content %r{ Redirect permanent /logout http://10\.0\.0\.10/test} } + end + end + end + end +end diff --git a/deployment/modules/apache/spec/fixtures/modules/site_apache/templates/fake.conf.erb b/deployment/modules/apache/spec/fixtures/modules/site_apache/templates/fake.conf.erb new file mode 100644 index 000000000..019debfe4 --- /dev/null +++ b/deployment/modules/apache/spec/fixtures/modules/site_apache/templates/fake.conf.erb @@ -0,0 +1 @@ +Fake template for rspec. diff --git a/deployment/modules/apache/spec/spec.opts b/deployment/modules/apache/spec/spec.opts new file mode 100644 index 000000000..de653df4b --- /dev/null +++ b/deployment/modules/apache/spec/spec.opts @@ -0,0 +1,4 @@ +--format s +--colour +--loadby mtime +--backtrace diff --git a/deployment/modules/apache/spec/spec_helper.rb b/deployment/modules/apache/spec/spec_helper.rb new file mode 100644 index 000000000..2c6f56649 --- /dev/null +++ b/deployment/modules/apache/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/deployment/modules/apache/spec/spec_helper_system.rb b/deployment/modules/apache/spec/spec_helper_system.rb new file mode 100644 index 000000000..55d51145a --- /dev/null +++ b/deployment/modules/apache/spec/spec_helper_system.rb @@ -0,0 +1,28 @@ +require 'rspec-system/spec_helper' +require 'rspec-system-puppet/helpers' +require 'rspec-system-serverspec/helpers' +include Serverspec::Helper::RSpecSystem +include Serverspec::Helper::DetectOS +include RSpecSystemPuppet::Helpers + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Enable colour + c.tty = true + + c.include RSpecSystemPuppet::Helpers + + # This is where we 'setup' the nodes before running our tests + c.before :suite do + # Install puppet + puppet_install + + # Install modules and dependencies + puppet_module_install(:source => proj_root, :module_name => 'apache') + shell('puppet module install puppetlabs-concat --version 1.0.0') + shell('puppet module install puppetlabs-stdlib --version 2.4.0') + end +end + diff --git a/deployment/modules/apache/spec/system/basic_spec.rb b/deployment/modules/apache/spec/system/basic_spec.rb new file mode 100644 index 000000000..a87f90841 --- /dev/null +++ b/deployment/modules/apache/spec/system/basic_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper_system' + +describe 'basic tests:' do + # Using puppet_apply as a subject + context puppet_apply 'notice("foo")' do + its(:stdout) { should =~ /foo/ } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end +end + +describe 'disable selinux:' do + context puppet_apply ' + exec { "setenforce 0": + path => "/bin:/sbin:/usr/bin:/usr/sbin", + onlyif => "which setenforce && getenforce | grep Enforcing", + } + ' do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + end +end diff --git a/deployment/modules/apache/spec/system/class_spec.rb b/deployment/modules/apache/spec/system/class_spec.rb new file mode 100644 index 000000000..441331658 --- /dev/null +++ b/deployment/modules/apache/spec/system/class_spec.rb @@ -0,0 +1,62 @@ +require 'spec_helper_system' + +describe 'apache class' do + case node.facts['osfamily'] + when 'RedHat' + package_name = 'httpd' + service_name = 'httpd' + when 'Debian' + package_name = 'apache2' + service_name = 'apache2' + end + + context 'default parameters' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'apache': } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + + describe package(package_name) do + it { should be_installed } + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end + end + + context 'custom site/mod dir parameters' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + file { '/apache': ensure => directory, } + class { 'apache': + mod_dir => '/apache/mods', + vhost_dir => '/apache/vhosts', + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end + end +end diff --git a/deployment/modules/apache/spec/system/default_mods_spec.rb b/deployment/modules/apache/spec/system/default_mods_spec.rb new file mode 100644 index 000000000..dbb233856 --- /dev/null +++ b/deployment/modules/apache/spec/system/default_mods_spec.rb @@ -0,0 +1,102 @@ +require 'spec_helper_system' + +case node.facts['osfamily'] +when 'RedHat' + servicename = 'httpd' +when 'Debian' + servicename = 'apache2' +else + raise Error, "Unconfigured OS for apache service on #{node.facts['osfamily']}" +end + +describe 'apache::default_mods class' do + describe 'no default mods' do + # Using puppet_apply as a helper + it 'should apply with no errors' do + pp = <<-EOS + class { 'apache': + default_mods => false, + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + [0,2].should include(r.exit_code) + r.refresh + r.exit_code.should be_zero + end + end + + describe service(servicename) do + it { should be_running } + end + end + + describe 'no default mods and failing' do + # Using puppet_apply as a helper + it 'should apply with errors' do + pp = <<-EOS + class { 'apache': + default_mods => false, + } + apache::vhost { 'defaults.example.com': + docroot => '/var/www/defaults', + aliases => { + alias => '/css', + path => '/var/www/css', + }, + setenv => 'TEST1 one', + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + [4,6].should include(r.exit_code) + end + end + + describe "service #{servicename}" do + it 'should not be running' do + shell("pidof #{servicename}") do |r| + r.exit_code.should eq(1) + end + end + end + end + + describe 'alternative default mods' do + # Using puppet_apply as a helper + it 'should apply with no errors' do + pp = <<-EOS + class { 'apache': + default_mods => [ + 'info', + 'alias', + 'mime', + 'env', + 'expires', + ], + } + apache::vhost { 'defaults.example.com': + docroot => '/var/www/defaults', + aliases => { + alias => '/css', + path => '/var/www/css', + }, + setenv => 'TEST1 one', + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + [0,2].should include(r.exit_code) + r.refresh + r.exit_code.should be_zero + end + end + + describe service(servicename) do + it { should be_running } + end + end +end diff --git a/deployment/modules/apache/spec/system/itk_spec.rb b/deployment/modules/apache/spec/system/itk_spec.rb new file mode 100644 index 000000000..fdbabb9fe --- /dev/null +++ b/deployment/modules/apache/spec/system/itk_spec.rb @@ -0,0 +1,36 @@ +require 'spec_helper_system' + +case node.facts['osfamily'] +when 'Debian' + service_name = 'apache2' +else + # Not implemented yet + service_name = :skip +end + +unless service_name.equal? :skip + describe 'apache::mod::itk class' do + describe 'running puppet code' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'apache': + mpm_module => 'itk', + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + end + + describe service(service_name) do + it { should be_running } + it { should be_enabled } + end + end +end diff --git a/deployment/modules/apache/spec/system/mod_php_spec.rb b/deployment/modules/apache/spec/system/mod_php_spec.rb new file mode 100644 index 000000000..71a806b6b --- /dev/null +++ b/deployment/modules/apache/spec/system/mod_php_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper_system' + +describe 'apache::mod::php class' do + case node.facts['osfamily'] + when 'Debian' + mod_dir = '/etc/apache2/mods-available' + service_name = 'apache2' + when 'RedHat' + mod_dir = '/etc/httpd/conf.d' + service_name = 'httpd' + end + + context "default php config" do + it 'succeeds in puppeting php' do + puppet_apply(%{ + class { 'apache': + mpm_module => 'prefork', + } + class { 'apache::mod::php': } + apache::vhost { 'php.example.com': + port => '80', + docroot => '/var/www/php', + } + host { 'php.example.com': ip => '127.0.0.1', } + file { '/var/www/php/index.php': + ensure => file, + content => "\\n", + } + }) { |r| [0,2].should include r.exit_code} + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end + + describe file("#{mod_dir}/php5.conf") do + it { should contain "DirectoryIndex index.php" } + end + + it 'should answer to php.example.com' do + shell("/usr/bin/curl php.example.com:80") do |r| + r.stdout.should =~ /PHP Version/ + r.exit_code.should == 0 + end + end + end +end diff --git a/deployment/modules/apache/spec/system/mod_suphp_spec.rb b/deployment/modules/apache/spec/system/mod_suphp_spec.rb new file mode 100644 index 000000000..297b2d54a --- /dev/null +++ b/deployment/modules/apache/spec/system/mod_suphp_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper_system' + +describe 'apache::mod::suphp class' do + case node.facts['osfamily'] + when 'Debian' + context "default suphp config" do + it 'succeeds in puppeting suphp' do + puppet_apply(%{ + class { 'apache': + mpm_module => 'prefork', + } + class { 'apache::mod::php': } + class { 'apache::mod::suphp': } + apache::vhost { 'suphp.example.com': + port => '80', + docroot => '/var/www/suphp', + } + host { 'suphp.example.com': ip => '127.0.0.1', } + file { '/var/www/suphp/index.php': + ensure => file, + owner => 'puppet', + group => 'puppet', + content => "\\n", + } + }) { |r| [0,2].should include r.exit_code} + end + + describe service('apache2') do + it { should be_enabled } + it { should be_running } + end + + it 'should answer to suphp.example.com' do + shell("/usr/bin/curl suphp.example.com:80") do |r| + r.stdout.should =~ /^puppet$/ + r.exit_code.should == 0 + end + end + end + when 'RedHat' + # Not implemented yet + end +end diff --git a/deployment/modules/apache/spec/system/prefork_worker_spec.rb b/deployment/modules/apache/spec/system/prefork_worker_spec.rb new file mode 100644 index 000000000..ae7eae9ed --- /dev/null +++ b/deployment/modules/apache/spec/system/prefork_worker_spec.rb @@ -0,0 +1,60 @@ +require 'spec_helper_system' + +case node.facts['osfamily'] +when 'RedHat' + servicename = 'httpd' +when 'Debian' + servicename = 'apache2' +else + raise Error, "Unconfigured OS for apache service on #{node.facts['osfamily']}" +end + +describe 'apache::mod::worker class' do + describe 'running puppet code' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'apache': + mpm_module => 'worker', + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + end + + describe service(servicename) do + it { should be_running } + it { should be_enabled } + end +end + +describe 'apache::mod::prefork class' do + describe 'running puppet code' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'apache': + mpm_module => 'prefork', + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + end + + describe service(servicename) do + it { should be_running } + it { should be_enabled } + end +end diff --git a/deployment/modules/apache/spec/system/service_spec.rb b/deployment/modules/apache/spec/system/service_spec.rb new file mode 100644 index 000000000..5f76600b3 --- /dev/null +++ b/deployment/modules/apache/spec/system/service_spec.rb @@ -0,0 +1,22 @@ +require 'spec_helper_system' + +describe 'apache::service class' do + describe 'adding dependencies in between the base class and service class' do + it 'should work with no errors' do + pp = <<-EOS + class { 'apache': } + file { '/tmp/test': + require => Class['apache'], + notify => Class['apache::service'], + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + [0,2].should include(r.exit_code) + r.refresh + r.exit_code.should be_zero + end + end + end +end diff --git a/deployment/modules/apache/spec/system/vhost_spec.rb b/deployment/modules/apache/spec/system/vhost_spec.rb new file mode 100644 index 000000000..3c8002e4d --- /dev/null +++ b/deployment/modules/apache/spec/system/vhost_spec.rb @@ -0,0 +1,183 @@ +require 'spec_helper_system' + +describe 'apache::vhost define' do + case node.facts['osfamily'] + when 'RedHat' + vhost_dir = '/etc/httpd/conf.d' + package_name = 'httpd' + service_name = 'httpd' + when 'Debian' + vhost_dir = '/etc/apache2/sites-enabled' + package_name = 'apache2' + service_name = 'apache2' + end + + context "default vhost without ssl" do + it 'should create a default vhost config' do + puppet_apply(%{ + class { 'apache': } + }) { |r| [0,2].should include r.exit_code} + end + + describe file("#{vhost_dir}/15-default.conf") do + it { should contain '' } + end + + describe file("#{vhost_dir}/15-default-ssl.conf") do + it { should_not be_file } + end + end + + context 'default vhost with ssl' do + it 'should create default vhost configs' do + puppet_apply(%{ + class { 'apache': + default_ssl_vhost => true, + } + }) { |r| [0,2].should include r.exit_code} + end + + describe file("#{vhost_dir}/15-default.conf") do + it { should contain '' } + end + + describe file("#{vhost_dir}/15-default-ssl.conf") do + it { should contain '' } + it { should contain "SSLEngine on" } + end + end + + context 'new vhost on port 80' do + it 'should configure an apache vhost' do + puppet_apply(%{ + class { 'apache': } + apache::vhost { 'first.example.com': + port => '80', + docroot => '/var/www/first', + } + }) { |r| [0,2].should include r.exit_code} + end + + describe file("#{vhost_dir}/25-first.example.com.conf") do + it { should contain '' } + it { should contain "ServerName first.example.com" } + end + end + + context 'new vhost on port 80' do + it 'should configure two apache vhosts' do + puppet_apply(%{ + class { 'apache': } + apache::vhost { 'first.example.com': + port => '80', + docroot => '/var/www/first', + } + host { 'first.example.com': ip => '127.0.0.1', } + file { '/var/www/first/index.html': + ensure => file, + content => "Hello from first\\n", + } + apache::vhost { 'second.example.com': + port => '80', + docroot => '/var/www/second', + } + host { 'second.example.com': ip => '127.0.0.1', } + file { '/var/www/second/index.html': + ensure => file, + content => "Hello from second\\n", + } + }) { |r| [0,2].should include r.exit_code} + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end + + it 'should answer to first.example.com' do + shell("/usr/bin/curl first.example.com:80") do |r| + r.stdout.should == "Hello from first\n" + r.exit_code.should == 0 + end + end + + it 'should answer to second.example.com' do + shell("/usr/bin/curl second.example.com:80") do |r| + r.stdout.should == "Hello from second\n" + r.exit_code.should == 0 + end + end + end + + context 'apache_directories readme example, adapted' do + it 'should configure a vhost with Files' do + puppet_apply(%{ + class { 'apache': } + apache::vhost { 'files.example.net': + docroot => '/var/www/files', + directories => [ + { path => '~ (\.swp|\.bak|~)$', 'provider' => 'files', 'deny' => 'from all' }, + ], + } + file { '/var/www/files/index.html.bak': + ensure => file, + content => "Hello World\\n", + } + host { 'files.example.net': ip => '127.0.0.1', } + }) { |r| [0,2].should include r.exit_code} + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end + + it 'should answer to files.example.net' do + shell("/usr/bin/curl -sSf files.example.net:80/index.html.bak") do |r| + r.stderr.should =~ /curl: \(22\) The requested URL returned error: 403/ + r.exit_code.should == 22 + end + end + + end + + context 'virtual_docroot hosting separate sites' do + it 'should configure a vhost with VirtualDocumentRoot' do + puppet_apply(%{ + class { 'apache': } + apache::vhost { 'virt.example.com': + vhost_name => '*', + serveraliases => '*virt.example.com', + port => '80', + docroot => '/var/www/virt', + virtual_docroot => '/var/www/virt/%1', + } + host { 'virt.example.com': ip => '127.0.0.1', } + host { 'a.virt.example.com': ip => '127.0.0.1', } + host { 'b.virt.example.com': ip => '127.0.0.1', } + file { [ '/var/www/virt/a', '/var/www/virt/b', ]: ensure => directory, } + file { '/var/www/virt/a/index.html': ensure => file, content => "Hello from a.virt\\n", } + file { '/var/www/virt/b/index.html': ensure => file, content => "Hello from b.virt\\n", } + }) { |r| [0,2].should include r.exit_code} + end + + describe service(service_name) do + it { should be_enabled } + it { should be_running } + end + + it 'should answer to a.virt.example.com' do + shell("/usr/bin/curl a.virt.example.com:80") do |r| + r.stdout.should == "Hello from a.virt\n" + r.exit_code.should == 0 + end + end + + it 'should answer to b.virt.example.com' do + shell("/usr/bin/curl b.virt.example.com:80") do |r| + r.stdout.should == "Hello from b.virt\n" + r.exit_code.should == 0 + end + end + end +end diff --git a/deployment/modules/apache/spec/unit/provider/a2mod/gentoo_spec.rb b/deployment/modules/apache/spec/unit/provider/a2mod/gentoo_spec.rb new file mode 100644 index 000000000..ddb9dddda --- /dev/null +++ b/deployment/modules/apache/spec/unit/provider/a2mod/gentoo_spec.rb @@ -0,0 +1,184 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +provider_class = Puppet::Type.type(:a2mod).provider(:gentoo) + +describe provider_class do + before :each do + provider_class.clear + end + + [:conf_file, :instances, :modules, :initvars, :conf_file, :clear].each do |method| + it "should respond to the class method #{method}" do + provider_class.should respond_to(method) + end + end + + describe "when fetching modules" do + before do + @filetype = mock() + end + + it "should return a sorted array of the defined parameters" do + @filetype.expects(:read).returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n}) + provider_class.expects(:filetype).returns(@filetype) + + provider_class.modules.should == %w{bar baz foo} + end + + it "should cache the module list" do + @filetype.expects(:read).once.returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAZ"\n}) + provider_class.expects(:filetype).once.returns(@filetype) + + 2.times { provider_class.modules.should == %w{bar baz foo} } + end + + it "should normalize parameters" do + @filetype.expects(:read).returns(%Q{APACHE2_OPTS="-D FOO -D BAR -D BAR"\n}) + provider_class.expects(:filetype).returns(@filetype) + + provider_class.modules.should == %w{bar foo} + end + end + + describe "when prefetching" do + it "should match providers to resources" do + provider = mock("ssl_provider", :name => "ssl") + resource = mock("ssl_resource") + resource.expects(:provider=).with(provider) + + provider_class.expects(:instances).returns([provider]) + provider_class.prefetch("ssl" => resource) + end + end + + describe "when flushing" do + before :each do + @filetype = mock() + @filetype.stubs(:backup) + provider_class.expects(:filetype).at_least_once.returns(@filetype) + + @info = mock() + @info.stubs(:[]).with(:name).returns("info") + @info.stubs(:provider=) + + @mpm = mock() + @mpm.stubs(:[]).with(:name).returns("mpm") + @mpm.stubs(:provider=) + + @ssl = mock() + @ssl.stubs(:[]).with(:name).returns("ssl") + @ssl.stubs(:provider=) + end + + it "should add modules whose ensure is present" do + @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""}) + @filetype.expects(:write).with(%Q{APACHE2_OPTS="-D INFO"}) + + @info.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("info" => @info) + + provider_class.flush + end + + it "should remove modules whose ensure is present" do + @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-D INFO"}) + @filetype.expects(:write).with(%Q{APACHE2_OPTS=""}) + + @info.stubs(:should).with(:ensure).returns(:absent) + @info.stubs(:provider=) + provider_class.prefetch("info" => @info) + + provider_class.flush + end + + it "should not modify providers without resources" do + @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-D INFO -D MPM"}) + @filetype.expects(:write).with(%Q{APACHE2_OPTS="-D MPM -D SSL"}) + + @info.stubs(:should).with(:ensure).returns(:absent) + provider_class.prefetch("info" => @info) + + @ssl.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("ssl" => @ssl) + + provider_class.flush + end + + it "should write the modules in sorted order" do + @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""}) + @filetype.expects(:write).with(%Q{APACHE2_OPTS="-D INFO -D MPM -D SSL"}) + + @mpm.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("mpm" => @mpm) + @info.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("info" => @info) + @ssl.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("ssl" => @ssl) + + provider_class.flush + end + + it "should write the records back once" do + @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""}) + @filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-D INFO -D SSL"}) + + @info.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("info" => @info) + + @ssl.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("ssl" => @ssl) + + provider_class.flush + end + + it "should only modify the line containing APACHE2_OPTS" do + @filetype.expects(:read).at_least_once.returns(%Q{# Comment\nAPACHE2_OPTS=""\n# Another comment}) + @filetype.expects(:write).once.with(%Q{# Comment\nAPACHE2_OPTS="-D INFO"\n# Another comment}) + + @info.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("info" => @info) + provider_class.flush + end + + it "should restore any arbitrary arguments" do + @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-Y -D MPM -X"}) + @filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-Y -X -D INFO -D MPM"}) + + @info.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("info" => @info) + provider_class.flush + end + + it "should backup the file once if changes were made" do + @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS=""}) + @filetype.expects(:write).once.with(%Q{APACHE2_OPTS="-D INFO -D SSL"}) + + @info.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("info" => @info) + + @ssl.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("ssl" => @ssl) + + @filetype.unstub(:backup) + @filetype.expects(:backup) + provider_class.flush + end + + it "should not write the file or run backups if no changes were made" do + @filetype.expects(:read).at_least_once.returns(%Q{APACHE2_OPTS="-X -D INFO -D SSL -Y"}) + @filetype.expects(:write).never + + @info.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("info" => @info) + + @ssl.stubs(:should).with(:ensure).returns(:present) + provider_class.prefetch("ssl" => @ssl) + + @filetype.unstub(:backup) + @filetype.expects(:backup).never + provider_class.flush + end + end +end diff --git a/deployment/modules/apache/templates/httpd.conf.erb b/deployment/modules/apache/templates/httpd.conf.erb new file mode 100644 index 000000000..2bfb2734a --- /dev/null +++ b/deployment/modules/apache/templates/httpd.conf.erb @@ -0,0 +1,86 @@ +# Security +ServerTokens OS +ServerSignature On +TraceEnable Off + +ServerName "<%= @servername %>" +ServerRoot "<%= @httpd_dir %>" +PidFile <%= @pidfile %> +Timeout 120 +KeepAlive <%= @keepalive %> +MaxKeepAliveRequests 100 +KeepAliveTimeout <%= @keepalive_timeout %> + +User <%= @user %> +Group <%= @group %> + +AccessFileName .htaccess + + Order allow,deny + Deny from all + Satisfy all + + + + Options FollowSymLinks + AllowOverride None + + +DefaultType none +HostnameLookups Off +ErrorLog <%= @logroot %>/<%= @error_log %> +LogLevel warn +<% if @sendfile %> +EnableSendfile <%= @sendfile %> +<% end %> + +#Listen 80 +Include <%= @mod_load_dir %>/*.load +<% if @mod_load_dir != @confd_dir and @mod_load_dir != @vhost_load_dir -%> +Include <%= @mod_load_dir %>/*.conf +<% end -%> +Include <%= @ports_file %> + +LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined +LogFormat "%h %l %u %t \"%r\" %>s %b" common +LogFormat "%{Referer}i -> %U" referer +LogFormat "%{User-agent}i" agent + +Include <%= @confd_dir %>/*.conf +<% if @vhost_load_dir != @confd_dir -%> +Include <%= @vhost_load_dir %>/*.conf +<% end -%> + +<% if @error_documents -%> +# /usr/share/apache2/error on debian +Alias /error/ "<%= @error_documents_path %>/" + +"> + AllowOverride None + Options IncludesNoExec + AddOutputFilter Includes html + AddHandler type-map var + Order allow,deny + Allow from all + LanguagePriority en cs de es fr it nl sv pt-br ro + ForceLanguagePriority Prefer Fallback + + +ErrorDocument 400 /error/HTTP_BAD_REQUEST.html.var +ErrorDocument 401 /error/HTTP_UNAUTHORIZED.html.var +ErrorDocument 403 /error/HTTP_FORBIDDEN.html.var +ErrorDocument 404 /error/HTTP_NOT_FOUND.html.var +ErrorDocument 405 /error/HTTP_METHOD_NOT_ALLOWED.html.var +ErrorDocument 408 /error/HTTP_REQUEST_TIME_OUT.html.var +ErrorDocument 410 /error/HTTP_GONE.html.var +ErrorDocument 411 /error/HTTP_LENGTH_REQUIRED.html.var +ErrorDocument 412 /error/HTTP_PRECONDITION_FAILED.html.var +ErrorDocument 413 /error/HTTP_REQUEST_ENTITY_TOO_LARGE.html.var +ErrorDocument 414 /error/HTTP_REQUEST_URI_TOO_LARGE.html.var +ErrorDocument 415 /error/HTTP_UNSUPPORTED_MEDIA_TYPE.html.var +ErrorDocument 500 /error/HTTP_INTERNAL_SERVER_ERROR.html.var +ErrorDocument 501 /error/HTTP_NOT_IMPLEMENTED.html.var +ErrorDocument 502 /error/HTTP_BAD_GATEWAY.html.var +ErrorDocument 503 /error/HTTP_SERVICE_UNAVAILABLE.html.var +ErrorDocument 506 /error/HTTP_VARIANT_ALSO_VARIES.html.var +<% end -%> diff --git a/deployment/modules/apache/templates/listen.erb b/deployment/modules/apache/templates/listen.erb new file mode 100644 index 000000000..8fc871b0a --- /dev/null +++ b/deployment/modules/apache/templates/listen.erb @@ -0,0 +1,6 @@ +<%# Listen should always be one of: + - + - : + - [ +-%> +Listen <%= @listen_addr_port %> diff --git a/deployment/modules/apache/templates/mod/alias.conf.erb b/deployment/modules/apache/templates/mod/alias.conf.erb new file mode 100644 index 000000000..9e8b0de9b --- /dev/null +++ b/deployment/modules/apache/templates/mod/alias.conf.erb @@ -0,0 +1,7 @@ +Alias /icons/ "<%= @icons_path %>/" +"> + Options Indexes MultiViews + AllowOverride None + Order allow,deny + Allow from all + diff --git a/deployment/modules/apache/templates/mod/autoindex.conf.erb b/deployment/modules/apache/templates/mod/autoindex.conf.erb new file mode 100644 index 000000000..ef6bbebea --- /dev/null +++ b/deployment/modules/apache/templates/mod/autoindex.conf.erb @@ -0,0 +1,56 @@ +IndexOptions FancyIndexing VersionSort HTMLTable NameWidth=* DescriptionWidth=* Charset=UTF-8 +AddIconByEncoding (CMP,/icons/compressed.gif) x-compress x-gzip x-bzip2 + +AddIconByType (TXT,/icons/text.gif) text/* +AddIconByType (IMG,/icons/image2.gif) image/* +AddIconByType (SND,/icons/sound2.gif) audio/* +AddIconByType (VID,/icons/movie.gif) video/* + +AddIcon /icons/binary.gif .bin .exe +AddIcon /icons/binhex.gif .hqx +AddIcon /icons/tar.gif .tar +AddIcon /icons/world2.gif .wrl .wrl.gz .vrml .vrm .iv +AddIcon /icons/compressed.gif .Z .z .tgz .gz .zip +AddIcon /icons/a.gif .ps .ai .eps +AddIcon /icons/layout.gif .html .shtml .htm .pdf +AddIcon /icons/text.gif .txt +AddIcon /icons/c.gif .c +AddIcon /icons/p.gif .pl .py +AddIcon /icons/f.gif .for +AddIcon /icons/dvi.gif .dvi +AddIcon /icons/uuencoded.gif .uu +AddIcon /icons/script.gif .conf .sh .shar .csh .ksh .tcl +AddIcon /icons/tex.gif .tex +AddIcon /icons/bomb.gif /core +AddIcon (SND,/icons/sound2.gif) .ogg +AddIcon (VID,/icons/movie.gif) .ogm + +AddIcon /icons/back.gif .. +AddIcon /icons/hand.right.gif README +AddIcon /icons/folder.gif ^^DIRECTORY^^ +AddIcon /icons/blank.gif ^^BLANKICON^^ + +AddIcon /icons/odf6odt-20x22.png .odt +AddIcon /icons/odf6ods-20x22.png .ods +AddIcon /icons/odf6odp-20x22.png .odp +AddIcon /icons/odf6odg-20x22.png .odg +AddIcon /icons/odf6odc-20x22.png .odc +AddIcon /icons/odf6odf-20x22.png .odf +AddIcon /icons/odf6odb-20x22.png .odb +AddIcon /icons/odf6odi-20x22.png .odi +AddIcon /icons/odf6odm-20x22.png .odm + +AddIcon /icons/odf6ott-20x22.png .ott +AddIcon /icons/odf6ots-20x22.png .ots +AddIcon /icons/odf6otp-20x22.png .otp +AddIcon /icons/odf6otg-20x22.png .otg +AddIcon /icons/odf6otc-20x22.png .otc +AddIcon /icons/odf6otf-20x22.png .otf +AddIcon /icons/odf6oti-20x22.png .oti +AddIcon /icons/odf6oth-20x22.png .oth + +DefaultIcon /icons/unknown.gif +ReadmeName README.html +HeaderName HEADER.html + +IndexIgnore .??* *~ *# HEADER* README* RCS CVS *,v *,t diff --git a/deployment/modules/apache/templates/mod/cgid.conf.erb b/deployment/modules/apache/templates/mod/cgid.conf.erb new file mode 100644 index 000000000..d771012de --- /dev/null +++ b/deployment/modules/apache/templates/mod/cgid.conf.erb @@ -0,0 +1 @@ +ScriptSock <%= @cgisock_path %> diff --git a/deployment/modules/apache/templates/mod/dav_fs.conf.erb b/deployment/modules/apache/templates/mod/dav_fs.conf.erb new file mode 100644 index 000000000..50edf004e --- /dev/null +++ b/deployment/modules/apache/templates/mod/dav_fs.conf.erb @@ -0,0 +1 @@ +DAVLockDB <%= @dav_lock %> diff --git a/deployment/modules/apache/templates/mod/deflate.conf.erb b/deployment/modules/apache/templates/mod/deflate.conf.erb new file mode 100644 index 000000000..d0997dfeb --- /dev/null +++ b/deployment/modules/apache/templates/mod/deflate.conf.erb @@ -0,0 +1,4 @@ +AddOutputFilterByType DEFLATE text/html text/plain text/xml +AddOutputFilterByType DEFLATE text/css +AddOutputFilterByType DEFLATE application/x-javascript application/javascript application/ecmascript +AddOutputFilterByType DEFLATE application/rss+xml diff --git a/deployment/modules/apache/templates/mod/dir.conf.erb b/deployment/modules/apache/templates/mod/dir.conf.erb new file mode 100644 index 000000000..741f6ae03 --- /dev/null +++ b/deployment/modules/apache/templates/mod/dir.conf.erb @@ -0,0 +1 @@ +DirectoryIndex <%= @indexes.join(' ') %> diff --git a/deployment/modules/apache/templates/mod/disk_cache.conf.erb b/deployment/modules/apache/templates/mod/disk_cache.conf.erb new file mode 100644 index 000000000..0c7e2c4b7 --- /dev/null +++ b/deployment/modules/apache/templates/mod/disk_cache.conf.erb @@ -0,0 +1,8 @@ + + + CacheEnable disk / + CacheRoot "<%= @cache_root %>" + CacheDirLevels 2 + CacheDirLength 1 + + diff --git a/deployment/modules/apache/templates/mod/info.conf.erb b/deployment/modules/apache/templates/mod/info.conf.erb new file mode 100644 index 000000000..01ffe95a9 --- /dev/null +++ b/deployment/modules/apache/templates/mod/info.conf.erb @@ -0,0 +1,6 @@ + + SetHandler server-info + Order deny,allow + Deny from all + Allow from <%= Array(@allow_from).join(" ") %> + diff --git a/deployment/modules/apache/templates/mod/itk.conf.erb b/deployment/modules/apache/templates/mod/itk.conf.erb new file mode 100644 index 000000000..f45f2b35d --- /dev/null +++ b/deployment/modules/apache/templates/mod/itk.conf.erb @@ -0,0 +1,8 @@ + + StartServers <%= @startservers %> + MinSpareServers <%= @minspareservers %> + MaxSpareServers <%= @maxspareservers %> + ServerLimit <%= @serverlimit %> + MaxClients <%= @maxclients %> + MaxRequestsPerChild <%= @maxrequestsperchild %> + diff --git a/deployment/modules/apache/templates/mod/ldap.conf.erb b/deployment/modules/apache/templates/mod/ldap.conf.erb new file mode 100644 index 000000000..14f33ab2b --- /dev/null +++ b/deployment/modules/apache/templates/mod/ldap.conf.erb @@ -0,0 +1,7 @@ + + SetHandler ldap-status + Order deny,allow + Deny from all + Allow from 127.0.0.1 ::1 + Satisfy all + diff --git a/deployment/modules/apache/templates/mod/mime.conf.erb b/deployment/modules/apache/templates/mod/mime.conf.erb new file mode 100644 index 000000000..34f4add92 --- /dev/null +++ b/deployment/modules/apache/templates/mod/mime.conf.erb @@ -0,0 +1,36 @@ +TypesConfig /etc/mime.types + +AddType application/x-compress .Z +AddType application/x-gzip .gz .tgz +AddType application/x-bzip2 .bz2 + +AddLanguage ca .ca +AddLanguage cs .cz .cs +AddLanguage da .dk +AddLanguage de .de +AddLanguage el .el +AddLanguage en .en +AddLanguage eo .eo +AddLanguage es .es +AddLanguage et .et +AddLanguage fr .fr +AddLanguage he .he +AddLanguage hr .hr +AddLanguage it .it +AddLanguage ja .ja +AddLanguage ko .ko +AddLanguage ltz .ltz +AddLanguage nl .nl +AddLanguage nn .nn +AddLanguage no .no +AddLanguage pl .po +AddLanguage pt .pt +AddLanguage pt-BR .pt-br +AddLanguage ru .ru +AddLanguage sv .sv +AddLanguage zh-CN .zh-cn +AddLanguage zh-TW .zh-tw + +AddHandler type-map var +AddType text/html .shtml +AddOutputFilter INCLUDES .shtml diff --git a/deployment/modules/apache/templates/mod/mime_magic.conf.erb b/deployment/modules/apache/templates/mod/mime_magic.conf.erb new file mode 100644 index 000000000..ee69bca4a --- /dev/null +++ b/deployment/modules/apache/templates/mod/mime_magic.conf.erb @@ -0,0 +1 @@ +MIMEMagicFile conf/magic diff --git a/deployment/modules/apache/templates/mod/mpm_event.conf.erb b/deployment/modules/apache/templates/mod/mpm_event.conf.erb new file mode 100644 index 000000000..eb6f1ff5f --- /dev/null +++ b/deployment/modules/apache/templates/mod/mpm_event.conf.erb @@ -0,0 +1,9 @@ + + StartServers 2 + MinSpareThreads 25 + MaxSpareThreads 75 + ThreadLimit 64 + ThreadsPerChild 25 + MaxClients 150 + MaxRequestsPerChild 0 + diff --git a/deployment/modules/apache/templates/mod/negotiation.conf.erb b/deployment/modules/apache/templates/mod/negotiation.conf.erb new file mode 100644 index 000000000..50921019b --- /dev/null +++ b/deployment/modules/apache/templates/mod/negotiation.conf.erb @@ -0,0 +1,2 @@ +LanguagePriority en ca cs da de el eo es et fr he hr it ja ko ltz nl nn no pl pt pt-BR ru sv zh-CN zh-TW +ForceLanguagePriority Prefer Fallback diff --git a/deployment/modules/apache/templates/mod/passenger.conf.erb b/deployment/modules/apache/templates/mod/passenger.conf.erb new file mode 100644 index 000000000..0be2c997a --- /dev/null +++ b/deployment/modules/apache/templates/mod/passenger.conf.erb @@ -0,0 +1,27 @@ +# The Passanger Apache module configuration file is being +# managed by Puppet and changes will be overwritten. + + PassengerRoot <%= @passenger_root %> + PassengerRuby <%= @passenger_ruby %> + <%- if @passenger_high_performance -%> + PassengerHighPerformance <%= @passenger_high_performance %> + <%- end -%> + <%- if @passenger_max_pool_size -%> + PassengerMaxPoolSize <%= @passenger_max_pool_size %> + <%- end -%> + <%- if @passenger_pool_idle_time -%> + PassengerPoolIdleTime <%= @passenger_pool_idle_time %> + <%- end -%> + <%- if @passenger_max_requests -%> + PassengerMaxRequests <%= @passenger_max_requests %> + <%- end -%> + <%- if @passenger_stat_throttle_rate -%> + PassengerStatThrottleRate <%= @passenger_stat_throttle_rate %> + <%- end -%> + <%- if @rack_autodetect -%> + RackAutoDetect <%= @rack_autodetect %> + <%- end -%> + <%- if @rails_autodetect -%> + RailsAutoDetect <%= @rails_autodetect %> + <%- end -%> + diff --git a/deployment/modules/apache/templates/mod/php5.conf.erb b/deployment/modules/apache/templates/mod/php5.conf.erb new file mode 100644 index 000000000..9eef7628a --- /dev/null +++ b/deployment/modules/apache/templates/mod/php5.conf.erb @@ -0,0 +1,30 @@ +# +# PHP is an HTML-embedded scripting language which attempts to make it +# easy for developers to write dynamically generated webpages. +# +# +# LoadModule php5_module modules/libphp5.so +# +# +# # Use of the "ZTS" build with worker is experimental, and no shared +# # modules are supported. +# LoadModule php5_module modules/libphp5-zts.so +# + +# +# Cause the PHP interpreter to handle files with a .php extension. +# +AddHandler php5-script .php +AddType text/html .php + +# +# Add index.php to the list of files that will be served as directory +# indexes. +# +DirectoryIndex index.php + +# +# Uncomment the following line to allow PHP to pretty-print .phps +# files as PHP source code: +# +#AddType application/x-httpd-php-source .phps diff --git a/deployment/modules/apache/templates/mod/prefork.conf.erb b/deployment/modules/apache/templates/mod/prefork.conf.erb new file mode 100644 index 000000000..aabfdf7b2 --- /dev/null +++ b/deployment/modules/apache/templates/mod/prefork.conf.erb @@ -0,0 +1,8 @@ + + StartServers <%= @startservers %> + MinSpareServers <%= @minspareservers %> + MaxSpareServers <%= @maxspareservers %> + ServerLimit <%= @serverlimit %> + MaxClients <%= @maxclients %> + MaxRequestsPerChild <%= @maxrequestsperchild %> + diff --git a/deployment/modules/apache/templates/mod/proxy.conf.erb b/deployment/modules/apache/templates/mod/proxy.conf.erb new file mode 100644 index 000000000..d4531a519 --- /dev/null +++ b/deployment/modules/apache/templates/mod/proxy.conf.erb @@ -0,0 +1,21 @@ +# +# Proxy Server directives. Uncomment the following lines to +# enable the proxy server: +# + + # Do not enable proxying with ProxyRequests until you have secured your + # server. Open proxy servers are dangerous both to your network and to the + # Internet at large. + ProxyRequests <%= @proxy_requests %> + + + Order deny,allow + Deny from all + Allow from <%= Array(@allow_from).join(" ") %> + + + # Enable/disable the handling of HTTP/1.1 "Via:" headers. + # ("Full" adds the server version; "Block" removes all outgoing Via: headers) + # Set to one of: Off | On | Full | Block + ProxyVia On + diff --git a/deployment/modules/apache/templates/mod/proxy_html.conf.erb b/deployment/modules/apache/templates/mod/proxy_html.conf.erb new file mode 100644 index 000000000..7f5898ef7 --- /dev/null +++ b/deployment/modules/apache/templates/mod/proxy_html.conf.erb @@ -0,0 +1,24 @@ +<% if @proxy_html_loadfiles -%> +<% Array(@proxy_html_loadfiles).each do |loadfile| -%> +LoadFile <%= loadfile %> +<% end -%> + +<% end -%> +ProxyHTMLLinks a href +ProxyHTMLLinks area href +ProxyHTMLLinks link href +ProxyHTMLLinks img src longdesc usemap +ProxyHTMLLinks object classid codebase data usemap +ProxyHTMLLinks q cite +ProxyHTMLLinks blockquote cite +ProxyHTMLLinks ins cite +ProxyHTMLLinks del cite +ProxyHTMLLinks form action +ProxyHTMLLinks input src usemap +ProxyHTMLLinks head profileProxyHTMLLinks base href +ProxyHTMLLinks script src for + +ProxyHTMLEvents onclick ondblclick onmousedown onmouseup \ + onmouseover onmousemove onmouseout onkeypress \ + onkeydown onkeyup onfocus onblur onload \ + onunload onsubmit onreset onselect onchange diff --git a/deployment/modules/apache/templates/mod/reqtimeout.conf.erb b/deployment/modules/apache/templates/mod/reqtimeout.conf.erb new file mode 100644 index 000000000..9a18800da --- /dev/null +++ b/deployment/modules/apache/templates/mod/reqtimeout.conf.erb @@ -0,0 +1,2 @@ +RequestReadTimeout header=20-40,minrate=500 +RequestReadTimeout body=10,minrate=500 diff --git a/deployment/modules/apache/templates/mod/setenvif.conf.erb b/deployment/modules/apache/templates/mod/setenvif.conf.erb new file mode 100644 index 000000000..d31c79fe5 --- /dev/null +++ b/deployment/modules/apache/templates/mod/setenvif.conf.erb @@ -0,0 +1,34 @@ +# +# The following directives modify normal HTTP response behavior to +# handle known problems with browser implementations. +# +BrowserMatch "Mozilla/2" nokeepalive +BrowserMatch "MSIE 4\.0b2;" nokeepalive downgrade-1.0 force-response-1.0 +BrowserMatch "RealPlayer 4\.0" force-response-1.0 +BrowserMatch "Java/1\.0" force-response-1.0 +BrowserMatch "JDK/1\.0" force-response-1.0 + +# +# The following directive disables redirects on non-GET requests for +# a directory that does not include the trailing slash. This fixes a +# problem with Microsoft WebFolders which does not appropriately handle +# redirects for folders with DAV methods. +# Same deal with Apple's DAV filesystem and Gnome VFS support for DAV. +# +BrowserMatch "Microsoft Data Access Internet Publishing Provider" redirect-carefully +BrowserMatch "MS FrontPage" redirect-carefully +BrowserMatch "^WebDrive" redirect-carefully +BrowserMatch "^WebDAVFS/1.[0123]" redirect-carefully +BrowserMatch "^gnome-vfs/1.0" redirect-carefully +BrowserMatch "^gvfs/1" redirect-carefully +BrowserMatch "^XML Spy" redirect-carefully +BrowserMatch "^Dreamweaver-WebDAV-SCM1" redirect-carefully +BrowserMatch " Konqueror/4" redirect-carefully + + + BrowserMatch "MSIE [2-6]" \ + nokeepalive ssl-unclean-shutdown \ + downgrade-1.0 force-response-1.0 + # MSIE 7 and newer should be able to use keepalive + BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown + diff --git a/deployment/modules/apache/templates/mod/ssl.conf.erb b/deployment/modules/apache/templates/mod/ssl.conf.erb new file mode 100644 index 000000000..854a0d0a6 --- /dev/null +++ b/deployment/modules/apache/templates/mod/ssl.conf.erb @@ -0,0 +1,21 @@ + + SSLRandomSeed startup builtin + SSLRandomSeed startup file:/dev/urandom 512 + SSLRandomSeed connect builtin + SSLRandomSeed connect file:/dev/urandom 512 + + AddType application/x-x509-ca-cert .crt + AddType application/x-pkcs7-crl .crl + + SSLPassPhraseDialog builtin + SSLSessionCache shmcb:<%= @session_cache %> + SSLSessionCacheTimeout 300 +<% if @ssl_compression -%> + SSLCompression Off +<% end -%> + SSLMutex <%= @ssl_mutex %> + SSLCryptoDevice builtin + SSLHonorCipherOrder On + SSLCipherSuite HIGH:MEDIUM:!aNULL:!MD5 + SSLProtocol all -SSLv2 + diff --git a/deployment/modules/apache/templates/mod/status.conf.erb b/deployment/modules/apache/templates/mod/status.conf.erb new file mode 100644 index 000000000..b29324ee9 --- /dev/null +++ b/deployment/modules/apache/templates/mod/status.conf.erb @@ -0,0 +1,12 @@ + + SetHandler server-status + Order deny,allow + Deny from all + Allow from 127.0.0.1 ::1 + +ExtendedStatus On + + + # Show Proxy LoadBalancer status in mod_status + ProxyStatus On + diff --git a/deployment/modules/apache/templates/mod/suphp.conf.erb b/deployment/modules/apache/templates/mod/suphp.conf.erb new file mode 100644 index 000000000..95fbf97c7 --- /dev/null +++ b/deployment/modules/apache/templates/mod/suphp.conf.erb @@ -0,0 +1,19 @@ + + AddType application/x-httpd-suphp .php .php3 .php4 .php5 .phtml + suPHP_AddHandler application/x-httpd-suphp + + + suPHP_Engine on + + + # By default, disable suPHP for debian packaged web applications as files + # are owned by root and cannot be executed by suPHP because of min_uid. + + suPHP_Engine off + + +# # Use a specific php config file (a dir which contains a php.ini file) +# suPHP_ConfigPath /etc/php4/cgi/suphp/ +# # Tells mod_suphp NOT to handle requests with the type . +# suPHP_RemoveHandler + diff --git a/deployment/modules/apache/templates/mod/userdir.conf.erb b/deployment/modules/apache/templates/mod/userdir.conf.erb new file mode 100644 index 000000000..cfe2e3879 --- /dev/null +++ b/deployment/modules/apache/templates/mod/userdir.conf.erb @@ -0,0 +1,19 @@ + +<% if @disable_root -%> + UserDir disabled root +<% end -%> + UserDir <%= @dir %> + + /*/<%= @dir %>> + AllowOverride FileInfo AuthConfig Limit Indexes + Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec + + Order allow,deny + Allow from all + + + Order deny,allow + Deny from all + + + diff --git a/deployment/modules/apache/templates/mod/worker.conf.erb b/deployment/modules/apache/templates/mod/worker.conf.erb new file mode 100644 index 000000000..f0bba3908 --- /dev/null +++ b/deployment/modules/apache/templates/mod/worker.conf.erb @@ -0,0 +1,9 @@ + + ServerLimit <%= @serverlimit %> + StartServers <%= @startservers %> + MaxClients <%= @maxclients %> + MinSpareThreads <%= @minsparethreads %> + MaxSpareThreads <%= @maxsparethreads %> + ThreadsPerChild <%= @threadsperchild %> + MaxRequestsPerChild <%= @maxrequestsperchild %> + diff --git a/deployment/modules/apache/templates/mod/wsgi.conf.erb b/deployment/modules/apache/templates/mod/wsgi.conf.erb new file mode 100644 index 000000000..f0611fc65 --- /dev/null +++ b/deployment/modules/apache/templates/mod/wsgi.conf.erb @@ -0,0 +1,10 @@ +# The WSGI Apache module configuration file is being +# managed by Puppet an changes will be overwritten. + + <%- if @wsgi_socket_prefix -%> + WSGISocketPrefix <%= @wsgi_socket_prefix %> + <%- end -%> + <%- if @wsgi_python_home -%> + WSGIPythonHome <%= @wsgi_python_home %> + <%- end -%> + diff --git a/deployment/modules/apache/templates/namevirtualhost.erb b/deployment/modules/apache/templates/namevirtualhost.erb new file mode 100644 index 000000000..cf767680f --- /dev/null +++ b/deployment/modules/apache/templates/namevirtualhost.erb @@ -0,0 +1,8 @@ +<%# NameVirtualHost should always be one of: + - * + - *: + - _default_: + - + - : +-%> +NameVirtualHost <%= @addr_port %> diff --git a/deployment/modules/apache/templates/ports_header.erb b/deployment/modules/apache/templates/ports_header.erb new file mode 100644 index 000000000..4908db4ad --- /dev/null +++ b/deployment/modules/apache/templates/ports_header.erb @@ -0,0 +1,5 @@ +# ************************************ +# Listen & NameVirtualHost resources in module puppetlabs-apache +# Managed by Puppet +# ************************************ + diff --git a/deployment/modules/apache/templates/vhost.conf.erb b/deployment/modules/apache/templates/vhost.conf.erb new file mode 100644 index 000000000..83317e229 --- /dev/null +++ b/deployment/modules/apache/templates/vhost.conf.erb @@ -0,0 +1,47 @@ +# ************************************ +# Vhost template in module puppetlabs-apache +# Managed by Puppet +# ************************************ + +> + ServerName <%= @servername %> +<% if @serveradmin -%> + ServerAdmin <%= @serveradmin %> +<% end -%> + + ## Vhost docroot +<% if @virtual_docroot -%> + VirtualDocumentRoot <%= @virtual_docroot %> +<% else -%> + DocumentRoot <%= @docroot %> +<% end -%> +<%= scope.function_template(['apache/vhost/_aliases.erb']) -%> + +<%= scope.function_template(['apache/vhost/_itk.erb']) -%> + + ## Directories, there should at least be a declaration for <%= @docroot %> +<%= scope.function_template(['apache/vhost/_directories.erb']) -%> + + ## Logging +<% if @error_log -%> + ErrorLog <%= @error_log_destination %> +<% end -%> + LogLevel warn + ServerSignature Off +<% if @access_log -%> + CustomLog <%= @access_log_destination %> <%= @_access_log_format %> +<% end -%> +<%= scope.function_template(['apache/vhost/_block.erb']) -%> +<%= scope.function_template(['apache/vhost/_proxy.erb']) -%> +<%= scope.function_template(['apache/vhost/_rack.erb']) -%> +<%= scope.function_template(['apache/vhost/_redirect.erb']) -%> +<%= scope.function_template(['apache/vhost/_rewrite.erb']) -%> +<%= scope.function_template(['apache/vhost/_scriptalias.erb']) -%> +<%= scope.function_template(['apache/vhost/_serveralias.erb']) -%> +<%= scope.function_template(['apache/vhost/_setenv.erb']) -%> +<%= scope.function_template(['apache/vhost/_ssl.erb']) -%> +<%= scope.function_template(['apache/vhost/_suphp.erb']) -%> +<%= scope.function_template(['apache/vhost/_requestheader.erb']) -%> +<%= scope.function_template(['apache/vhost/_wsgi.erb']) -%> +<%= scope.function_template(['apache/vhost/_custom_fragment.erb']) -%> + diff --git a/deployment/modules/apache/templates/vhost/_aliases.erb b/deployment/modules/apache/templates/vhost/_aliases.erb new file mode 100644 index 000000000..90c7d168b --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_aliases.erb @@ -0,0 +1,8 @@ +<% if @aliases and ! @aliases.empty? -%> + ## Alias declarations for resources outside the DocumentRoot + <%- [@aliases].flatten.compact.each do |alias_statement| -%> + <%- if alias_statement["alias"] != '' and alias_statement["path"] != ''-%> + Alias <%= alias_statement["alias"] %> <%= alias_statement["path"] %> + <%- end -%> + <%- end -%> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_block.erb b/deployment/modules/apache/templates/vhost/_block.erb new file mode 100644 index 000000000..f235f89d2 --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_block.erb @@ -0,0 +1,10 @@ +<% if @block and ! @block.empty? -%> + + ## Block access statements +<% if @block.include? 'scm' -%> + # Block access to SCM directories. + + Deny From All + +<% end -%> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_custom_fragment.erb b/deployment/modules/apache/templates/vhost/_custom_fragment.erb new file mode 100644 index 000000000..973964655 --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_custom_fragment.erb @@ -0,0 +1,5 @@ +<% if @custom_fragment -%> + + ## Custom fragment +<%= @custom_fragment %> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_directories.erb b/deployment/modules/apache/templates/vhost/_directories.erb new file mode 100644 index 000000000..3f4405edb --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_directories.erb @@ -0,0 +1,89 @@ +<% if @_directories and ! @_directories.empty? -%> + <%- [@_directories].flatten.compact.each do |directory| -%> + <%- if directory['path'] and directory['path'] != ''-%> + + <%- provider = 'Directory' -%> + <%- if directory['provider'] and [ 'directory', 'location', 'files' ].include?(directory['provider']) -%> + <%- provider = directory['provider'].capitalize -%> + <%- end -%> + <<%= provider + ' ' + directory['path'] %>> + <%- if directory['headers'] -%> + <%- Array(directory['headers']).each do |header| -%> + Header <%= header %> + <%- end -%> + <%- end -%> + <%- if directory['options'] -%> + Options <%= Array(directory['options']).join(' ') %> + <%- end -%> + <%- if directory['allow_override'] -%> + AllowOverride <%= Array(directory['allow_override']).join(' ') %> + <%- else -%> + AllowOverride None + <%- end -%> + <%- if directory['order'] and directory['order'] != '' -%> + Order <%= Array(directory['order']).join(',') %> + <%- else -%> + Order allow,deny + <%- end -%> + <%- if directory['deny'] and directory['deny'] != '' -%> + Deny <%= directory['deny'] %> + <%- end -%> + <%- if directory['allow'] and directory['allow'] != '' -%> + Allow <%= directory['allow'] %> + <%- else -%> + Allow from all + <%- end -%> + <%- if directory['addhandlers'] and ! directory['addhandlers'].empty? -%> + <%- [directory['addhandlers']].flatten.compact.each do |addhandler| -%> + AddHandler <%= addhandler['handler'] %> <%= Array(addhandler['extensions']).join(' ') %> + <%- end -%> + <%- end -%> + <%- if directory['passenger_enabled'] and directory['passenger_enabled'] != '' -%> + PassengerEnabled <%= directory['passenger_enabled'] %> + <%- end -%> + <%- if directory['auth_type'] -%> + AuthType <%= directory['auth_type'] %> + <%- end -%> + <%- if directory['auth_name'] -%> + AuthName "<%= directory['auth_name'] %>" + <%- end -%> + <%- if directory['auth_digest_algorithm'] -%> + AuthDigestAlgorithm <%= directory['auth_digest_algorithm'] %> + <%- end -%> + <%- if directory['auth_digest_domain'] -%> + AuthDigestDomain <%= Array(directory['auth_digest_domain']).join(' ') %> + <%- end -%> + <%- if directory['auth_digest_nonce_lifetime'] -%> + AuthDigestNonceLifetime <%= directory['auth_digest_nonce_lifetime'] %> + <%- end -%> + <%- if directory['auth_digest_provider'] -%> + AuthDigestProvider <%= directory['auth_digest_provider'] %> + <%- end -%> + <%- if directory['auth_digest_qop'] -%> + AuthDigestQop <%= directory['auth_digest_qop'] %> + <%- end -%> + <%- if directory['auth_digest_shmem_size'] -%> + AuthDigestShmemSize <%= directory['auth_digest_shmem_size'] %> + <%- end -%> + <%- if directory['auth_basic_authoritative'] -%> + AuthBasicAuthoritative <%= directory['auth_basic_authoritative'] %> + <%- end -%> + <%- if directory['auth_basic_fake'] -%> + AuthBasicFake <%= directory['auth_basic_fake'] %> + <%- end -%> + <%- if directory['auth_basic_provider'] -%> + AuthBasicProvider <%= directory['auth_basic_provider'] %> + <%- end -%> + <%- if directory['auth_user_file'] -%> + AuthUserFile <%= directory['auth_user_file'] %> + <%- end -%> + <%- if directory['auth_require'] -%> + Require <%= directory['auth_require'] %> + <%- end -%> + <%- if directory['custom_fragment'] -%> + <%= directory['custom_fragment'] %> + <%- end -%> + > + <%- end -%> + <%- end -%> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_itk.erb b/deployment/modules/apache/templates/vhost/_itk.erb new file mode 100644 index 000000000..7d3bb5166 --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_itk.erb @@ -0,0 +1,28 @@ +<% if @itk and ! @itk.empty? -%> + ## ITK statement + + <%- if @itk["user"] and @itk["group"] -%> + AssignUserId <%= @itk["user"] %> <%= @itk["group"] %> + <%- end -%> + <%- if @itk["assignuieridexpr"] -%> + AssignUserIdExpr <%= @itk["assignuieridexpr"] %> + <%- end -%> + <%- if @itk["assignuiergroupexpr"] -%> + AssignGroupIdExpr <%= @itk["assignuiergroupexpr"] %> + <%- end -%> + <%- if @itk["maxclientvhost"] -%> + MaxClientsVHost <%= @itk["maxclientvhost"] %> + <%- end -%> + <%- if @itk["nice"] -%> + NiceValue <%= @itk["nice"] %> + <%- end -%> + <%- if @kernelversion >= '3.5.0' -%> + <%- if @itk["limituidrange"] -%> + LimitUIDRange <%= @itk["limituidrange"] %> + <%- end -%> + <%- if @itk["limitgidrange"] -%> + LimitGIDRange <%= @itk["limitgidrange"] %> + <%- end -%> + <%- end -%> + +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_proxy.erb b/deployment/modules/apache/templates/vhost/_proxy.erb new file mode 100644 index 000000000..badf73abb --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_proxy.erb @@ -0,0 +1,21 @@ +<% if @proxy_dest or @proxy_pass -%> + + ## Proxy rules + ProxyRequests Off + + Order deny,allow + Allow from all + +<%- end -%> +<% [@proxy_pass].flatten.compact.each do |proxy| %> + ProxyPass <%= proxy['path'] %> <%= proxy['url'] %> + ProxyPassReverse <%= proxy['path'] %> <%= proxy['url'] %> +<% end %> +<% if @proxy_dest -%> +<% Array(@no_proxy_uris).each do |uri| %> + ProxyPass <%= uri %> ! +<% end %> + ProxyPass / <%= @proxy_dest %>/ + ProxyPassReverse / <%= @proxy_dest %>/ + ProxyPreserveHost On +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_rack.erb b/deployment/modules/apache/templates/vhost/_rack.erb new file mode 100644 index 000000000..4a5b5f1cd --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_rack.erb @@ -0,0 +1,7 @@ +<% if @rack_base_uris -%> + + ## Enable rack +<% Array(@rack_base_uris).each do |uri| -%> + RackBaseURI <%= uri %> +<% end -%> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_redirect.erb b/deployment/modules/apache/templates/vhost/_redirect.erb new file mode 100644 index 000000000..66eee5e6d --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_redirect.erb @@ -0,0 +1,12 @@ +<% if @redirect_source and @redirect_dest -%> +<% @redirect_dest_a = Array(@redirect_dest) -%> +<% @redirect_source_a = Array(@redirect_source) -%> +<% @redirect_status_a = Array(@redirect_status) -%> + + ## Redirect rules +<% @redirect_source_a.each_with_index do |source, i| -%> +<% @redirect_dest_a[i] ||= @redirect_dest_a[0] -%> +<% @redirect_status_a[i] ||= @redirect_status_a[0] -%> + Redirect <%= "#{@redirect_status_a[i]} " %><%= source %> <%= @redirect_dest_a[i] %> +<% end -%> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_requestheader.erb b/deployment/modules/apache/templates/vhost/_requestheader.erb new file mode 100644 index 000000000..9f175052b --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_requestheader.erb @@ -0,0 +1,10 @@ +<% if @request_headers and ! @request_headers.empty? -%> + + ## Request header rules + ## as per http://httpd.apache.org/docs/2.2/mod/mod_headers.html#requestheader + <%- Array(@request_headers).each do |request_statement| -%> + <%- if request_statement != '' -%> + RequestHeader <%= request_statement %> + <%- end -%> + <%- end -%> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_rewrite.erb b/deployment/modules/apache/templates/vhost/_rewrite.erb new file mode 100644 index 000000000..a39db1c96 --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_rewrite.erb @@ -0,0 +1,14 @@ +<% if @rewrite_rule -%> + + ## Rewrite rules + RewriteEngine On +<% if @rewrite_base -%> + RewriteBase <%= @rewrite_base %> +<% end -%> +<% if @rewrite_cond -%> +<% Array(@rewrite_cond).each do |cond| -%> + RewriteCond <%= cond %> +<% end -%> +<% end -%> + RewriteRule <%= @rewrite_rule %> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_scriptalias.erb b/deployment/modules/apache/templates/vhost/_scriptalias.erb new file mode 100644 index 000000000..0262055f3 --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_scriptalias.erb @@ -0,0 +1,14 @@ +<% if @scriptalias -%> + + ## Script alias directives + ScriptAlias /cgi-bin/ "<%= @scriptalias %>/" + "> + AllowOverride None + Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch + Order allow,deny + Allow from all +<% if @ssl -%> + SSLOptions +StdEnvVars +<% end -%> + +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_serveralias.erb b/deployment/modules/apache/templates/vhost/_serveralias.erb new file mode 100644 index 000000000..278b6ddc5 --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_serveralias.erb @@ -0,0 +1,7 @@ +<% if @serveraliases and ! @serveraliases.empty? -%> + + ## Server aliases +<% Array(@serveraliases).each do |serveralias| -%> + ServerAlias <%= serveralias %> +<% end -%> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_setenv.erb b/deployment/modules/apache/templates/vhost/_setenv.erb new file mode 100644 index 000000000..d5f9ea845 --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_setenv.erb @@ -0,0 +1,12 @@ +<% if @setenv and ! @setenv.empty? -%> + + ## SetEnv/SetEnvIf for environment variables +<% Array(@setenv).each do |envvar| -%> + SetEnv <%= envvar %> +<% end -%> +<% end -%> +<% if @setenvif and ! @setenvif.empty? -%> +<% Array(@setenvif).each do |envifvar| -%> + SetEnvIf <%= envifvar %> +<% end -%> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_ssl.erb b/deployment/modules/apache/templates/vhost/_ssl.erb new file mode 100644 index 000000000..239c30494 --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_ssl.erb @@ -0,0 +1,26 @@ +<% if @ssl -%> + + ## SSL directives + SSLEngine on + SSLCertificateFile <%= @ssl_cert %> + SSLCertificateKeyFile <%= @ssl_key %> +<% if @ssl_chain -%> + SSLCertificateChainFile <%= @ssl_chain %> +<% end -%> + SSLCACertificatePath <%= @ssl_certs_dir %> +<% if @ssl_ca -%> + SSLCACertificateFile <%= @ssl_ca %> +<% end -%> +<% if @ssl_crl_path -%> + SSLCARevocationPath <%= @ssl_crl_path %> +<% end -%> +<% if @ssl_crl -%> + SSLCARevocationFile <%= @ssl_crl %> +<% end -%> +<% if @sslproxyengine -%> + SSLProxyEngine On +<% end -%> + + SSLOptions +StdEnvVars + +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_suphp.erb b/deployment/modules/apache/templates/vhost/_suphp.erb new file mode 100644 index 000000000..37aa299aa --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_suphp.erb @@ -0,0 +1,11 @@ +<% if @suphp_engine == 'on' -%> +<% if @suphp_addhandler -%> + suPHP_AddHandler <%= @suphp_addhandler %> +<% end -%> +<% if @suphp_engine -%> + suPHP_Engine <%= @suphp_engine %> +<% end -%> +<% if @suphp_configpath -%> + suPHP_ConfigPath <%= @suphp_configpath %> +<% end -%> +<% end -%> diff --git a/deployment/modules/apache/templates/vhost/_wsgi.erb b/deployment/modules/apache/templates/vhost/_wsgi.erb new file mode 100644 index 000000000..d9970bddc --- /dev/null +++ b/deployment/modules/apache/templates/vhost/_wsgi.erb @@ -0,0 +1,15 @@ +<% if @wsgi_daemon_process and @wsgi_daemon_process_options -%> + WSGIDaemonProcess <%= @wsgi_daemon_process %> <%= @wsgi_daemon_process_options.collect { |k,v| "#{k}=#{v}"}.sort.join(' ') %> +<% elsif @wsgi_daemon_process and !@wsgi_daemon_process_options -%> + WSGIDaemonProcess <%= @wsgi_daemon_process %> +<% end -%> +<% if @wsgi_process_group -%> + WSGIProcessGroup <%= @wsgi_process_group %> +<% end -%> +<% if @wsgi_script_aliases and ! @wsgi_script_aliases.empty? -%> + <%- @wsgi_script_aliases.each do |a, p| -%> + <%- if a != '' and p != ''-%> + WSGIScriptAlias <%= a %> <%= p %> + <%- end -%> + <%- end -%> +<% end -%> diff --git a/deployment/modules/apache/tests/apache.pp b/deployment/modules/apache/tests/apache.pp new file mode 100644 index 000000000..0d4543564 --- /dev/null +++ b/deployment/modules/apache/tests/apache.pp @@ -0,0 +1,6 @@ +include apache +include apache::mod::php +include apache::mod::cgi +include apache::mod::userdir +include apache::mod::disk_cache +include apache::mod::proxy_http diff --git a/deployment/modules/apache/tests/dev.pp b/deployment/modules/apache/tests/dev.pp new file mode 100644 index 000000000..805ad7e37 --- /dev/null +++ b/deployment/modules/apache/tests/dev.pp @@ -0,0 +1 @@ +include apache::dev diff --git a/deployment/modules/apache/tests/init.pp b/deployment/modules/apache/tests/init.pp new file mode 100644 index 000000000..b3f9f13aa --- /dev/null +++ b/deployment/modules/apache/tests/init.pp @@ -0,0 +1 @@ +include apache diff --git a/deployment/modules/apache/tests/mods.pp b/deployment/modules/apache/tests/mods.pp new file mode 100644 index 000000000..59362bd9a --- /dev/null +++ b/deployment/modules/apache/tests/mods.pp @@ -0,0 +1,9 @@ +## Default mods + +# Base class. Declares default vhost on port 80 and default ssl +# vhost on port 443 listening on all interfaces and serving +# $apache::docroot, and declaring our default set of modules. +class { 'apache': + default_mods => true, +} + diff --git a/deployment/modules/apache/tests/mods_custom.pp b/deployment/modules/apache/tests/mods_custom.pp new file mode 100644 index 000000000..0ae699c73 --- /dev/null +++ b/deployment/modules/apache/tests/mods_custom.pp @@ -0,0 +1,16 @@ +## custom mods + +# Base class. Declares default vhost on port 80 and default ssl +# vhost on port 443 listening on all interfaces and serving +# $apache::docroot, and declaring a custom set of modules. +class { 'apache': + default_mods => [ + 'info', + 'alias', + 'mime', + 'env', + 'setenv', + 'expires', + ], +} + diff --git a/deployment/modules/apache/tests/php.pp b/deployment/modules/apache/tests/php.pp new file mode 100644 index 000000000..618e0ebd2 --- /dev/null +++ b/deployment/modules/apache/tests/php.pp @@ -0,0 +1 @@ +include apache::php diff --git a/deployment/modules/apache/tests/vhost.pp b/deployment/modules/apache/tests/vhost.pp new file mode 100644 index 000000000..10aa9e324 --- /dev/null +++ b/deployment/modules/apache/tests/vhost.pp @@ -0,0 +1,185 @@ +## Default vhosts, and custom vhosts +# NB: Please see the other vhost_*.pp example files for further +# examples. + +# Base class. Declares default vhost on port 80 and default ssl +# vhost on port 443 listening on all interfaces and serving +# $apache::docroot +class { 'apache': } + +# Most basic vhost +apache::vhost { 'first.example.com': + port => '80', + docroot => '/var/www/first', +} + +# Vhost with different docroot owner/group +apache::vhost { 'second.example.com': + port => '80', + docroot => '/var/www/second', + docroot_owner => 'third', + docroot_group => 'third', +} + +# Vhost with serveradmin +apache::vhost { 'third.example.com': + port => '80', + docroot => '/var/www/third', + serveradmin => 'admin@example.com', +} + +# Vhost with ssl (uses default ssl certs) +apache::vhost { 'ssl.example.com': + port => '443', + docroot => '/var/www/ssl', + ssl => true, +} + +# Vhost with ssl and specific ssl certs +apache::vhost { 'fourth.example.com': + port => '443', + docroot => '/var/www/fourth', + ssl => true, + ssl_cert => '/etc/ssl/fourth.example.com.cert', + ssl_key => '/etc/ssl/fourth.example.com.key', +} + +# Vhost with english title and servername parameter +apache::vhost { 'The fifth vhost': + servername => 'fifth.example.com', + port => '80', + docroot => '/var/www/fifth', +} + +# Vhost with server aliases +apache::vhost { 'sixth.example.com': + serveraliases => [ + 'sixth.example.org', + 'sixth.example.net', + ], + port => '80', + docroot => '/var/www/fifth', +} + +# Vhost with alternate options +apache::vhost { 'seventh.example.com': + port => '80', + docroot => '/var/www/seventh', + options => [ + 'Indexes', + 'MultiViews', + ], +} + +# Vhost with AllowOverride for .htaccess +apache::vhost { 'eighth.example.com': + port => '80', + docroot => '/var/www/eighth', + override => 'All', +} + +# Vhost with access and error logs disabled +apache::vhost { 'ninth.example.com': + port => '80', + docroot => '/var/www/ninth', + access_log => false, + error_log => false, +} + +# Vhost with custom access and error logs and logroot +apache::vhost { 'tenth.example.com': + port => '80', + docroot => '/var/www/tenth', + access_log_file => 'tenth_vhost.log', + error_log_file => 'tenth_vhost_error.log', + logroot => '/var/log', +} + +# Vhost with a cgi-bin +apache::vhost { 'eleventh.example.com': + port => '80', + docroot => '/var/www/eleventh', + scriptalias => '/usr/lib/cgi-bin', +} + +# Vhost with a proxypass configuration +apache::vhost { 'twelfth.example.com': + port => '80', + docroot => '/var/www/twelfth', + proxy_dest => 'http://internal.example.com:8080/twelfth', + no_proxy_uris => ['/login','/logout'], +} + +# Vhost to redirect /login and /logout +apache::vhost { 'thirteenth.example.com': + port => '80', + docroot => '/var/www/thirteenth', + redirect_source => [ + '/login', + '/logout', + ], + redirect_dest => [ + 'http://10.0.0.10/login', + 'http://10.0.0.10/logout', + ], +} + +# Vhost to permamently redirect +apache::vhost { 'fourteenth.example.com': + port => '80', + docroot => '/var/www/fourteenth', + redirect_source => '/blog', + redirect_dest => 'http://blog.example.com', + redirect_status => 'permanent', +} + +# Vhost with a rack configuration +apache::vhost { 'fifteenth.example.com': + port => '80', + docroot => '/var/www/fifteenth', + rack_base_uris => ['/rackapp1', '/rackapp2'], +} + +# Vhost to redirect non-ssl to ssl +apache::vhost { 'sixteenth.example.com non-ssl': + servername => 'sixteenth.example.com', + port => '80', + docroot => '/var/www/sixteenth', + rewrite_cond => '%{HTTPS} off', + rewrite_rule => '(.*) https://%{HTTPS_HOST}%{REQUEST_URI}', +} +apache::vhost { 'sixteenth.example.com ssl': + servername => 'sixteenth.example.com', + port => '443', + docroot => '/var/www/sixteenth', + ssl => true, +} + +# Vhost to block repository files +apache::vhost { 'seventeenth.example.com': + port => '80', + docroot => '/var/www/seventeenth', + block => 'scm', +} + +# Vhost with special environment variables +apache::vhost { 'eighteenth.example.com': + port => '80', + docroot => '/var/www/eighteenth', + setenv => ['SPECIAL_PATH /foo/bin','KILROY was_here'], +} +apache::vhost { 'nineteenth.example.com': + port => '80', + docroot => '/var/www/nineteenth', + setenvif => 'Host "^([^\.]*)\.website\.com$" CLIENT_NAME=$1', +} + +# Vhost with alias for subdomain mapped to same named directory +# http://example.com.loc => /var/www/example.com +apache::vhost { 'subdomain.loc': + vhost_name => '*', + port => '80', + virtual_docroot => '/var/www/%-2+', + docroot => '/var/www', + serveraliases => ['*.loc',], +} diff --git a/deployment/modules/apache/tests/vhost_directories.pp b/deployment/modules/apache/tests/vhost_directories.pp new file mode 100644 index 000000000..d8fcc0f8f --- /dev/null +++ b/deployment/modules/apache/tests/vhost_directories.pp @@ -0,0 +1,30 @@ +# Base class. Declares default vhost on port 80 and default ssl +# vhost on port 443 listening on all interfaces and serving +# $apache::docroot +class { 'apache': } + +# Example from README adapted. +apache::vhost { 'readme.example.net': + docroot => '/var/www/readme', + directories => [ + { path => '/var/www/readme', 'ServerTokens' => 'prod' }, + { path => '/usr/share/empty', 'allow' => 'from all' }, + ], +} + +# location test +apache::vhost { 'location.example.net': + docroot => '/var/www/location', + directories => [ + { path => '/location', 'provider' => 'location', 'ServerTokens' => 'prod' }, + ], +} + +# files test, curedly disable access to accidental backup files. +apache::vhost { 'files.example.net': + docroot => '/var/www/files', + directories => [ + { path => '~ (\.swp|\.bak|~)$', 'provider' => 'files', 'deny' => 'from all' }, + ], +} + diff --git a/deployment/modules/apache/tests/vhost_ip_based.pp b/deployment/modules/apache/tests/vhost_ip_based.pp new file mode 100644 index 000000000..dc0fa4f33 --- /dev/null +++ b/deployment/modules/apache/tests/vhost_ip_based.pp @@ -0,0 +1,25 @@ +## IP-based vhosts on any listen port +# IP-based vhosts respond to requests on specific IP addresses. + +# Base class. Turn off the default vhosts; we will be declaring +# all vhosts below. +class { 'apache': + default_vhost => false, +} + +# Listen on port 80 and 81; required because the following vhosts +# are not declared with a port parameter. +apache::listen { '80': } +apache::listen { '81': } + +# IP-based vhosts +apache::vhost { 'first.example.com': + ip => '10.0.0.10', + docroot => '/var/www/first', + ip_based => true, +} +apache::vhost { 'second.example.com': + ip => '10.0.0.11', + docroot => '/var/www/second', + ip_based => true, +} diff --git a/deployment/modules/apache/tests/vhost_ssl.pp b/deployment/modules/apache/tests/vhost_ssl.pp new file mode 100644 index 000000000..8e7a2b279 --- /dev/null +++ b/deployment/modules/apache/tests/vhost_ssl.pp @@ -0,0 +1,23 @@ +## SSL-enabled vhosts +# SSL-enabled vhosts respond only to HTTPS queries. + +# Base class. Turn off the default vhosts; we will be declaring +# all vhosts below. +class { 'apache': + default_vhost => false, +} + +# Non-ssl vhost +apache::vhost { 'first.example.com non-ssl': + servername => 'first.example.com', + port => '80', + docroot => '/var/www/first', +} + +# SSL vhost at the same domain +apache::vhost { 'first.example.com ssl': + servername => 'first.example.com', + port => '443', + docroot => '/var/www/first', + ssl => true, +} diff --git a/deployment/modules/apache/tests/vhosts_without_listen.pp b/deployment/modules/apache/tests/vhosts_without_listen.pp new file mode 100644 index 000000000..e7d6cc036 --- /dev/null +++ b/deployment/modules/apache/tests/vhosts_without_listen.pp @@ -0,0 +1,53 @@ +## Declare ip-based and name-based vhosts +# Mixing Name-based vhost with IP-specific vhosts requires `add_listen => +# 'false'` on the non-IP vhosts + +# Base class. Turn off the default vhosts; we will be declaring +# all vhosts below. +class { 'apache': + default_vhost => false, +} + + +# Add two an IP-based vhost on 10.0.0.10, ssl and non-ssl +apache::vhost { 'The first IP-based vhost, non-ssl': + servername => 'first.example.com', + ip => '10.0.0.10', + port => '80', + ip_based => true, + docroot => '/var/www/first', +} +apache::vhost { 'The first IP-based vhost, ssl': + servername => 'first.example.com', + ip => '10.0.0.10', + port => '443', + ip_based => true, + docroot => '/var/www/first-ssl', + ssl => true, +} + +# Two name-based vhost listening on 10.0.0.20 +apache::vhost { 'second.example.com': + ip => '10.0.0.20', + port => '80', + docroot => '/var/www/second', +} +apache::vhost { 'third.example.com': + ip => '10.0.0.20', + port => '80', + docroot => '/var/www/third', +} + +# Two name-based vhosts without IPs specified, so that they will answer on either 10.0.0.10 or 10.0.0.20 . It is requried to declare +# `add_listen => 'false'` to disable declaring "Listen 80" which will conflict +# with the IP-based preceeding vhosts. +apache::vhost { 'fourth.example.com': + port => '80', + docroot => '/var/www/fourth', + add_listen => false, +} +apache::vhost { 'fifth.example.com': + port => '80', + docroot => '/var/www/fifth', + add_listen => false, +} diff --git a/deployment/modules/apt/manifests/init.pp b/deployment/modules/apt/manifests/init.pp new file mode 100644 index 000000000..56f4fd725 --- /dev/null +++ b/deployment/modules/apt/manifests/init.pp @@ -0,0 +1,6 @@ +class apt { + exec { 'apt-get update': + provider => shell, + command => 'apt-get update' + } +} diff --git a/deployment/modules/concat/CHANGELOG b/deployment/modules/concat/CHANGELOG new file mode 100644 index 000000000..f8141d7f7 --- /dev/null +++ b/deployment/modules/concat/CHANGELOG @@ -0,0 +1,66 @@ +2013-08-09 1.0.0 + +Summary: + +Many new features and bugfixes in this release, and if you're a heavy concat +user you should test carefully before upgrading. The features should all be +backwards compatible but only light testing has been done from our side before +this release. + +Features: +- New parameters in concat: + - `replace`: specify if concat should replace existing files. + - `ensure_newline`: controls if fragments should contain a newline at the end. +- Improved README documentation. +- Add rspec:system tests (rake spec:system to test concat) + +Bugfixes +- Gracefully handle \n in a fragment resource name. +- Adding more helpful message for 'pluginsync = true' +- Allow passing `source` and `content` directly to file resource, rather than +defining resource defaults. +- Added -r flag to read so that filenames with \ will be read correctly. +- sort always uses LANG=C. +- Allow WARNMSG to contain/start with '#'. +- Replace while-read pattern with for-do in order to support Solaris. + +CHANGELOG: +- 2010/02/19 - initial release +- 2010/03/12 - add support for 0.24.8 and newer + - make the location of sort configurable + - add the ability to add shell comment based warnings to + top of files + - add the ablity to create empty files +- 2010/04/05 - fix parsing of WARN and change code style to match rest + of the code + - Better and safer boolean handling for warn and force + - Don't use hard coded paths in the shell script, set PATH + top of the script + - Use file{} to copy the result and make all fragments owned + by root. This means we can chnage the ownership/group of the + resulting file at any time. + - You can specify ensure => "/some/other/file" in concat::fragment + to include the contents of a symlink into the final file. +- 2010/04/16 - Add more cleaning of the fragment name - removing / from the $name +- 2010/05/22 - Improve documentation and show the use of ensure => +- 2010/07/14 - Add support for setting the filebucket behavior of files +- 2010/10/04 - Make the warning message configurable +- 2010/12/03 - Add flags to make concat work better on Solaris - thanks Jonathan Boyett +- 2011/02/03 - Make the shell script more portable and add a config option for root group +- 2011/06/21 - Make base dir root readable only for security +- 2011/06/23 - Set base directory using a fact instead of hardcoding it +- 2011/06/23 - Support operating as non privileged user +- 2011/06/23 - Support dash instead of bash or sh +- 2011/07/11 - Better solaris support +- 2011/12/05 - Use fully qualified variables +- 2011/12/13 - Improve Nexenta support +- 2012/04/11 - Do not use any GNU specific extensions in the shell script +- 2012/03/24 - Comply to community style guides +- 2012/05/23 - Better errors when basedir isnt set +- 2012/05/31 - Add spec tests +- 2012/07/11 - Include concat::setup in concat improving UX +- 2012/08/14 - Puppet Lint improvements +- 2012/08/30 - The target path can be different from the $name +- 2012/08/30 - More Puppet Lint cleanup +- 2012/09/04 - RELEASE 0.2.0 +- 2012/12/12 - Added (file) $replace parameter to concat diff --git a/deployment/modules/concat/Gemfile b/deployment/modules/concat/Gemfile new file mode 100644 index 000000000..783e522e0 --- /dev/null +++ b/deployment/modules/concat/Gemfile @@ -0,0 +1,21 @@ +source 'https://rubygems.org' + +group :development, :test do + gem 'rake', :require => false + gem 'rspec-puppet', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'rspec-system-puppet', :require => false + gem 'puppet-lint', :require => false + gem 'serverspec', :require => false + gem 'rspec-system-serverspec', :require => false + gem 'pry', :require => false + gem 'vagrant-wrapper', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/deployment/modules/concat/LICENSE b/deployment/modules/concat/LICENSE new file mode 100644 index 000000000..6a9e9a194 --- /dev/null +++ b/deployment/modules/concat/LICENSE @@ -0,0 +1,14 @@ + Copyright 2012 R.I.Pienaar + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/deployment/modules/concat/Modulefile b/deployment/modules/concat/Modulefile new file mode 100644 index 000000000..8515b1749 --- /dev/null +++ b/deployment/modules/concat/Modulefile @@ -0,0 +1,8 @@ +name 'puppetlabs-concat' +version '1.0.0' +source 'git://github.com/puppetlabs/puppetlabs-concat.git' +author 'Puppetlabs' +license 'Apache 2.0' +summary 'Concat module' +description 'Concat module' +project_page 'http://github.com/puppetlabs/puppetlabs-concat' diff --git a/deployment/modules/concat/README b/deployment/modules/concat/README new file mode 100644 index 000000000..650141c90 --- /dev/null +++ b/deployment/modules/concat/README @@ -0,0 +1,91 @@ +== Module: concat + +A system to construct files using fragments from other files or templates. + +This requires at least puppet 0.25 to work correctly as we use some +enhancements in recursive directory management and regular expressions +to do the work here. + +=== Usage: + +The basic use case is as below: + + concat{"/etc/named.conf": + notify => Service["named"] + } + + concat::fragment{"foo.com_config": + target => "/etc/named.conf", + order => 10, + content => template("named_conf_zone.erb") + } + + # add a fragment not managed by puppet so local users + # can add content to managed file + concat::fragment{"foo.com_user_config": + target => "/etc/named.conf", + order => 12, + ensure => "/etc/named.conf.local" + } + +This will use the template named_conf_zone.erb to build a single +bit of config up and put it into the fragments dir. The file +will have an number prefix of 10, you can use the order option +to control that and thus control the order the final file gets built in. + +You can also specify a path and use a different name for your resources: + + # You can make this something dynamic, based on whatever parameters your + # module/class for example. + $vhost_file = '/etc/httpd/vhosts/01-my-vhost.conf' + + concat{'apache-vhost-myvhost': + path => $vhost_file, + } + + # We don't care where the file is located, just what to put in it. + concat::fragment {'apache-vhost-myvhost-main': + target => 'apache-vhost-myvhost', + content => '', + order => 01, + } + + concat::fragment {'apache-vhost-myvhost-close': + target => 'apache-vhost-myvhost', + content => '', + order => 99, + } + +=== Setup: + +The class concat::setup uses the fact concat_basedir to define the variable +$concatdir, where all the temporary files and fragments will be +durably stored. The fact concat_basedir will be set up on the client to +/concat, so you will be able to run different setup/flavours +of puppet clients. +However, since this requires the file lib/facter/concat_basedir.rb to be +deployed on the clients, so you will have to set "pluginsync = true" on +both the master and client, at least for the first run. + +There's some regular expression magic to figure out the puppet version but +if you're on an older 0.24 version just set $puppetversion = 24 + +=== Detail: + +We use a helper shell script called concatfragments.sh that gets placed +in /concat/bin to do the concatenation. While this might +seem more complex than some of the one-liner alternatives you might find on +the net we do a lot of error checking and safety checks in the script to avoid +problems that might be caused by complex escaping errors etc. + +=== License: + +Apache Version 2 + +=== Latest: + +http://github.com/puppetlabs/puppetlabs-concat/ + +=== Contact: + +Puppetlabs, via our puppet-users@ mailing list. diff --git a/deployment/modules/concat/README.markdown b/deployment/modules/concat/README.markdown new file mode 100644 index 000000000..c9a52b33b --- /dev/null +++ b/deployment/modules/concat/README.markdown @@ -0,0 +1,154 @@ +What is it? +=========== + +A Puppet module that can construct files from fragments. + +Please see the comments in the various .pp files for details +as well as posts on my blog at http://www.devco.net/ + +Released under the Apache 2.0 licence + +Usage: +------ + +If you wanted a /etc/motd file that listed all the major modules +on the machine. And that would be maintained automatically even +if you just remove the include lines for other modules you could +use code like below, a sample /etc/motd would be: + +
+Puppet modules on this server:
+
+    -- Apache
+    -- MySQL
+
+ +Local sysadmins can also append to the file by just editing /etc/motd.local +their changes will be incorporated into the puppet managed motd. + +
+# class to setup basic motd, include on all nodes
+class motd {
+   $motd = "/etc/motd"
+
+   concat{$motd:
+      owner => root,
+      group => root,
+      mode  => '0644',
+   }
+
+   concat::fragment{"motd_header":
+      target => $motd,
+      content => "\nPuppet modules on this server:\n\n",
+      order   => 01,
+   }
+
+   # local users on the machine can append to motd by just creating
+   # /etc/motd.local
+   concat::fragment{"motd_local":
+      target => $motd,
+      ensure  => "/etc/motd.local",
+      order   => 15
+   }
+}
+
+# used by other modules to register themselves in the motd
+define motd::register($content="", $order=10) {
+   if $content == "" {
+      $body = $name
+   } else {
+      $body = $content
+   }
+
+   concat::fragment{"motd_fragment_$name":
+      target  => "/etc/motd",
+      content => "    -- $body\n"
+   }
+}
+
+# a sample apache module
+class apache {
+   include apache::install, apache::config, apache::service
+
+   motd::register{"Apache": }
+}
+
+ +Detailed documentation of the class options can be found in the +manifest files. + +Known Issues: +------------- +* Since puppet-concat now relies on a fact for the concat directory, + you will need to set up pluginsync = true on the [master] section of your + node's '/etc/puppet/puppet.conf' for at least the first run. + You have this issue if puppet fails to run on the client and you have + a message similar to + "err: Failed to apply catalog: Parameter path failed: File + paths must be fully qualified, not 'undef' at [...]/concat/manifests/setup.pp:44". + +Contributors: +------------- +**Paul Elliot** + + * Provided 0.24.8 support, shell warnings and empty file creation support. + +**Chad Netzer** + + * Various patches to improve safety of file operations + * Symlink support + +**David Schmitt** + + * Patch to remove hard coded paths relying on OS path + * Patch to use file{} to copy the resulting file to the final destination. This means Puppet client will show diffs and that hopefully we can change file ownerships now + +**Peter Meier** + + * Basedir as a fact + * Unprivileged user support + +**Sharif Nassar** + + * Solaris/Nexenta support + * Better error reporting + +**Christian G. Warden** + + * Style improvements + +**Reid Vandewiele** + + * Support non GNU systems by default + +**Erik Dalén** + + * Style improvements + +**Gildas Le Nadan** + + * Documentation improvements + +**Paul Belanger** + + * Testing improvements and Travis support + +**Branan Purvine-Riley** + + * Support Puppet Module Tool better + +**Dustin J. Mitchell** + + * Always include setup when using the concat define + +**Andreas Jaggi** + + * Puppet Lint support + +**Jan Vansteenkiste** + + * Configurable paths + +Contact: +-------- +puppet-users@ mailing list. diff --git a/deployment/modules/concat/Rakefile b/deployment/modules/concat/Rakefile new file mode 100644 index 000000000..bb60173e5 --- /dev/null +++ b/deployment/modules/concat/Rakefile @@ -0,0 +1,2 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'rspec-system/rake_task' diff --git a/deployment/modules/concat/files/concatfragments.sh b/deployment/modules/concat/files/concatfragments.sh new file mode 100755 index 000000000..570d553c6 --- /dev/null +++ b/deployment/modules/concat/files/concatfragments.sh @@ -0,0 +1,140 @@ +#!/bin/sh + +# Script to concat files to a config file. +# +# Given a directory like this: +# /path/to/conf.d +# |-- fragments +# | |-- 00_named.conf +# | |-- 10_domain.net +# | `-- zz_footer +# +# The script supports a test option that will build the concat file to a temp location and +# use /usr/bin/cmp to verify if it should be run or not. This would result in the concat happening +# twice on each run but gives you the option to have an unless option in your execs to inhibit rebuilds. +# +# Without the test option and the unless combo your services that depend on the final file would end up +# restarting on each run, or in other manifest models some changes might get missed. +# +# OPTIONS: +# -o The file to create from the sources +# -d The directory where the fragments are kept +# -t Test to find out if a build is needed, basically concats the files to a temp +# location and compare with what's in the final location, return codes are designed +# for use with unless on an exec resource +# -w Add a shell style comment at the top of the created file to warn users that it +# is generated by puppet +# -f Enables the creation of empty output files when no fragments are found +# -n Sort the output numerically rather than the default alpha sort +# +# the command: +# +# concatfragments.sh -o /path/to/conffile.cfg -d /path/to/conf.d +# +# creates /path/to/conf.d/fragments.concat and copies the resulting +# file to /path/to/conffile.cfg. The files will be sorted alphabetically +# pass the -n switch to sort numerically. +# +# The script does error checking on the various dirs and files to make +# sure things don't fail. + +OUTFILE="" +WORKDIR="" +TEST="" +FORCE="" +WARN="" +SORTARG="" +ENSURE_NEWLINE="" + +PATH=/sbin:/usr/sbin:/bin:/usr/bin + +## Well, if there's ever a bad way to do things, Nexenta has it. +## http://nexenta.org/projects/site/wiki/Personalities +unset SUN_PERSONALITY + +while getopts "o:s:d:tnw:fl" options; do + case $options in + o ) OUTFILE=$OPTARG;; + d ) WORKDIR=$OPTARG;; + n ) SORTARG="-n";; + w ) WARNMSG="$OPTARG";; + f ) FORCE="true";; + t ) TEST="true";; + l ) ENSURE_NEWLINE="true";; + * ) echo "Specify output file with -o and fragments directory with -d" + exit 1;; + esac +done + +# do we have -o? +if [ x${OUTFILE} = "x" ]; then + echo "Please specify an output file with -o" + exit 1 +fi + +# do we have -d? +if [ x${WORKDIR} = "x" ]; then + echo "Please fragments directory with -d" + exit 1 +fi + +# can we write to -o? +if [ -f ${OUTFILE} ]; then + if [ ! -w ${OUTFILE} ]; then + echo "Cannot write to ${OUTFILE}" + exit 1 + fi +else + if [ ! -w `dirname ${OUTFILE}` ]; then + echo "Cannot write to `dirname ${OUTFILE}` to create ${OUTFILE}" + exit 1 + fi +fi + +# do we have a fragments subdir inside the work dir? +if [ ! -d "${WORKDIR}/fragments" ] && [ ! -x "${WORKDIR}/fragments" ]; then + echo "Cannot access the fragments directory" + exit 1 +fi + +# are there actually any fragments? +if [ ! "$(ls -A ${WORKDIR}/fragments)" ]; then + if [ x${FORCE} = "x" ]; then + echo "The fragments directory is empty, cowardly refusing to make empty config files" + exit 1 + fi +fi + +cd ${WORKDIR} + +if [ "x${WARNMSG}" = "x" ]; then + : > "fragments.concat" +else + printf '%s\n' "$WARNMSG" > "fragments.concat" +fi + +if [ x${ENSURE_NEWLINE} != x ]; then + find fragments/ -type f -follow -print0 | xargs -0 -I '{}' sh -c 'if [ -n "$(tail -c 1 < {} )" ]; then echo >> {} ; fi' +fi + +# find all the files in the fragments directory, sort them numerically and concat to fragments.concat in the working dir +IFS_BACKUP=$IFS +IFS=' +' +for fragfile in `find fragments/ -type f -follow | LANG=C sort ${SORTARG}` +do + cat $fragfile >> "fragments.concat" +done +IFS=$IFS_BACKUP + +if [ x${TEST} = "x" ]; then + # This is a real run, copy the file to outfile + cp fragments.concat ${OUTFILE} + RETVAL=$? +else + # Just compare the result to outfile to help the exec decide + cmp ${OUTFILE} fragments.concat + RETVAL=$? +fi + +exit $RETVAL diff --git a/deployment/modules/concat/lib/facter/concat_basedir.rb b/deployment/modules/concat/lib/facter/concat_basedir.rb new file mode 100644 index 000000000..ef5a689db --- /dev/null +++ b/deployment/modules/concat/lib/facter/concat_basedir.rb @@ -0,0 +1,11 @@ +# == Fact: concat_basedir +# +# A custom fact that sets the default location for fragments +# +# "${::vardir}/concat/" +# +Facter.add("concat_basedir") do + setcode do + File.join(Puppet[:vardir],"concat") + end +end diff --git a/deployment/modules/concat/manifests/fragment.pp b/deployment/modules/concat/manifests/fragment.pp new file mode 100644 index 000000000..a6831f88c --- /dev/null +++ b/deployment/modules/concat/manifests/fragment.pp @@ -0,0 +1,67 @@ +# == Define: concat::fragment +# +# Puts a file fragment into a directory previous setup using concat +# +# === Options: +# +# [*target*] +# The file that these fragments belong to +# [*content*] +# If present puts the content into the file +# [*source*] +# If content was not specified, use the source +# [*order*] +# By default all files gets a 10_ prefix in the directory you can set it to +# anything else using this to influence the order of the content in the file +# [*ensure*] +# Present/Absent or destination to a file to include another file +# [*mode*] +# Mode for the file +# [*owner*] +# Owner of the file +# [*group*] +# Owner of the file +# [*backup*] +# Controls the filebucketing behavior of the final file and see File type +# reference for its use. Defaults to 'puppet' +# +define concat::fragment( + $target, + $content=undef, + $source=undef, + $order=10, + $ensure = 'present', + $mode = '0644', + $owner = $::id, + $group = $concat::setup::root_group, + $backup = 'puppet') { + $safe_name = regsubst($name, '[/\n]', '_', 'GM') + $safe_target_name = regsubst($target, '[/\n]', '_', 'GM') + $concatdir = $concat::setup::concatdir + $fragdir = "${concatdir}/${safe_target_name}" + + # if content is passed, use that, else if source is passed use that + # if neither passed, but $ensure is in symlink form, make a symlink + case $ensure { + '', 'absent', 'present', 'file', 'directory': { + if ! ($content or $source) { + crit('No content, source or symlink specified') + } + } + default: { + # do nothing, make puppet-lint happy + } + } + + file{"${fragdir}/fragments/${order}_${safe_name}": + ensure => $ensure, + mode => $mode, + owner => $owner, + group => $group, + source => $source, + content => $content, + backup => $backup, + alias => "concat_fragment_${name}", + notify => Exec["concat_${target}"] + } +} diff --git a/deployment/modules/concat/manifests/init.pp b/deployment/modules/concat/manifests/init.pp new file mode 100644 index 000000000..ed4068b0c --- /dev/null +++ b/deployment/modules/concat/manifests/init.pp @@ -0,0 +1,190 @@ +# == Define: concat +# +# Sets up so that you can use fragments to build a final config file, +# +# === Options: +# +# [*path*] +# The path to the final file. Use this in case you want to differentiate +# between the name of a resource and the file path. Note: Use the name you +# provided in the target of your fragments. +# [*mode*] +# The mode of the final file +# [*owner*] +# Who will own the file +# [*group*] +# Who will own the file +# [*force*] +# Enables creating empty files if no fragments are present +# [*warn*] +# Adds a normal shell style comment top of the file indicating that it is +# built by puppet +# [*backup*] +# Controls the filebucketing behavior of the final file and see File type +# reference for its use. Defaults to 'puppet' +# [*replace*] +# Whether to replace a file that already exists on the local system +# +# === Actions: +# * Creates fragment directories if it didn't exist already +# * Executes the concatfragments.sh script to build the final file, this +# script will create directory/fragments.concat. Execution happens only +# when: +# * The directory changes +# * fragments.concat != final destination, this means rebuilds will happen +# whenever someone changes or deletes the final file. Checking is done +# using /usr/bin/cmp. +# * The Exec gets notified by something else - like the concat::fragment +# define +# * Copies the file over to the final destination using a file resource +# +# === Aliases: +# +# * The exec can notified using Exec["concat_/path/to/file"] or +# Exec["concat_/path/to/directory"] +# * The final file can be referened as File["/path/to/file"] or +# File["concat_/path/to/file"] +# +define concat( + $path = $name, + $owner = $::id, + $group = $concat::setup::root_group, + $mode = '0644', + $warn = false, + $force = false, + $backup = 'puppet', + $replace = true, + $gnu = undef, + $order='alpha', + $ensure_newline = false +) { + include concat::setup + + $safe_name = regsubst($name, '/', '_', 'G') + $concatdir = $concat::setup::concatdir + $version = $concat::setup::majorversion + $fragdir = "${concatdir}/${safe_name}" + $concat_name = 'fragments.concat.out' + $default_warn_message = '# This file is managed by Puppet. DO NOT EDIT.' + + case $warn { + 'true', true, yes, on: { + $warnmsg = $default_warn_message + } + 'false', false, no, off: { + $warnmsg = '' + } + default: { + $warnmsg = $warn + } + } + + $warnmsg_escaped = regsubst($warnmsg, "'", "'\\\\''", 'G') + $warnflag = $warnmsg_escaped ? { + '' => '', + default => "-w '${warnmsg_escaped}'" + } + + case $force { + 'true', true, yes, on: { + $forceflag = '-f' + } + 'false', false, no, off: { + $forceflag = '' + } + default: { + fail("Improper 'force' value given to concat: ${force}") + } + } + + case $order { + numeric: { + $orderflag = '-n' + } + alpha: { + $orderflag = '' + } + default: { + fail("Improper 'order' value given to concat: ${order}") + } + } + + case $ensure_newline { + 'true', true, yes, on: { + $newlineflag = '-l' + } + 'false', false, no, off: { + $newlineflag = '' + } + default: { + fail("Improper 'ensure_newline' value given to concat: ${ensure_newline}") + } + } + + File { + owner => $::id, + group => $group, + mode => $mode, + backup => $backup, + replace => $replace + } + + file { $fragdir: + ensure => directory, + } + + $source_real = $version ? { + 24 => 'puppet:///concat/null', + default => undef, + } + + file { "${fragdir}/fragments": + ensure => directory, + force => true, + ignore => ['.svn', '.git', '.gitignore'], + notify => Exec["concat_${name}"], + purge => true, + recurse => true, + source => $source_real, + } + + file { "${fragdir}/fragments.concat": + ensure => present, + } + + file { "${fragdir}/${concat_name}": + ensure => present, + } + + file { $name: + ensure => present, + path => $path, + alias => "concat_${name}", + group => $group, + mode => $mode, + owner => $owner, + source => "${fragdir}/${concat_name}", + } + + exec { "concat_${name}": + alias => "concat_${fragdir}", + command => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} ${warnflag} ${forceflag} ${orderflag} ${newlineflag}", + notify => File[$name], + require => [ + File[$fragdir], + File["${fragdir}/fragments"], + File["${fragdir}/fragments.concat"], + ], + subscribe => File[$fragdir], + unless => "${concat::setup::concatdir}/bin/concatfragments.sh -o ${fragdir}/${concat_name} -d ${fragdir} -t ${warnflag} ${forceflag} ${orderflag} ${newlineflag}", + } + + if $::id == 'root' { + Exec["concat_${name}"] { + user => root, + group => $group, + } + } +} + +# vim:sw=2:ts=2:expandtab:textwidth=79 diff --git a/deployment/modules/concat/manifests/setup.pp b/deployment/modules/concat/manifests/setup.pp new file mode 100644 index 000000000..2d29bf846 --- /dev/null +++ b/deployment/modules/concat/manifests/setup.pp @@ -0,0 +1,55 @@ +# === Class: concat::setup +# +# Sets up the concat system. +# +# [$concatdir] +# is where the fragments live and is set on the fact concat_basedir. +# Since puppet should always manage files in $concatdir and they should +# not be deleted ever, /tmp is not an option. +# +# [$puppetversion] +# should be either 24 or 25 to enable a 24 compatible +# mode, in 24 mode you might see phantom notifies this is a side effect +# of the method we use to clear the fragments directory. +# +# The regular expression below will try to figure out your puppet version +# but this code will only work in 0.24.8 and newer. +# +# It also copies out the concatfragments.sh file to ${concatdir}/bin +# +class concat::setup { + $id = $::id + $root_group = $id ? { + root => 0, + default => $id + } + + if $::concat_basedir { + $concatdir = $::concat_basedir + } else { + fail ("\$concat_basedir not defined. Try running again with pluginsync=true on the [master] section of your node's '/etc/puppet/puppet.conf'.") + } + + $majorversion = regsubst($::puppetversion, '^[0-9]+[.]([0-9]+)[.][0-9]+$', '\1') + $fragments_source = $majorversion ? { + 24 => 'puppet:///concat/concatfragments.sh', + default => 'puppet:///modules/concat/concatfragments.sh' + } + + file{"${concatdir}/bin/concatfragments.sh": + owner => $id, + group => $root_group, + mode => '0755', + source => $fragments_source; + + [ $concatdir, "${concatdir}/bin" ]: + ensure => directory, + owner => $id, + group => $root_group, + mode => '0750'; + + ## Old versions of this module used a different path. + '/usr/local/bin/concatfragments.sh': + ensure => absent; + } +} diff --git a/deployment/modules/concat/metadata.json b/deployment/modules/concat/metadata.json new file mode 100644 index 000000000..28f080eb7 --- /dev/null +++ b/deployment/modules/concat/metadata.json @@ -0,0 +1,39 @@ +{ + "name": "puppetlabs-concat", + "version": "1.0.0", + "source": "git://github.com/puppetlabs/puppetlabs-concat.git", + "author": "Puppetlabs", + "license": "Apache 2.0", + "summary": "Concat module", + "description": "Concat module", + "project_page": "http://github.com/puppetlabs/puppetlabs-concat", + "dependencies": [ + + ], + "types": [ + + ], + "checksums": { + "CHANGELOG": "89220fae3ab04a350132fe94d7a6ca00", + "Gemfile": "a913d6f7a0420e07539d8ff1ef047ffb", + "LICENSE": "f5a76685d453424cd63dde1535811cf0", + "Modulefile": "f99ee2f6778b9e23635ac1027888bbd3", + "README": "d15ec3400f628942dd7b7fa8c1a18da3", + "README.markdown": "d82e203d729ea4785bdcaca1be166e62", + "Rakefile": "0428ea3759a4692c91604396c406a9c1", + "files/concatfragments.sh": "2fbba597a1513eb61229551d35d42b9f", + "lib/facter/concat_basedir.rb": "e152593fafe27ef305fc473929c62ca6", + "manifests/fragment.pp": "196ee8e405b3a31b84ae618ed54377ed", + "manifests/init.pp": "8d0cc8e9cf145ca7a23db05a30252476", + "manifests/setup.pp": "2246572410d94c68aff310f8132c55b4", + "spec/defines/init_spec.rb": "35e41d4abceba0dca090d3addd92bb4f", + "spec/fixtures/manifests/site.pp": "d41d8cd98f00b204e9800998ecf8427e", + "spec/spec_helper.rb": "0db89c9a486df193c0e40095422e19dc", + "spec/spec_helper_system.rb": "9c3742bf87d62027f080c6b9fa98b979", + "spec/system/basic_spec.rb": "9135d9af6a21f16980ab59b58e91ed9a", + "spec/system/concat_spec.rb": "5fe675ec42ca441d0c7e431c31bbc238", + "spec/system/empty_spec.rb": "51ab1fc7c86268f1ab1cda72dc5ff583", + "spec/system/replace_spec.rb": "275295e6b4f04fc840dc3f87faf56249", + "spec/system/warn_spec.rb": "0ea35b44e8f0ac5352256f95115995ce" + } +} \ No newline at end of file diff --git a/deployment/modules/concat/spec/defines/init_spec.rb b/deployment/modules/concat/spec/defines/init_spec.rb new file mode 100644 index 000000000..ace50f0d0 --- /dev/null +++ b/deployment/modules/concat/spec/defines/init_spec.rb @@ -0,0 +1,115 @@ +require 'spec_helper' + +describe 'concat' do + basedir = '/var/lib/puppet/concat' + let(:title) { '/etc/foo.bar' } + let(:facts) { { + :concat_basedir => '/var/lib/puppet/concat', + :id => 'root', + } } + let :pre_condition do + 'include concat::setup' + end + + directories = [ + "#{basedir}/_etc_foo.bar", + "#{basedir}/_etc_foo.bar/fragments", + ] + + directories.each do |dirs| + it do + should contain_file(dirs).with({ + 'ensure' => 'directory', + 'backup' => 'puppet', + 'group' => 0, + 'mode' => '0644', + 'owner' => 'root', + }) + end + end + + files = [ + "/etc/foo.bar", + "#{basedir}/_etc_foo.bar/fragments.concat", + ] + + files.each do |file| + it do + should contain_file(file).with({ + 'ensure' => 'present', + 'backup' => 'puppet', + 'group' => 0, + 'mode' => '0644', + 'owner' => 'root', + }) + end + end + + it do + should contain_exec("concat_/etc/foo.bar").with_command( + "#{basedir}/bin/concatfragments.sh " + + "-o #{basedir}/_etc_foo.bar/fragments.concat.out " + + "-d #{basedir}/_etc_foo.bar " + ) + end +end + +describe 'concat' do + + basedir = '/var/lib/puppet/concat' + let(:title) { 'foobar' } + let(:target) { '/etc/foo.bar' } + let(:facts) { { + :concat_basedir => '/var/lib/puppet/concat', + :id => 'root', + } } + let :pre_condition do + 'include concat::setup' + end + + directories = [ + "#{basedir}/foobar", + "#{basedir}/foobar/fragments", + ] + + directories.each do |dirs| + it do + should contain_file(dirs).with({ + 'ensure' => 'directory', + 'backup' => 'puppet', + 'group' => 0, + 'mode' => '0644', + 'owner' => 'root', + }) + end + end + + files = [ + "foobar", + "#{basedir}/foobar/fragments.concat", + ] + + files.each do |file| + it do + should contain_file(file).with({ + 'ensure' => 'present', + 'backup' => 'puppet', + 'group' => 0, + 'mode' => '0644', + 'owner' => 'root', + }) + end + end + + it do + should contain_exec("concat_foobar").with_command( + "#{basedir}/bin/concatfragments.sh " + + "-o #{basedir}/foobar/fragments.concat.out " + + "-d #{basedir}/foobar " + ) + end + + +end + +# vim:sw=2:ts=2:expandtab:textwidth=79 diff --git a/deployment/modules/concat/spec/fixtures/manifests/site.pp b/deployment/modules/concat/spec/fixtures/manifests/site.pp new file mode 100644 index 000000000..e69de29bb diff --git a/deployment/modules/concat/spec/spec_helper.rb b/deployment/modules/concat/spec/spec_helper.rb new file mode 100644 index 000000000..2c6f56649 --- /dev/null +++ b/deployment/modules/concat/spec/spec_helper.rb @@ -0,0 +1 @@ +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/deployment/modules/concat/spec/spec_helper_system.rb b/deployment/modules/concat/spec/spec_helper_system.rb new file mode 100644 index 000000000..bf66a530e --- /dev/null +++ b/deployment/modules/concat/spec/spec_helper_system.rb @@ -0,0 +1,25 @@ +require 'rspec-system/spec_helper' +require 'rspec-system-puppet/helpers' +require 'rspec-system-serverspec/helpers' +include Serverspec::Helper::RSpecSystem +include Serverspec::Helper::DetectOS +include RSpecSystemPuppet::Helpers + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Enable colour + c.tty = true + + c.include RSpecSystemPuppet::Helpers + + # This is where we 'setup' the nodes before running our tests + c.before :suite do + # Install puppet + puppet_install + + # Install modules and dependencies + puppet_module_install(:source => proj_root, :module_name => 'concat') + end +end diff --git a/deployment/modules/concat/spec/system/basic_spec.rb b/deployment/modules/concat/spec/system/basic_spec.rb new file mode 100644 index 000000000..39ac746b6 --- /dev/null +++ b/deployment/modules/concat/spec/system/basic_spec.rb @@ -0,0 +1,13 @@ +require 'spec_helper_system' + +# Here we put the more basic fundamental tests, ultra obvious stuff. +describe "basic tests:" do + context 'make sure we have copied the module across' do + # No point diagnosing any more if the module wasn't copied properly + context shell 'ls /etc/puppet/modules/concat' do + its(:stdout) { should =~ /Modulefile/ } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + end +end diff --git a/deployment/modules/concat/spec/system/concat_spec.rb b/deployment/modules/concat/spec/system/concat_spec.rb new file mode 100644 index 000000000..af360d63e --- /dev/null +++ b/deployment/modules/concat/spec/system/concat_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper_system' + +describe 'basic concat test' do + context 'should run successfully' do + pp=" + concat { '/tmp/file': + owner => root, + group => root, + mode => '0644', + } + + concat::fragment { '1': + target => '/tmp/file', + content => '1', + order => '01', + } + + concat::fragment { '2': + target => '/tmp/file', + content => '2', + order => '02', + } + " + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + + describe file('/tmp/file') do + it { should be_file } + it { should contain '1' } + it { should contain '2' } + end + + # Test that all the relevant bits exist on disk after it + # concats. + describe file('/var/lib/puppet/concat') do + it { should be_directory } + end + describe file('/var/lib/puppet/concat/_tmp_file') do + it { should be_directory } + end + describe file('/var/lib/puppet/concat/_tmp_file/fragments') do + it { should be_directory } + end + describe file('/var/lib/puppet/concat/_tmp_file/fragments.concat') do + it { should be_file } + end + + end +end diff --git a/deployment/modules/concat/spec/system/empty_spec.rb b/deployment/modules/concat/spec/system/empty_spec.rb new file mode 100644 index 000000000..83dae0145 --- /dev/null +++ b/deployment/modules/concat/spec/system/empty_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper_system' + +describe 'basic concat test' do + context 'should run successfully' do + pp=" + concat { '/tmp/file': + owner => root, + group => root, + mode => '0644', + force => true, + } + " + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + + describe file('/tmp/file') do + it { should be_file } + it { should_not contain '1\n2' } + end + end +end diff --git a/deployment/modules/concat/spec/system/replace_spec.rb b/deployment/modules/concat/spec/system/replace_spec.rb new file mode 100644 index 000000000..7f11e5ff4 --- /dev/null +++ b/deployment/modules/concat/spec/system/replace_spec.rb @@ -0,0 +1,37 @@ +require 'spec_helper_system' + + +describe 'file should not replace' do + shell('echo "file exists" >> /tmp/file') + context 'should fail' do + pp=" + concat { '/tmp/file': + owner => root, + group => root, + mode => '0644', + replace => false, + } + + concat::fragment { '1': + target => '/tmp/file', + content => '1', + order => '01', + } + + concat::fragment { '2': + target => '/tmp/file', + content => '2', + order => '02', + } + " + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + + end +end diff --git a/deployment/modules/concat/spec/system/warn_spec.rb b/deployment/modules/concat/spec/system/warn_spec.rb new file mode 100644 index 000000000..872058bdc --- /dev/null +++ b/deployment/modules/concat/spec/system/warn_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper_system' + +describe 'basic concat test' do + context 'should run successfully' do + pp=" + concat { '/tmp/file': + owner => root, + group => root, + mode => '0644', + warn => true, + } + + concat::fragment { '1': + target => '/tmp/file', + content => '1', + order => '01', + } + + concat::fragment { '2': + target => '/tmp/file', + content => '2', + order => '02', + } + " + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + + describe file('/tmp/file') do + it { should be_file } + it { should contain '# This file is managed by Puppet. DO NOT EDIT.' } + it { should contain '1' } + it { should contain '2' } + end + end +end diff --git a/deployment/modules/evap/files/localsettings.py b/deployment/modules/evap/files/localsettings.py new file mode 100644 index 000000000..a8aaeb5ca --- /dev/null +++ b/deployment/modules/evap/files/localsettings.py @@ -0,0 +1,10 @@ +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.mysql', # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'. + 'NAME': 'evap', # Or path to database file if using sqlite3. + 'USER': 'evap', # Not used with sqlite3. + 'PASSWORD': '0Am5dWVSC9kd', # Not used with sqlite3. + 'HOST': '', # Set to empty string for localhost. Not used with sqlite3. + 'PORT': '', # Set to empty string for default. Not used with sqlite3. + } +} diff --git a/deployment/modules/evap/manifests/init.pp b/deployment/modules/evap/manifests/init.pp new file mode 100644 index 000000000..a74c11183 --- /dev/null +++ b/deployment/modules/evap/manifests/init.pp @@ -0,0 +1,2 @@ +class evap { +} diff --git a/deployment/modules/mysql/CHANGELOG b/deployment/modules/mysql/CHANGELOG new file mode 100644 index 000000000..828a4c523 --- /dev/null +++ b/deployment/modules/mysql/CHANGELOG @@ -0,0 +1,403 @@ +2013-11-13 - Version 2.1.0 + +Summary: + +The most important changes in 2.1.0 are improvements to the my.cnf creation, +as well as providers. Setting options to = true strips them to be just the +key name itself, which is required for some options. + +The provider updates fix a number of bugs, from lowercase privileges to +deprecation warnings. + +Last, the new hiera integration functionality should make it easier to +externalize all your grantts, users, and, databases. Another great set of +community submissions helped to make this release. + +Features: +- Some options can not take a argument. Gets rid of the '= true' when an +option is set to true. +- Easier hiera integration: Add hash parameters to mysql::server to allow +specifying grants, users, and databases. + +Fixes: +- Fix an issue with lowercase privileges in mysql_grant{} causing them to be reapplied needlessly. +- Changed defaults-file to defaults-extra-file in providers. +- Ensure /root/.my.cnf is 0600 and root owned. +- database_user deprecation warning was incorrect. +- Add anchor pattern for client.pp +- Documentation improvements. +- Various test fixes. + +2013-10-21 - Version 2.0.1 + +Summary: + +This is a bugfix release to handle an issue where unsorted mysql_grant{} +privileges could cause Puppet to incorrectly reapply the permissions on +each run. + +Fixes: +- Mysql_grant now sorts privileges in the type and provider for comparision. +- Comment and test tweak for PE3.1. + +2013-10-14 - Version 2.0.0 + +Summary: + +(Previously detailed in the changelog for 2.0.0-rc1) + +This module has been completely refactored and works significantly different. +The changes are broad and touch almost every piece of the module. + +See the README.md for full details of all changes and syntax. +Please remain on 1.0.0 if you don't have time to fully test this in dev. + +* mysql::server, mysql::client, and mysql::bindings are the primary interface +classes. +* mysql::server takes an `options_override` parameter to set my.cnf options, +with the hash format: { 'section' => { 'thing' => 'value' }} +* mysql attempts backwards compatibility by forwarding all parameters to +mysql::server. + +2013-10-09 - Version 2.0.0-rc5 + +Summary: + +Hopefully the final rc! Further fixes to mysql_grant (stripping out the +cleverness so we match a much wider range of input.) + +Fixes: +- Make mysql_grant accept '.*'@'.*' in terms of input for user@host. + +2013-10-09 - Version 2.0.0-rc4 + +Summary: + +Bugfixes to mysql_grant and mysql_user form the bulk of this rc, as well as +ensuring that values in the override_options hash that contain a value of '' +are created as just "key" in the conf rather than "key =" or "key = false". + +Fixes: +- Improve mysql_grant to work with IPv6 addresses (both long and short). +- Ensure @host users work as well as user@host users. +- Updated my.cnf template to support items with no values. + +2013-10-07 - Version 2.0.0-rc3 + +Summary: + +Fix mysql::server::monitor's use of mysql_user{}. + +Fixes: +- Fix myql::server::monitor's use of mysql_user{} to grant the proper +permissions. Add specs as well. (Thanks to treydock!) + +2013-10-03 - Version 2.0.0-rc2 + +Summary: + +Bugfixes + +Fixes: +- Fix a duplicate parameter in mysql::server + +2013-10-03 - Version 2.0.0-rc1 + +Summary: + +This module has been completely refactored and works significantly different. +The changes are broad and touch almost every piece of the module. + +See the README.md for full details of all changes and syntax. +Please remain on 1.0.0 if you don't have time to fully test this in dev. + +* mysql::server, mysql::client, and mysql::bindings are the primary interface +classes. +* mysql::server takes an `options_override` parameter to set my.cnf options, +with the hash format: { 'section' => { 'thing' => 'value' }} +* mysql attempts backwards compatibility by forwarding all parameters to +mysql::server. + +2013-09-23 - Version 1.0.0 + +Summary: + +This release introduces a number of new type/providers, to eventually +replace the database_ ones. The module has been converted to call the +new providers rather than the previous ones as they have a number of +fixes, additional options, and work with puppet resource. + +This 1.0.0 release precedes a large refactoring that will be released +almost immediately after as 2.0.0. + +Features: +- Added mysql_grant, mysql_database, and mysql_user. +- Add `mysql::bindings` class and refactor all other bindings to be contained underneath mysql::bindings:: namespace. +- Added support to back up specified databases only with 'mysqlbackup' parameter. +- Add option to mysql::backup to set the backup script to perform a mysqldump on each database to its own file + +Bugfixes: +- Update my.cnf.pass.erb to allow custom socket support +- Add environment variable for .my.cnf in mysql::db. +- Add HOME environment variable for .my.cnf to mysqladmin command when +(re)setting root password + +2013-07-15 - Version 0.9.0 +Features: +- Add `mysql::backup::backuprotate` parameter +- Add `mysql::backup::delete_before_dump` parameter +- Add `max_user_connections` attribute to `database_user` type + +Bugfixes: +- Add client package dependency for `mysql::db` +- Remove duplicate `expire_logs_days` and `max_binlog_size` settings +- Make root's `.my.cnf` file path dynamic +- Update pidfile path for Suse variants +- Fixes for lint + +2013-07-05 - Version 0.8.1 +Bugfixes: + - Fix a typo in the Fedora 19 support. + +2013-07-01 - Version 0.8.0 +Features: + - mysql::perl class to install perl-DBD-mysql. + - minor improvements to the providers to improve reliability + - Install the MariaDB packages on Fedora 19 instead of MySQL. + - Add new `mysql` class parameters: + - `max_connections`: The maximum number of allowed connections. + - `manage_config_file`: Opt out of puppetized control of my.cnf. + - `ft_min_word_len`: Fine tune the full text search. + - `ft_max_word_len`: Fine tune the full text search. + - Add new `mysql` class performance tuning parameters: + - `key_buffer` + - `thread_stack` + - `thread_cache_size` + - `myisam-recover` + - `query_cache_limit` + - `query_cache_size` + - `max_connections` + - `tmp_table_size` + - `table_open_cache` + - `long_query_time` + - Add new `mysql` class replication parameters: + - `server_id` + - `sql_log_bin` + - `log_bin` + - `max_binlog_size` + - `binlog_do_db` + - `expire_logs_days` + - `log_bin_trust_function_creators` + - `replicate_ignore_table` + - `replicate_wild_do_table` + - `replicate_wild_ignore_table` + - `expire_logs_days` + - `max_binlog_size` + +Bugfixes: + - No longer restart MySQL when /root/.my.cnf changes. + - Ensure mysql::config runs before any mysql::db defines. + +2013-06-26 - Version 0.7.1 +Bugfixes: +- Single-quote password for special characters +- Update travis testing for puppet 3.2.x and missing Bundler gems + +2013-06-25 - Version 0.7.0 +This is a maintenance release for community bugfixes and exposing +configuration variables. + +* Add new `mysql` class parameters: + - `basedir`: The base directory mysql uses + - `bind_address`: The IP mysql binds to + - `client_package_name`: The name of the mysql client package + - `config_file`: The location of the server config file + - `config_template`: The template to use to generate my.cnf + - `datadir`: The directory MySQL's datafiles are stored + - `default_engine`: The default engine to use for tables + - `etc_root_password`: Whether or not to add the mysql root password to + /etc/my.cnf + - `java_package_name`: The name of the java package containing the java + connector + - `log_error`: Where to log errors + - `manage_service`: Boolean dictating if mysql::server should manage the + service + - `max_allowed_packet`: Maximum network packet size mysqld will accept + - `old_root_password`: Previous root user password + - `php_package_name`: The name of the phpmysql package to install + - `pidfile`: The location mysql will expect the pidfile to be + - `port`: The port mysql listens on + - `purge_conf_dir`: Value fed to recurse and purge parameters of the + /etc/mysql/conf.d resource + - `python_package_name`: The name of the python mysql package to install + - `restart`: Whether to restart mysqld + - `root_group`: Use specified group for root-owned files + - `root_password`: The root MySQL password to use + - `ruby_package_name`: The name of the ruby mysql package to install + - `ruby_package_provider`: The installation suite to use when installing the + ruby package + - `server_package_name`: The name of the server package to install + - `service_name`: The name of the service to start + - `service_provider`: The name of the service provider + - `socket`: The location of the MySQL server socket file + - `ssl_ca`: The location of the SSL CA Cert + - `ssl_cert`: The location of the SSL Certificate to use + - `ssl_key`: The SSL key to use + - `ssl`: Whether or not to enable ssl + - `tmpdir`: The directory MySQL's tmpfiles are stored +* Deprecate `mysql::package_name` parameter in favor of +`mysql::client_package_name` +* Fix local variable template deprecation +* Fix dependency ordering in `mysql::db` +* Fix ANSI quoting in queries +* Fix travis support (but still messy) +* Fix typos + +2013-01-11 - Version 0.6.1 +* Fix providers when /root/.my.cnf is absent + +2013-01-09 - Version 0.6.0 +* Add `mysql::server::config` define for specific config directives +* Add `mysql::php` class for php support +* Add `backupcompress` parameter to `mysql::backup` +* Add `restart` parameter to `mysql::config` +* Add `purge_conf_dir` parameter to `mysql::config` +* Add `manage_service` parameter to `mysql::server` +* Add syslog logging support via the `log_error` parameter +* Add initial SuSE support +* Fix remove non-localhost root user when fqdn != hostname +* Fix dependency in `mysql::server::monitor` +* Fix .my.cnf path for root user and root password +* Fix ipv6 support for users +* Fix / update various spec tests +* Fix typos +* Fix lint warnings + +2012-08-23 - Version 0.5.0 +* Add puppetlabs/stdlib as requirement +* Add validation for mysql privs in provider +* Add `pidfile` parameter to mysql::config +* Add `ensure` parameter to mysql::db +* Add Amazon linux support +* Change `bind_address` parameter to be optional in my.cnf template +* Fix quoting root passwords + +2012-07-24 - Version 0.4.0 +* Fix various bugs regarding database names +* FreeBSD support +* Allow specifying the storage engine +* Add a backup class +* Add a security class to purge default accounts + +2012-05-03 - Version 0.3.0 +* #14218 Query the database for available privileges +* Add mysql::java class for java connector installation +* Use correct error log location on different distros +* Fix set_mysql_rootpw to properly depend on my.cnf + +2012-04-11 - Version 0.2.0 + +2012-03-19 - William Van Hevelingen +* (#13203) Add ssl support (f7e0ea5) + +2012-03-18 - Nan Liu +* Travis ci before script needs success exit code. (0ea463b) + +2012-03-18 - Nan Liu +* Fix Puppet 2.6 compilation issues. (9ebbbc4) + +2012-03-16 - Nan Liu +* Add travis.ci for testing multiple puppet versions. (33c72ef) + +2012-03-15 - William Van Hevelingen +* (#13163) Datadir should be configurable (f353fc6) + +2012-03-16 - Nan Liu +* Document create_resources dependency. (558a59c) + +2012-03-16 - Nan Liu +* Fix spec test issues related to error message. (eff79b5) + +2012-03-16 - Nan Liu +* Fix mysql service on Ubuntu. (72da2c5) + +2012-03-16 - Dan Bode +* Add more spec test coverage (55e399d) + +2012-03-16 - Nan Liu +* (#11963) Fix spec test due to path changes. (1700349) + +2012-03-07 - François Charlier +* Add a test to check path for 'mysqld-restart' (b14c7d1) + +2012-03-07 - François Charlier +* Fix path for 'mysqld-restart' (1a9ae6b) + +2012-03-15 - Dan Bode +* Add rspec-puppet tests for mysql::config (907331a) + +2012-03-15 - Dan Bode +* Moved class dependency between sever and config to server (da62ad6) + +2012-03-14 - Dan Bode +* Notify mysql restart from set_mysql_rootpw exec (0832a2c) + +2012-03-15 - Nan Liu +* Add documentation related to osfamily fact. (8265d28) + +2012-03-14 - Dan Bode +* Mention osfamily value in failure message (e472d3b) + +2012-03-14 - Dan Bode +* Fix bug when querying for all database users (015490c) + +2012-02-09 - Nan Liu +* Major refactor of mysql module. (b1f90fd) + +2012-01-11 - Justin Ellison +* Ruby and Python's MySQL libraries are named differently on different distros. (1e926b4) + +2012-01-11 - Justin Ellison +* Per @ghoneycutt, we should fail explicitly and explain why. (09af083) + +2012-01-11 - Justin Ellison +* Removing duplicate declaration (7513d03) + +2012-01-10 - Justin Ellison +* Use socket value from params class instead of hardcoding. (663e97c) + +2012-01-10 - Justin Ellison +* Instead of hardcoding the config file target, pull it from mysql::params (031a47d) + +2012-01-10 - Justin Ellison +* Moved $socket to within the case to toggle between distros. Added a $config_file variable to allow per-distro config file destinations. (360eacd) + +2012-01-10 - Justin Ellison +* Pretty sure this is a bug, 99% of Linux distros out there won't ever hit the default. (3462e6b) + +2012-02-09 - William Van Hevelingen +* Changed the README to use markdown (3b7dfeb) + +2012-02-04 - Daniel Black +* (#12412) mysqltuner.pl update (b809e6f) + +2011-11-17 - Matthias Pigulla +* (#11363) Add two missing privileges to grant: event_priv, trigger_priv (d15c9d1) + +2011-12-20 - Jeff McCune +* (minor) Fixup typos in Modulefile metadata (a0ed6a1) + +2011-12-19 - Carl Caum +* Only notify Exec to import sql if sql is given (0783c74) + +2011-12-19 - Carl Caum +* (#11508) Only load sql_scripts on DB creation (e3b9fd9) + +2011-12-13 - Justin Ellison +* Require not needed due to implicit dependencies (3058feb) + +2011-12-13 - Justin Ellison +* Bug #11375: puppetlabs-mysql fails on CentOS/RHEL (a557b8d) + +2011-06-03 - Dan Bode - 0.0.1 +* initial commit diff --git a/deployment/modules/mysql/Gemfile b/deployment/modules/mysql/Gemfile new file mode 100644 index 000000000..d40840a2a --- /dev/null +++ b/deployment/modules/mysql/Gemfile @@ -0,0 +1,24 @@ +source 'https://rubygems.org' + +group :development, :test do + gem 'mime-types', '<2.0', :require => false + gem 'rake', :require => false + gem 'rspec-puppet', :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'rspec-system', :require => false + gem 'rspec-system-puppet', :require => false + gem 'rspec-system-serverspec', :require => false + gem 'serverspec', :require => false + gem 'puppet-lint', :require => false + gem 'pry', :require => false + gem 'simplecov', :require => false + gem 'beaker', :require => false +end + +if puppetversion = ENV['PUPPET_GEM_VERSION'] + gem 'puppet', puppetversion, :require => false +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/deployment/modules/mysql/Gemfile.lock b/deployment/modules/mysql/Gemfile.lock new file mode 100644 index 000000000..cfd88bd3e --- /dev/null +++ b/deployment/modules/mysql/Gemfile.lock @@ -0,0 +1,129 @@ +GEM + remote: https://rubygems.org/ + specs: + CFPropertyList (2.2.4) + beaker (1.0.0) + blimpy + fission + inifile + json + net-scp + net-ssh + nokogiri (= 1.5.10) + rbvmomi + unf + blimpy (0.6.7) + fog + minitar + thor + builder (3.2.2) + coderay (1.1.0) + diff-lcs (1.2.5) + docile (1.1.0) + excon (0.28.0) + facter (1.7.3) + fission (0.5.0) + CFPropertyList (~> 2.2) + fog (1.18.0) + builder + excon (~> 0.28.0) + formatador (~> 0.2.0) + mime-types + multi_json (~> 1.0) + net-scp (~> 1.1) + net-ssh (>= 2.1.3) + nokogiri (~> 1.5) + ruby-hmac + formatador (0.2.4) + highline (1.6.20) + inifile (2.0.2) + json (1.8.1) + kwalify (0.7.2) + lockfile (2.1.0) + metaclass (0.0.1) + method_source (0.8.2) + mime-types (1.25) + minitar (0.5.4) + mocha (0.14.0) + metaclass (~> 0.0.1) + multi_json (1.8.2) + net-scp (1.1.2) + net-ssh (>= 2.6.5) + net-ssh (2.7.0) + nokogiri (1.5.10) + pry (0.9.12.3) + coderay (~> 1.0) + method_source (~> 0.8) + slop (~> 3.4) + puppet (2.7.23) + facter (~> 1.5) + puppet-lint (0.3.2) + puppetlabs_spec_helper (0.4.1) + mocha (>= 0.10.5) + rake + rspec (>= 2.9.0) + rspec-puppet (>= 0.1.1) + rake (10.1.0) + rbvmomi (1.6.0) + builder + nokogiri (>= 1.4.1) + trollop + rspec (2.14.1) + rspec-core (~> 2.14.0) + rspec-expectations (~> 2.14.0) + rspec-mocks (~> 2.14.0) + rspec-core (2.14.7) + rspec-expectations (2.14.4) + diff-lcs (>= 1.1.3, < 2.0) + rspec-mocks (2.14.4) + rspec-puppet (0.1.6) + rspec + rspec-system (2.7.2) + kwalify (~> 0.7.2) + net-scp (~> 1.1) + net-ssh (~> 2.7) + nokogiri (~> 1.5.10) + rbvmomi (~> 1.6) + rspec (~> 2.14) + systemu (~> 2.5) + rspec-system-puppet (2.2.1) + rspec-system (~> 2.0) + rspec-system-serverspec (1.0.1) + rspec-system (~> 2.0) + serverspec (~> 0.0) + ruby-hmac (0.4.0) + serverspec (0.11.1) + highline + net-ssh + rspec (>= 2.13.0) + simplecov (0.8.1) + docile (~> 1.1.0) + lockfile (>= 2.1.0) + multi_json + simplecov-html (~> 0.8.0) + simplecov-html (0.8.0) + slop (3.4.6) + systemu (2.5.2) + thor (0.18.1) + trollop (2.0) + unf (0.1.3) + unf_ext + unf_ext (0.0.6) + +PLATFORMS + ruby + +DEPENDENCIES + beaker + mime-types (< 2.0) + pry + puppet (~> 2.7.0) + puppet-lint + puppetlabs_spec_helper + rake + rspec-puppet + rspec-system + rspec-system-puppet + rspec-system-serverspec + serverspec + simplecov diff --git a/deployment/modules/mysql/LICENSE b/deployment/modules/mysql/LICENSE new file mode 100644 index 000000000..297f85cfa --- /dev/null +++ b/deployment/modules/mysql/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2013 Puppet Labs + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/deployment/modules/mysql/Modulefile b/deployment/modules/mysql/Modulefile new file mode 100644 index 000000000..4301a0dd9 --- /dev/null +++ b/deployment/modules/mysql/Modulefile @@ -0,0 +1,9 @@ +name 'puppetlabs-mysql' +version '2.1.0' +source 'git://github.com/puppetlabs/puppetlabs-mysql.git' +author 'Puppet Labs' +license 'Apache 2.0' +summary 'Mysql module' +description 'Mysql module' +project_page 'http://github.com/puppetlabs/puppetlabs-mysql' +dependency 'puppetlabs/stdlib', '>= 2.2.1' diff --git a/deployment/modules/mysql/README.md b/deployment/modules/mysql/README.md new file mode 100644 index 000000000..78c957582 --- /dev/null +++ b/deployment/modules/mysql/README.md @@ -0,0 +1,492 @@ +#MySQL + +####Table of Contents + +1. [Overview](#overview) +2. [Module Description - What the module does and why it is useful](#module-description) +3. [Setup - The basics of getting started with mysql](#setup) + * [What mysql affects](#what-mysql-affects) + * [Setup requirements](#setup-requirements) + * [Beginning with mysql](#beginning-with-mysql) +4. [Usage - Configuration options and additional functionality](#usage) +5. [Reference - An under-the-hood peek at what the module is doing and how](#reference) +5. [Limitations - OS compatibility, etc.](#limitations) +6. [Development - Guide for contributing to the module](#development) + +##Overview + +The MySQL module installs, configures, and manages the MySQL service. + +##Module Description + +The MySQL module manages both the installation and configuration of MySQL as +well as extends Pupppet to allow management of MySQL resources, such as +databases, users, and grants. + +##Backwards Compatibility + +This module has just undergone a very large rewrite. As a result it will no +longer work with the previous classes and configuration as before. We've +attempted to handle backwards compatibility automatically by adding a +`attempt_compatibility_mode` parameter to the main mysql class. If you set +this to true it will attempt to map your previous parameters into the new +`mysql::server` class. + +###WARNING + +This may fail. It may eat your MySQL server. PLEASE test it before running it +live. Even if it's just a no-op and a manual comparision. Please be careful! + +##Setup + +###What MySQL affects + +* MySQL package. +* MySQL configuration files. +* MySQL service. + +###Beginning with MySQL + +If you just want a server installing with the default options you can run +`include '::mysql::server'`. If you need to customize options, such as the root +password or /etc/my.cnf settings then you can also include `mysql::server` and +pass in an override hash as seen below: + +```puppet +class { '::mysql::server': + root_password => 'strongpassword', + override_options => { 'mysqld' => { 'max_connections' => '1024' } } +} +``` + +##Usage + +All interaction for the server is done via `mysql::server`. To install the +client you use `mysql::client`, and to install bindings you can use +`mysql::bindings`. + +###Overrides + +The hash structure for overrides in `mysql::server` is as follows: + +```puppet +$override_options = { + 'section' => { + 'item' => 'thing', + } +} +``` + +For items that you would traditionally represent as: + +
+[section]
+thing
+
+ +You can just make an entry like `thing => true` in the hash. MySQL doesn't +care if thing is alone or set to a value, it'll happily accept both. + +###Custom configuration + +To add custom mysql configuration you can drop additional files into +`/etc/mysql/conf.d/` in order to override settings or add additional ones (if you +choose not to use override_options in `mysql::server`). This location is +hardcoded into the my.cnf template file. + +##Reference + +###Classes + +####Public classes +* `mysql::server`: Installs and configures MySQL. +* `mysql::server::account_security`: Deletes default MySQL accounts. +* `mysql::server::monitor`: Sets up a monitoring user. +* `mysql::server::mysqltuner`: Installs MySQL tuner script. +* `mysql::server::backup`: Sets up MySQL backups via cron. +* `mysql::bindings`: Installs various MySQL language bindings. +* `mysql::client`: Installs MySQL client (for non-servers). + +####Private classes +* `mysql::server::install`: Installs packages. +* `mysql::server::config`: Configures MYSQL. +* `mysql::server::service`: Manages service. +* `mysql::server::root_password`: Sets MySQL root password. +* `mysql::server::providers`: Creates users, grants, and databases. +* `mysql::bindings::java`: Installs Java bindings. +* `mysql::bindings::perl`: Installs Perl bindings. +* `mysql::bindings::python`: Installs Python bindings. +* `mysql::bindings::ruby`: Installs Ruby bindings. +* `mysql::client::install`: Installs MySQL client. + +###Parameters + +####mysql::server + +#####`root_password` + +What is the MySQL root password. Puppet will attempt to set it to this and update `/root/.my.cnf`. + +#####`old_root_password` + +What was the previous root password (REQUIRED if you wish to change the root password via Puppet.) + +#####`override_options` + +This is the hash of override options to pass into MySQL. It can be visualized +like a hash of the my.cnf file, so that entries look like: + +```puppet +$override_options = { + 'section' => { + 'item' => 'thing', + } +} +``` + +For items that you would traditionally represent as: + +
+[section]
+thing
+
+ +You can just make an entry like `thing => true` in the hash. MySQL doesn't +care if thing is alone or set to a value, it'll happily accept both. + +#####`config_file` + +The location of the MySQL configuration file. + +#####`manage_config_file` + +Should we manage the MySQL configuration file. + +#####`purge_conf_dir` + +Should we purge the conf.d directory? + +#####`restart` + +Should the service be restarted when things change? + +#####`root_group` + +What is the group used for root? + +#####`package_ensure` + +What to set the package to. Can be present, absent, or version. + +#####`package_name` + +What is the name of the mysql server package to install. + +#####`remove_default_accounts` + +Boolean to decide if we should automatically include +`mysql::server::account_security`. + +#####`service_enabled` + +Boolean to decide if the service should be enabled. + +#####`service_manage` + +Boolean to decide if the service should be managed. + +#####`service_name` + +What is the name of the mysql server service. + +#####`service_provider` + +Which provider to use to manage the service. + +#####`users` + +Optional hash of users to create, which are passed to [mysql_user](#mysql_user). Example: +```puppet +$users = { + 'someuser@localhost' => { + ensure => 'present', + max_connections_per_hour => '0', + max_queries_per_hour => '0', + max_updates_per_hour => '0', + max_user_connections => '0', + password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF', + }, +} +``` + +#####`grants` + +Optional hash of grants, which are passed to [mysql_grant](#mysql_grant). Example: +```puppet +$grants = { + 'someuser@localhost/somedb.*' => { + ensure => 'present', + options => ['GRANT'], + privileges => ['SELECT', 'INSERT', 'UPDATE', 'DELETE'], + table => 'somedb.*', + user => 'someuser@localhost', + }, +} +``` + +#####`databases` + +Optional hash of databases to create, which are passed to [mysql_database](#mysql_database). Example: +```puppet +$databases = { + 'somedb' => { + ensure => 'present', + charset => 'utf8', + }, +} +``` + +#####`service_provider` + +####mysql::server::backup + +#####`backupuser` + +MySQL user to create for backing up. + +#####`backuppassword` + +MySQL user password for backups. + +#####`backupdir` + +Directory to backup into. + +#####`backupcompress` + +Boolean to determine if backups should be compressed. + +#####`backuprotate` + +How many days to keep backups for. + +#####`delete_before_dump` + +Boolean to determine if you should cleanup before backing up or after. + +#####`backupdatabases` + +Array of databases to specifically backup. + +#####`file_per_database` + +Should a seperate file be used per database. + +#####`ensure` + +Present or absent, allows you to remove the backup scripts. + +#####`time` + +An array of two elements to set the time to backup. Allows ['23', '5'] or ['3', '45'] for HH:MM times. + +####mysql::server::monitor + +#####`mysql_monitor_username` + +The username to create for MySQL monitoring. + +#####`mysql_monitor_password` + +The password to create for MySQL monitoring. + +#####`mysql_monitor_hostname` + +The hostname to allow to access the MySQL monitoring user. + +####mysql::bindings + +#####`java_enable` + +Boolean to decide if the Java bindings should be installed. + +#####`perl_enable` + +Boolean to decide if the Perl bindings should be installed. + +#####`php_enable` + +Boolean to decide if the PHP bindings should be installed. + +#####`python_enable` + +Boolean to decide if the Python bindings should be installed. + +#####`ruby_enable` + +Boolean to decide if the Ruby bindings should be installed. + +#####`java_package_ensure` + +What to set the package to. Can be present, absent, or version. + +#####`java_package_name` + +The name of the package to install. + +#####`java_package_provider` + +What provider should be used to install the package. + +#####`perl_package_ensure` + +What to set the package to. Can be present, absent, or version. + +#####`perl_package_name` + +The name of the package to install. + +#####`perl_package_provider` + +What provider should be used to install the package. + +#####`python_package_ensure` + +What to set the package to. Can be present, absent, or version. + +#####`python_package_name` + +The name of the package to install. + +#####`python_package_provider` + +What provider should be used to install the package. + +#####`ruby_package_ensure` + +What to set the package to. Can be present, absent, or version. + +#####`ruby_package_name` + +The name of the package to install. + +#####`ruby_package_provider` + +What provider should be used to install the package. + +####mysql::client + +#####`bindings_enable` + +Boolean to automatically install all bindings. + +#####`package_ensure` + +What to set the package to. Can be present, absent, or version. + +#####`package_name` + +What is the name of the mysql client package to install. + +###Defines + +####mysql::db + +Creates a database with a user and assign some privileges. + +```puppet + mysql::db { 'mydb': + user => 'myuser', + password => 'mypass', + host => 'localhost', + grant => ['SELECT', 'UPDATE'], + } +``` + +###Providers + +####mysql_database + +mysql_database can be used to create and manage databases within MySQL: + +```puppet +mysql_database { 'information_schema': + ensure => 'present', + charset => 'utf8', + collate => 'utf8_swedish_ci', +} +mysql_database { 'mysql': + ensure => 'present', + charset => 'latin1', + collate => 'latin1_swedish_ci', +} +``` + +####mysql_user + +mysql_user can be used to create and manage user grants within MySQL: + +```puppet +mysql_user { 'root@127.0.0.1': + ensure => 'present', + max_connections_per_hour => '0', + max_queries_per_hour => '0', + max_updates_per_hour => '0', + max_user_connections => '0', +} +``` + +####mysql_grant + +mysql_grant can be used to create grant permissions to access databases within +MySQL. To use it you must create the title of the resource as shown below, +following the pattern of `username@hostname/database.table`: + +```puppet +mysql_grant { 'root@localhost/*.*': + ensure => 'present', + options => ['GRANT'], + privileges => ['ALL'], + table => '*.*', + user => 'root@localhost', +} +``` + +##Limitations + +This module has been tested on: + +* RedHat Enterprise Linux 5/6 +* Debian 6/7 +* CentOS 5/6 +* Ubuntu 12.04 + +Testing on other platforms has been light and cannot be guaranteed. + +#Development + +Puppet Labs modules on the Puppet Forge are open projects, and community +contributions are essential for keeping them great. We can’t access the +huge number of platforms and myriad of hardware, software, and deployment +configurations that Puppet is intended to serve. + +We want to keep it as easy as possible to contribute changes so that our +modules work in your environment. There are a few guidelines that we need +contributors to follow so that we can have a chance of keeping on top of things. + +You can read the complete module contribution guide [on the Puppet Labs wiki.](http://projects.puppetlabs.com/projects/module-site/wiki/Module_contributing) + +### Authors + +This module is based on work by David Schmitt. The following contributor have contributed patches to this module (beyond Puppet Labs): + +* Larry Ludwig +* Christian G. Warden +* Daniel Black +* Justin Ellison +* Lowe Schmidt +* Matthias Pigulla +* William Van Hevelingen +* Michael Arnold +* Chris Weyl + diff --git a/deployment/modules/mysql/Rakefile b/deployment/modules/mysql/Rakefile new file mode 100644 index 000000000..bb60173e5 --- /dev/null +++ b/deployment/modules/mysql/Rakefile @@ -0,0 +1,2 @@ +require 'puppetlabs_spec_helper/rake_tasks' +require 'rspec-system/rake_task' diff --git a/deployment/modules/mysql/TODO b/deployment/modules/mysql/TODO new file mode 100644 index 000000000..391329393 --- /dev/null +++ b/deployment/modules/mysql/TODO @@ -0,0 +1,8 @@ +The best that I can tell is that this code traces back to David Schmitt. It has been forked many times since then :) + +1. you cannot add databases to an instance that has a root password +2. you have to specify username as USER@BLAH or it cannot be found +3. mysql_grant does not complain if user does not exist +4. Needs support for pre-seeding on debian +5. the types may need to take user/password +6. rather or not to configure /etc/.my.cnf should be configurable diff --git a/deployment/modules/mysql/files/mysqltuner.pl b/deployment/modules/mysql/files/mysqltuner.pl new file mode 100644 index 000000000..46cdb7f42 --- /dev/null +++ b/deployment/modules/mysql/files/mysqltuner.pl @@ -0,0 +1,966 @@ +#!/usr/bin/perl -w +# mysqltuner.pl - Version 1.2.0 +# High Performance MySQL Tuning Script +# Copyright (C) 2006-2011 Major Hayden - major@mhtx.net +# +# For the latest updates, please visit http://mysqltuner.com/ +# Git repository available at http://github.com/rackerhacker/MySQLTuner-perl +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +# This project would not be possible without help from: +# Matthew Montgomery Paul Kehrer Dave Burgess +# Jonathan Hinds Mike Jackson Nils Breunese +# Shawn Ashlee Luuk Vosslamber Ville Skytta +# Trent Hornibrook Jason Gill Mark Imbriaco +# Greg Eden Aubin Galinotti Giovanni Bechis +# Bill Bradford Ryan Novosielski Michael Scheidell +# Blair Christensen Hans du Plooy Victor Trac +# Everett Barnes Tom Krouper Gary Barrueto +# Simon Greenaway Adam Stein Isart Montane +# Baptiste M. +# +# Inspired by Matthew Montgomery's tuning-primer.sh script: +# http://forge.mysql.com/projects/view.php?id=44 +# +use strict; +use warnings; +use diagnostics; +use File::Spec; +use Getopt::Long; + +# Set up a few variables for use in the script +my $tunerversion = "1.2.0"; +my (@adjvars, @generalrec); + +# Set defaults +my %opt = ( + "nobad" => 0, + "nogood" => 0, + "noinfo" => 0, + "nocolor" => 0, + "forcemem" => 0, + "forceswap" => 0, + "host" => 0, + "socket" => 0, + "port" => 0, + "user" => 0, + "pass" => 0, + "skipsize" => 0, + "checkversion" => 0, + ); + +# Gather the options from the command line +GetOptions(\%opt, + 'nobad', + 'nogood', + 'noinfo', + 'nocolor', + 'forcemem=i', + 'forceswap=i', + 'host=s', + 'socket=s', + 'port=i', + 'user=s', + 'pass=s', + 'skipsize', + 'checkversion', + 'help', + ); + +if (defined $opt{'help'} && $opt{'help'} == 1) { usage(); } + +sub usage { + # Shown with --help option passed + print "\n". + " MySQLTuner $tunerversion - MySQL High Performance Tuning Script\n". + " Bug reports, feature requests, and downloads at http://mysqltuner.com/\n". + " Maintained by Major Hayden (major\@mhtx.net) - Licensed under GPL\n". + "\n". + " Important Usage Guidelines:\n". + " To run the script with the default options, run the script without arguments\n". + " Allow MySQL server to run for at least 24-48 hours before trusting suggestions\n". + " Some routines may require root level privileges (script will provide warnings)\n". + " You must provide the remote server's total memory when connecting to other servers\n". + "\n". + " Connection and Authentication\n". + " --host Connect to a remote host to perform tests (default: localhost)\n". + " --socket Use a different socket for a local connection\n". + " --port Port to use for connection (default: 3306)\n". + " --user Username to use for authentication\n". + " --pass Password to use for authentication\n". + "\n". + " Performance and Reporting Options\n". + " --skipsize Don't enumerate tables and their types/sizes (default: on)\n". + " (Recommended for servers with many tables)\n". + " --checkversion Check for updates to MySQLTuner (default: don't check)\n". + " --forcemem Amount of RAM installed in megabytes\n". + " --forceswap Amount of swap memory configured in megabytes\n". + "\n". + " Output Options:\n". + " --nogood Remove OK responses\n". + " --nobad Remove negative/suggestion responses\n". + " --noinfo Remove informational responses\n". + " --nocolor Don't print output in color\n". + "\n"; + exit; +} + +my $devnull = File::Spec->devnull(); + +# Setting up the colors for the print styles +my $good = ($opt{nocolor} == 0)? "[\e[0;32mOK\e[0m]" : "[OK]" ; +my $bad = ($opt{nocolor} == 0)? "[\e[0;31m!!\e[0m]" : "[!!]" ; +my $info = ($opt{nocolor} == 0)? "[\e[0;34m--\e[0m]" : "[--]" ; + +# Functions that handle the print styles +sub goodprint { print $good." ".$_[0] unless ($opt{nogood} == 1); } +sub infoprint { print $info." ".$_[0] unless ($opt{noinfo} == 1); } +sub badprint { print $bad." ".$_[0] unless ($opt{nobad} == 1); } +sub redwrap { return ($opt{nocolor} == 0)? "\e[0;31m".$_[0]."\e[0m" : $_[0] ; } +sub greenwrap { return ($opt{nocolor} == 0)? "\e[0;32m".$_[0]."\e[0m" : $_[0] ; } + +# Calculates the parameter passed in bytes, and then rounds it to one decimal place +sub hr_bytes { + my $num = shift; + if ($num >= (1024**3)) { #GB + return sprintf("%.1f",($num/(1024**3)))."G"; + } elsif ($num >= (1024**2)) { #MB + return sprintf("%.1f",($num/(1024**2)))."M"; + } elsif ($num >= 1024) { #KB + return sprintf("%.1f",($num/1024))."K"; + } else { + return $num."B"; + } +} + +# Calculates the parameter passed in bytes, and then rounds it to the nearest integer +sub hr_bytes_rnd { + my $num = shift; + if ($num >= (1024**3)) { #GB + return int(($num/(1024**3)))."G"; + } elsif ($num >= (1024**2)) { #MB + return int(($num/(1024**2)))."M"; + } elsif ($num >= 1024) { #KB + return int(($num/1024))."K"; + } else { + return $num."B"; + } +} + +# Calculates the parameter passed to the nearest power of 1000, then rounds it to the nearest integer +sub hr_num { + my $num = shift; + if ($num >= (1000**3)) { # Billions + return int(($num/(1000**3)))."B"; + } elsif ($num >= (1000**2)) { # Millions + return int(($num/(1000**2)))."M"; + } elsif ($num >= 1000) { # Thousands + return int(($num/1000))."K"; + } else { + return $num; + } +} + +# Calculates uptime to display in a more attractive form +sub pretty_uptime { + my $uptime = shift; + my $seconds = $uptime % 60; + my $minutes = int(($uptime % 3600) / 60); + my $hours = int(($uptime % 86400) / (3600)); + my $days = int($uptime / (86400)); + my $uptimestring; + if ($days > 0) { + $uptimestring = "${days}d ${hours}h ${minutes}m ${seconds}s"; + } elsif ($hours > 0) { + $uptimestring = "${hours}h ${minutes}m ${seconds}s"; + } elsif ($minutes > 0) { + $uptimestring = "${minutes}m ${seconds}s"; + } else { + $uptimestring = "${seconds}s"; + } + return $uptimestring; +} + +# Retrieves the memory installed on this machine +my ($physical_memory,$swap_memory,$duflags); +sub os_setup { + sub memerror { + badprint "Unable to determine total memory/swap; use '--forcemem' and '--forceswap'\n"; + exit; + } + my $os = `uname`; + $duflags = ($os =~ /Linux/) ? '-b' : ''; + if ($opt{'forcemem'} > 0) { + $physical_memory = $opt{'forcemem'} * 1048576; + infoprint "Assuming $opt{'forcemem'} MB of physical memory\n"; + if ($opt{'forceswap'} > 0) { + $swap_memory = $opt{'forceswap'} * 1048576; + infoprint "Assuming $opt{'forceswap'} MB of swap space\n"; + } else { + $swap_memory = 0; + badprint "Assuming 0 MB of swap space (use --forceswap to specify)\n"; + } + } else { + if ($os =~ /Linux/) { + $physical_memory = `free -b | grep Mem | awk '{print \$2}'` or memerror; + $swap_memory = `free -b | grep Swap | awk '{print \$2}'` or memerror; + } elsif ($os =~ /Darwin/) { + $physical_memory = `sysctl -n hw.memsize` or memerror; + $swap_memory = `sysctl -n vm.swapusage | awk '{print \$3}' | sed 's/\..*\$//'` or memerror; + } elsif ($os =~ /NetBSD|OpenBSD/) { + $physical_memory = `sysctl -n hw.physmem` or memerror; + if ($physical_memory < 0) { + $physical_memory = `sysctl -n hw.physmem64` or memerror; + } + $swap_memory = `swapctl -l | grep '^/' | awk '{ s+= \$2 } END { print s }'` or memerror; + } elsif ($os =~ /BSD/) { + $physical_memory = `sysctl -n hw.realmem`; + $swap_memory = `swapinfo | grep '^/' | awk '{ s+= \$2 } END { print s }'`; + } elsif ($os =~ /SunOS/) { + $physical_memory = `/usr/sbin/prtconf | grep Memory | cut -f 3 -d ' '` or memerror; + chomp($physical_memory); + $physical_memory = $physical_memory*1024*1024; + } elsif ($os =~ /AIX/) { + $physical_memory = `lsattr -El sys0 | grep realmem | awk '{print \$2}'` or memerror; + chomp($physical_memory); + $physical_memory = $physical_memory*1024; + $swap_memory = `lsps -as | awk -F"(MB| +)" '/MB /{print \$2}'` or memerror; + chomp($swap_memory); + $swap_memory = $swap_memory*1024*1024; + } + } + chomp($physical_memory); +} + +# Checks to see if a MySQL login is possible +my ($mysqllogin,$doremote,$remotestring); +sub mysql_setup { + $doremote = 0; + $remotestring = ''; + my $command = `which mysqladmin`; + chomp($command); + if (! -e $command) { + badprint "Unable to find mysqladmin in your \$PATH. Is MySQL installed?\n"; + exit; + } + # Are we being asked to connect via a socket? + if ($opt{socket} ne 0) { + $remotestring = " -S $opt{socket}"; + } + # Are we being asked to connect to a remote server? + if ($opt{host} ne 0) { + chomp($opt{host}); + $opt{port} = ($opt{port} eq 0)? 3306 : $opt{port} ; + # If we're doing a remote connection, but forcemem wasn't specified, we need to exit + if ($opt{'forcemem'} eq 0) { + badprint "The --forcemem option is required for remote connections\n"; + exit; + } + infoprint "Performing tests on $opt{host}:$opt{port}\n"; + $remotestring = " -h $opt{host} -P $opt{port}"; + $doremote = 1; + } + # Did we already get a username and password passed on the command line? + if ($opt{user} ne 0 and $opt{pass} ne 0) { + $mysqllogin = "-u $opt{user} -p'$opt{pass}'".$remotestring; + my $loginstatus = `mysqladmin ping $mysqllogin 2>&1`; + if ($loginstatus =~ /mysqld is alive/) { + goodprint "Logged in using credentials passed on the command line\n"; + return 1; + } else { + badprint "Attempted to use login credentials, but they were invalid\n"; + exit 0; + } + } + if ( -r "/etc/psa/.psa.shadow" and $doremote == 0 ) { + # It's a Plesk box, use the available credentials + $mysqllogin = "-u admin -p`cat /etc/psa/.psa.shadow`"; + my $loginstatus = `mysqladmin ping $mysqllogin 2>&1`; + unless ($loginstatus =~ /mysqld is alive/) { + badprint "Attempted to use login credentials from Plesk, but they failed.\n"; + exit 0; + } + } elsif ( -r "/etc/mysql/debian.cnf" and $doremote == 0 ){ + # We have a debian maintenance account, use it + $mysqllogin = "--defaults-extra-file=/etc/mysql/debian.cnf"; + my $loginstatus = `mysqladmin $mysqllogin ping 2>&1`; + if ($loginstatus =~ /mysqld is alive/) { + goodprint "Logged in using credentials from debian maintenance account.\n"; + return 1; + } else { + badprint "Attempted to use login credentials from debian maintenance account, but they failed.\n"; + exit 0; + } + } else { + # It's not Plesk or debian, we should try a login + my $loginstatus = `mysqladmin $remotestring ping 2>&1`; + if ($loginstatus =~ /mysqld is alive/) { + # Login went just fine + $mysqllogin = " $remotestring "; + # Did this go well because of a .my.cnf file or is there no password set? + my $userpath = `printenv HOME`; + if (length($userpath) > 0) { + chomp($userpath); + } + unless ( -e "${userpath}/.my.cnf" ) { + badprint "Successfully authenticated with no password - SECURITY RISK!\n"; + } + return 1; + } else { + print STDERR "Please enter your MySQL administrative login: "; + my $name = <>; + print STDERR "Please enter your MySQL administrative password: "; + system("stty -echo >$devnull 2>&1"); + my $password = <>; + system("stty echo >$devnull 2>&1"); + chomp($password); + chomp($name); + $mysqllogin = "-u $name"; + if (length($password) > 0) { + $mysqllogin .= " -p'$password'"; + } + $mysqllogin .= $remotestring; + my $loginstatus = `mysqladmin ping $mysqllogin 2>&1`; + if ($loginstatus =~ /mysqld is alive/) { + print STDERR "\n"; + if (! length($password)) { + # Did this go well because of a .my.cnf file or is there no password set? + my $userpath = `ls -d ~`; + chomp($userpath); + unless ( -e "$userpath/.my.cnf" ) { + badprint "Successfully authenticated with no password - SECURITY RISK!\n"; + } + } + return 1; + } else { + print "\n".$bad." Attempted to use login credentials, but they were invalid.\n"; + exit 0; + } + exit 0; + } + } +} + +# Populates all of the variable and status hashes +my (%mystat,%myvar,$dummyselect); +sub get_all_vars { + # We need to initiate at least one query so that our data is useable + $dummyselect = `mysql $mysqllogin -Bse "SELECT VERSION();"`; + my @mysqlvarlist = `mysql $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ VARIABLES;"`; + foreach my $line (@mysqlvarlist) { + $line =~ /([a-zA-Z_]*)\s*(.*)/; + $myvar{$1} = $2; + } + my @mysqlstatlist = `mysql $mysqllogin -Bse "SHOW /*!50000 GLOBAL */ STATUS;"`; + foreach my $line (@mysqlstatlist) { + $line =~ /([a-zA-Z_]*)\s*(.*)/; + $mystat{$1} = $2; + } + # Workaround for MySQL bug #59393 wrt. ignore-builtin-innodb + if (($myvar{'ignore_builtin_innodb'} || "") eq "ON") { + $myvar{'have_innodb'} = "NO"; + } + # have_* for engines is deprecated and will be removed in MySQL 5.6; + # check SHOW ENGINES and set corresponding old style variables. + # Also works around MySQL bug #59393 wrt. skip-innodb + my @mysqlenginelist = `mysql $mysqllogin -Bse "SHOW ENGINES;" 2>$devnull`; + foreach my $line (@mysqlenginelist) { + if ($line =~ /^([a-zA-Z_]+)\s+(\S+)/) { + my $engine = lc($1); + if ($engine eq "federated" || $engine eq "blackhole") { + $engine .= "_engine"; + } elsif ($engine eq "berkeleydb") { + $engine = "bdb"; + } + my $val = ($2 eq "DEFAULT") ? "YES" : $2; + $myvar{"have_$engine"} = $val; + } + } +} + +sub security_recommendations { + print "\n-------- Security Recommendations -------------------------------------------\n"; + my @mysqlstatlist = `mysql $mysqllogin -Bse "SELECT CONCAT(user, '\@', host) FROM mysql.user WHERE password = '' OR password IS NULL;"`; + if (@mysqlstatlist) { + foreach my $line (sort @mysqlstatlist) { + chomp($line); + badprint "User '".$line."' has no password set.\n"; + } + } else { + goodprint "All database users have passwords assigned\n"; + } +} + +sub get_replication_status { + my $slave_status = `mysql $mysqllogin -Bse "show slave status\\G"`; + my ($io_running) = ($slave_status =~ /slave_io_running\S*\s+(\S+)/i); + my ($sql_running) = ($slave_status =~ /slave_sql_running\S*\s+(\S+)/i); + if ($io_running eq 'Yes' && $sql_running eq 'Yes') { + if ($myvar{'read_only'} eq 'OFF') { + badprint "This replication slave is running with the read_only option disabled."; + } else { + goodprint "This replication slave is running with the read_only option enabled."; + } + } +} + +# Checks for updates to MySQLTuner +sub validate_tuner_version { + print "\n-------- General Statistics --------------------------------------------------\n"; + if ($opt{checkversion} eq 0) { + infoprint "Skipped version check for MySQLTuner script\n"; + return; + } + my $update; + my $url = "http://mysqltuner.com/versioncheck.php?v=$tunerversion"; + if (-e "/usr/bin/curl") { + $update = `/usr/bin/curl --connect-timeout 5 '$url' 2>$devnull`; + chomp($update); + } elsif (-e "/usr/bin/wget") { + $update = `/usr/bin/wget -e timestamping=off -T 5 -O - '$url' 2>$devnull`; + chomp($update); + } + if ($update eq 1) { + badprint "There is a new version of MySQLTuner available\n"; + } elsif ($update eq 0) { + goodprint "You have the latest version of MySQLTuner\n"; + } else { + infoprint "Unable to check for the latest MySQLTuner version\n"; + } +} + +# Checks for supported or EOL'ed MySQL versions +my ($mysqlvermajor,$mysqlverminor); +sub validate_mysql_version { + ($mysqlvermajor,$mysqlverminor) = $myvar{'version'} =~ /(\d)\.(\d)/; + if (!mysql_version_ge(5)) { + badprint "Your MySQL version ".$myvar{'version'}." is EOL software! Upgrade soon!\n"; + } elsif (mysql_version_ge(6)) { + badprint "Currently running unsupported MySQL version ".$myvar{'version'}."\n"; + } else { + goodprint "Currently running supported MySQL version ".$myvar{'version'}."\n"; + } +} + +# Checks if MySQL version is greater than equal to (major, minor) +sub mysql_version_ge { + my ($maj, $min) = @_; + return $mysqlvermajor > $maj || ($mysqlvermajor == $maj && $mysqlverminor >= ($min || 0)); +} + +# Checks for 32-bit boxes with more than 2GB of RAM +my ($arch); +sub check_architecture { + if ($doremote eq 1) { return; } + if (`uname` =~ /SunOS/ && `isainfo -b` =~ /64/) { + $arch = 64; + goodprint "Operating on 64-bit architecture\n"; + } elsif (`uname` !~ /SunOS/ && `uname -m` =~ /64/) { + $arch = 64; + goodprint "Operating on 64-bit architecture\n"; + } elsif (`uname` =~ /AIX/ && `bootinfo -K` =~ /64/) { + $arch = 64; + goodprint "Operating on 64-bit architecture\n"; + } else { + $arch = 32; + if ($physical_memory > 2147483648) { + badprint "Switch to 64-bit OS - MySQL cannot currently use all of your RAM\n"; + } else { + goodprint "Operating on 32-bit architecture with less than 2GB RAM\n"; + } + } +} + +# Start up a ton of storage engine counts/statistics +my (%enginestats,%enginecount,$fragtables); +sub check_storage_engines { + if ($opt{skipsize} eq 1) { + print "\n-------- Storage Engine Statistics -------------------------------------------\n"; + infoprint "Skipped due to --skipsize option\n"; + return; + } + print "\n-------- Storage Engine Statistics -------------------------------------------\n"; + infoprint "Status: "; + my $engines; + $engines .= (defined $myvar{'have_archive'} && $myvar{'have_archive'} eq "YES")? greenwrap "+Archive " : redwrap "-Archive " ; + $engines .= (defined $myvar{'have_bdb'} && $myvar{'have_bdb'} eq "YES")? greenwrap "+BDB " : redwrap "-BDB " ; + $engines .= (defined $myvar{'have_federated_engine'} && $myvar{'have_federated_engine'} eq "YES")? greenwrap "+Federated " : redwrap "-Federated " ; + $engines .= (defined $myvar{'have_innodb'} && $myvar{'have_innodb'} eq "YES")? greenwrap "+InnoDB " : redwrap "-InnoDB " ; + $engines .= (defined $myvar{'have_isam'} && $myvar{'have_isam'} eq "YES")? greenwrap "+ISAM " : redwrap "-ISAM " ; + $engines .= (defined $myvar{'have_ndbcluster'} && $myvar{'have_ndbcluster'} eq "YES")? greenwrap "+NDBCluster " : redwrap "-NDBCluster " ; + print "$engines\n"; + if (mysql_version_ge(5)) { + # MySQL 5 servers can have table sizes calculated quickly from information schema + my @templist = `mysql $mysqllogin -Bse "SELECT ENGINE,SUM(DATA_LENGTH),COUNT(ENGINE) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND ENGINE IS NOT NULL GROUP BY ENGINE ORDER BY ENGINE ASC;"`; + foreach my $line (@templist) { + my ($engine,$size,$count); + ($engine,$size,$count) = $line =~ /([a-zA-Z_]*)\s+(\d+)\s+(\d+)/; + if (!defined($size)) { next; } + $enginestats{$engine} = $size; + $enginecount{$engine} = $count; + } + $fragtables = `mysql $mysqllogin -Bse "SELECT COUNT(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema','mysql') AND Data_free > 0 AND NOT ENGINE='MEMORY';"`; + chomp($fragtables); + } else { + # MySQL < 5 servers take a lot of work to get table sizes + my @tblist; + # Now we build a database list, and loop through it to get storage engine stats for tables + my @dblist = `mysql $mysqllogin -Bse "SHOW DATABASES"`; + foreach my $db (@dblist) { + chomp($db); + if ($db eq "information_schema") { next; } + my @ixs = (1, 6, 9); + if (!mysql_version_ge(4, 1)) { + # MySQL 3.23/4.0 keeps Data_Length in the 5th (0-based) column + @ixs = (1, 5, 8); + } + push(@tblist, map { [ (split)[@ixs] ] } `mysql $mysqllogin -Bse "SHOW TABLE STATUS FROM \\\`$db\\\`"`); + } + # Parse through the table list to generate storage engine counts/statistics + $fragtables = 0; + foreach my $tbl (@tblist) { + my ($engine, $size, $datafree) = @$tbl; + if (defined $enginestats{$engine}) { + $enginestats{$engine} += $size; + $enginecount{$engine} += 1; + } else { + $enginestats{$engine} = $size; + $enginecount{$engine} = 1; + } + if ($datafree > 0) { + $fragtables++; + } + } + } + while (my ($engine,$size) = each(%enginestats)) { + infoprint "Data in $engine tables: ".hr_bytes_rnd($size)." (Tables: ".$enginecount{$engine}.")"."\n"; + } + # If the storage engine isn't being used, recommend it to be disabled + if (!defined $enginestats{'InnoDB'} && defined $myvar{'have_innodb'} && $myvar{'have_innodb'} eq "YES") { + badprint "InnoDB is enabled but isn't being used\n"; + push(@generalrec,"Add skip-innodb to MySQL configuration to disable InnoDB"); + } + if (!defined $enginestats{'BerkeleyDB'} && defined $myvar{'have_bdb'} && $myvar{'have_bdb'} eq "YES") { + badprint "BDB is enabled but isn't being used\n"; + push(@generalrec,"Add skip-bdb to MySQL configuration to disable BDB"); + } + if (!defined $enginestats{'ISAM'} && defined $myvar{'have_isam'} && $myvar{'have_isam'} eq "YES") { + badprint "ISAM is enabled but isn't being used\n"; + push(@generalrec,"Add skip-isam to MySQL configuration to disable ISAM (MySQL > 4.1.0)"); + } + # Fragmented tables + if ($fragtables > 0) { + badprint "Total fragmented tables: $fragtables\n"; + push(@generalrec,"Run OPTIMIZE TABLE to defragment tables for better performance"); + } else { + goodprint "Total fragmented tables: $fragtables\n"; + } +} + +my %mycalc; +sub calculations { + if ($mystat{'Questions'} < 1) { + badprint "Your server has not answered any queries - cannot continue..."; + exit 0; + } + # Per-thread memory + if (mysql_version_ge(4)) { + $mycalc{'per_thread_buffers'} = $myvar{'read_buffer_size'} + $myvar{'read_rnd_buffer_size'} + $myvar{'sort_buffer_size'} + $myvar{'thread_stack'} + $myvar{'join_buffer_size'}; + } else { + $mycalc{'per_thread_buffers'} = $myvar{'record_buffer'} + $myvar{'record_rnd_buffer'} + $myvar{'sort_buffer'} + $myvar{'thread_stack'} + $myvar{'join_buffer_size'}; + } + $mycalc{'total_per_thread_buffers'} = $mycalc{'per_thread_buffers'} * $myvar{'max_connections'}; + $mycalc{'max_total_per_thread_buffers'} = $mycalc{'per_thread_buffers'} * $mystat{'Max_used_connections'}; + + # Server-wide memory + $mycalc{'max_tmp_table_size'} = ($myvar{'tmp_table_size'} > $myvar{'max_heap_table_size'}) ? $myvar{'max_heap_table_size'} : $myvar{'tmp_table_size'} ; + $mycalc{'server_buffers'} = $myvar{'key_buffer_size'} + $mycalc{'max_tmp_table_size'}; + $mycalc{'server_buffers'} += (defined $myvar{'innodb_buffer_pool_size'}) ? $myvar{'innodb_buffer_pool_size'} : 0 ; + $mycalc{'server_buffers'} += (defined $myvar{'innodb_additional_mem_pool_size'}) ? $myvar{'innodb_additional_mem_pool_size'} : 0 ; + $mycalc{'server_buffers'} += (defined $myvar{'innodb_log_buffer_size'}) ? $myvar{'innodb_log_buffer_size'} : 0 ; + $mycalc{'server_buffers'} += (defined $myvar{'query_cache_size'}) ? $myvar{'query_cache_size'} : 0 ; + + # Global memory + $mycalc{'max_used_memory'} = $mycalc{'server_buffers'} + $mycalc{"max_total_per_thread_buffers"}; + $mycalc{'total_possible_used_memory'} = $mycalc{'server_buffers'} + $mycalc{'total_per_thread_buffers'}; + $mycalc{'pct_physical_memory'} = int(($mycalc{'total_possible_used_memory'} * 100) / $physical_memory); + + # Slow queries + $mycalc{'pct_slow_queries'} = int(($mystat{'Slow_queries'}/$mystat{'Questions'}) * 100); + + # Connections + $mycalc{'pct_connections_used'} = int(($mystat{'Max_used_connections'}/$myvar{'max_connections'}) * 100); + $mycalc{'pct_connections_used'} = ($mycalc{'pct_connections_used'} > 100) ? 100 : $mycalc{'pct_connections_used'} ; + + # Key buffers + if (mysql_version_ge(4, 1)) { + $mycalc{'pct_key_buffer_used'} = sprintf("%.1f",(1 - (($mystat{'Key_blocks_unused'} * $myvar{'key_cache_block_size'}) / $myvar{'key_buffer_size'})) * 100); + } + if ($mystat{'Key_read_requests'} > 0) { + $mycalc{'pct_keys_from_mem'} = sprintf("%.1f",(100 - (($mystat{'Key_reads'} / $mystat{'Key_read_requests'}) * 100))); + } else { + $mycalc{'pct_keys_from_mem'} = 0; + } + if ($doremote eq 0 and !mysql_version_ge(5)) { + my $size = 0; + $size += (split)[0] for `find $myvar{'datadir'} -name "*.MYI" 2>&1 | xargs du -L $duflags 2>&1`; + $mycalc{'total_myisam_indexes'} = $size; + } elsif (mysql_version_ge(5)) { + $mycalc{'total_myisam_indexes'} = `mysql $mysqllogin -Bse "SELECT IFNULL(SUM(INDEX_LENGTH),0) FROM information_schema.TABLES WHERE TABLE_SCHEMA NOT IN ('information_schema') AND ENGINE = 'MyISAM';"`; + } + if (defined $mycalc{'total_myisam_indexes'} and $mycalc{'total_myisam_indexes'} == 0) { + $mycalc{'total_myisam_indexes'} = "fail"; + } elsif (defined $mycalc{'total_myisam_indexes'}) { + chomp($mycalc{'total_myisam_indexes'}); + } + + # Query cache + if (mysql_version_ge(4)) { + $mycalc{'query_cache_efficiency'} = sprintf("%.1f",($mystat{'Qcache_hits'} / ($mystat{'Com_select'} + $mystat{'Qcache_hits'})) * 100); + if ($myvar{'query_cache_size'}) { + $mycalc{'pct_query_cache_used'} = sprintf("%.1f",100 - ($mystat{'Qcache_free_memory'} / $myvar{'query_cache_size'}) * 100); + } + if ($mystat{'Qcache_lowmem_prunes'} == 0) { + $mycalc{'query_cache_prunes_per_day'} = 0; + } else { + $mycalc{'query_cache_prunes_per_day'} = int($mystat{'Qcache_lowmem_prunes'} / ($mystat{'Uptime'}/86400)); + } + } + + # Sorting + $mycalc{'total_sorts'} = $mystat{'Sort_scan'} + $mystat{'Sort_range'}; + if ($mycalc{'total_sorts'} > 0) { + $mycalc{'pct_temp_sort_table'} = int(($mystat{'Sort_merge_passes'} / $mycalc{'total_sorts'}) * 100); + } + + # Joins + $mycalc{'joins_without_indexes'} = $mystat{'Select_range_check'} + $mystat{'Select_full_join'}; + $mycalc{'joins_without_indexes_per_day'} = int($mycalc{'joins_without_indexes'} / ($mystat{'Uptime'}/86400)); + + # Temporary tables + if ($mystat{'Created_tmp_tables'} > 0) { + if ($mystat{'Created_tmp_disk_tables'} > 0) { + $mycalc{'pct_temp_disk'} = int(($mystat{'Created_tmp_disk_tables'} / ($mystat{'Created_tmp_tables'} + $mystat{'Created_tmp_disk_tables'})) * 100); + } else { + $mycalc{'pct_temp_disk'} = 0; + } + } + + # Table cache + if ($mystat{'Opened_tables'} > 0) { + $mycalc{'table_cache_hit_rate'} = int($mystat{'Open_tables'}*100/$mystat{'Opened_tables'}); + } else { + $mycalc{'table_cache_hit_rate'} = 100; + } + + # Open files + if ($myvar{'open_files_limit'} > 0) { + $mycalc{'pct_files_open'} = int($mystat{'Open_files'}*100/$myvar{'open_files_limit'}); + } + + # Table locks + if ($mystat{'Table_locks_immediate'} > 0) { + if ($mystat{'Table_locks_waited'} == 0) { + $mycalc{'pct_table_locks_immediate'} = 100; + } else { + $mycalc{'pct_table_locks_immediate'} = int($mystat{'Table_locks_immediate'}*100/($mystat{'Table_locks_waited'} + $mystat{'Table_locks_immediate'})); + } + } + + # Thread cache + $mycalc{'thread_cache_hit_rate'} = int(100 - (($mystat{'Threads_created'} / $mystat{'Connections'}) * 100)); + + # Other + if ($mystat{'Connections'} > 0) { + $mycalc{'pct_aborted_connections'} = int(($mystat{'Aborted_connects'}/$mystat{'Connections'}) * 100); + } + if ($mystat{'Questions'} > 0) { + $mycalc{'total_reads'} = $mystat{'Com_select'}; + $mycalc{'total_writes'} = $mystat{'Com_delete'} + $mystat{'Com_insert'} + $mystat{'Com_update'} + $mystat{'Com_replace'}; + if ($mycalc{'total_reads'} == 0) { + $mycalc{'pct_reads'} = 0; + $mycalc{'pct_writes'} = 100; + } else { + $mycalc{'pct_reads'} = int(($mycalc{'total_reads'}/($mycalc{'total_reads'}+$mycalc{'total_writes'})) * 100); + $mycalc{'pct_writes'} = 100-$mycalc{'pct_reads'}; + } + } + + # InnoDB + if ($myvar{'have_innodb'} eq "YES") { + $mycalc{'innodb_log_size_pct'} = ($myvar{'innodb_log_file_size'} * 100 / $myvar{'innodb_buffer_pool_size'}); + } +} + +sub mysql_stats { + print "\n-------- Performance Metrics -------------------------------------------------\n"; + # Show uptime, queries per second, connections, traffic stats + my $qps; + if ($mystat{'Uptime'} > 0) { $qps = sprintf("%.3f",$mystat{'Questions'}/$mystat{'Uptime'}); } + if ($mystat{'Uptime'} < 86400) { push(@generalrec,"MySQL started within last 24 hours - recommendations may be inaccurate"); } + infoprint "Up for: ".pretty_uptime($mystat{'Uptime'})." (".hr_num($mystat{'Questions'}). + " q [".hr_num($qps)." qps], ".hr_num($mystat{'Connections'})." conn,". + " TX: ".hr_num($mystat{'Bytes_sent'}).", RX: ".hr_num($mystat{'Bytes_received'}).")\n"; + infoprint "Reads / Writes: ".$mycalc{'pct_reads'}."% / ".$mycalc{'pct_writes'}."%\n"; + + # Memory usage + infoprint "Total buffers: ".hr_bytes($mycalc{'server_buffers'})." global + ".hr_bytes($mycalc{'per_thread_buffers'})." per thread ($myvar{'max_connections'} max threads)\n"; + if ($mycalc{'total_possible_used_memory'} > 2*1024*1024*1024 && $arch eq 32) { + badprint "Allocating > 2GB RAM on 32-bit systems can cause system instability\n"; + badprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n"; + } elsif ($mycalc{'pct_physical_memory'} > 85) { + badprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n"; + push(@generalrec,"Reduce your overall MySQL memory footprint for system stability"); + } else { + goodprint "Maximum possible memory usage: ".hr_bytes($mycalc{'total_possible_used_memory'})." ($mycalc{'pct_physical_memory'}% of installed RAM)\n"; + } + + # Slow queries + if ($mycalc{'pct_slow_queries'} > 5) { + badprint "Slow queries: $mycalc{'pct_slow_queries'}% (".hr_num($mystat{'Slow_queries'})."/".hr_num($mystat{'Questions'}).")\n"; + } else { + goodprint "Slow queries: $mycalc{'pct_slow_queries'}% (".hr_num($mystat{'Slow_queries'})."/".hr_num($mystat{'Questions'}).")\n"; + } + if ($myvar{'long_query_time'} > 10) { push(@adjvars,"long_query_time (<= 10)"); } + if (defined($myvar{'log_slow_queries'})) { + if ($myvar{'log_slow_queries'} eq "OFF") { push(@generalrec,"Enable the slow query log to troubleshoot bad queries"); } + } + + # Connections + if ($mycalc{'pct_connections_used'} > 85) { + badprint "Highest connection usage: $mycalc{'pct_connections_used'}% ($mystat{'Max_used_connections'}/$myvar{'max_connections'})\n"; + push(@adjvars,"max_connections (> ".$myvar{'max_connections'}.")"); + push(@adjvars,"wait_timeout (< ".$myvar{'wait_timeout'}.")","interactive_timeout (< ".$myvar{'interactive_timeout'}.")"); + push(@generalrec,"Reduce or eliminate persistent connections to reduce connection usage") + } else { + goodprint "Highest usage of available connections: $mycalc{'pct_connections_used'}% ($mystat{'Max_used_connections'}/$myvar{'max_connections'})\n"; + } + + # Key buffer + if (!defined($mycalc{'total_myisam_indexes'}) and $doremote == 1) { + push(@generalrec,"Unable to calculate MyISAM indexes on remote MySQL server < 5.0.0"); + } elsif ($mycalc{'total_myisam_indexes'} =~ /^fail$/) { + badprint "Cannot calculate MyISAM index size - re-run script as root user\n"; + } elsif ($mycalc{'total_myisam_indexes'} == "0") { + badprint "None of your MyISAM tables are indexed - add indexes immediately\n"; + } else { + if ($myvar{'key_buffer_size'} < $mycalc{'total_myisam_indexes'} && $mycalc{'pct_keys_from_mem'} < 95) { + badprint "Key buffer size / total MyISAM indexes: ".hr_bytes($myvar{'key_buffer_size'})."/".hr_bytes($mycalc{'total_myisam_indexes'})."\n"; + push(@adjvars,"key_buffer_size (> ".hr_bytes($mycalc{'total_myisam_indexes'}).")"); + } else { + goodprint "Key buffer size / total MyISAM indexes: ".hr_bytes($myvar{'key_buffer_size'})."/".hr_bytes($mycalc{'total_myisam_indexes'})."\n"; + } + if ($mystat{'Key_read_requests'} > 0) { + if ($mycalc{'pct_keys_from_mem'} < 95) { + badprint "Key buffer hit rate: $mycalc{'pct_keys_from_mem'}% (".hr_num($mystat{'Key_read_requests'})." cached / ".hr_num($mystat{'Key_reads'})." reads)\n"; + } else { + goodprint "Key buffer hit rate: $mycalc{'pct_keys_from_mem'}% (".hr_num($mystat{'Key_read_requests'})." cached / ".hr_num($mystat{'Key_reads'})." reads)\n"; + } + } else { + # No queries have run that would use keys + } + } + + # Query cache + if (!mysql_version_ge(4)) { + # MySQL versions < 4.01 don't support query caching + push(@generalrec,"Upgrade MySQL to version 4+ to utilize query caching"); + } elsif ($myvar{'query_cache_size'} < 1) { + badprint "Query cache is disabled\n"; + push(@adjvars,"query_cache_size (>= 8M)"); + } elsif ($mystat{'Com_select'} == 0) { + badprint "Query cache cannot be analyzed - no SELECT statements executed\n"; + } else { + if ($mycalc{'query_cache_efficiency'} < 20) { + badprint "Query cache efficiency: $mycalc{'query_cache_efficiency'}% (".hr_num($mystat{'Qcache_hits'})." cached / ".hr_num($mystat{'Qcache_hits'}+$mystat{'Com_select'})." selects)\n"; + push(@adjvars,"query_cache_limit (> ".hr_bytes_rnd($myvar{'query_cache_limit'}).", or use smaller result sets)"); + } else { + goodprint "Query cache efficiency: $mycalc{'query_cache_efficiency'}% (".hr_num($mystat{'Qcache_hits'})." cached / ".hr_num($mystat{'Qcache_hits'}+$mystat{'Com_select'})." selects)\n"; + } + if ($mycalc{'query_cache_prunes_per_day'} > 98) { + badprint "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}\n"; + if ($myvar{'query_cache_size'} > 128*1024*1024) { + push(@generalrec,"Increasing the query_cache size over 128M may reduce performance"); + push(@adjvars,"query_cache_size (> ".hr_bytes_rnd($myvar{'query_cache_size'}).") [see warning above]"); + } else { + push(@adjvars,"query_cache_size (> ".hr_bytes_rnd($myvar{'query_cache_size'}).")"); + } + } else { + goodprint "Query cache prunes per day: $mycalc{'query_cache_prunes_per_day'}\n"; + } + } + + # Sorting + if ($mycalc{'total_sorts'} == 0) { + # For the sake of space, we will be quiet here + # No sorts have run yet + } elsif ($mycalc{'pct_temp_sort_table'} > 10) { + badprint "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}% (".hr_num($mystat{'Sort_merge_passes'})." temp sorts / ".hr_num($mycalc{'total_sorts'})." sorts)\n"; + push(@adjvars,"sort_buffer_size (> ".hr_bytes_rnd($myvar{'sort_buffer_size'}).")"); + push(@adjvars,"read_rnd_buffer_size (> ".hr_bytes_rnd($myvar{'read_rnd_buffer_size'}).")"); + } else { + goodprint "Sorts requiring temporary tables: $mycalc{'pct_temp_sort_table'}% (".hr_num($mystat{'Sort_merge_passes'})." temp sorts / ".hr_num($mycalc{'total_sorts'})." sorts)\n"; + } + + # Joins + if ($mycalc{'joins_without_indexes_per_day'} > 250) { + badprint "Joins performed without indexes: $mycalc{'joins_without_indexes'}\n"; + push(@adjvars,"join_buffer_size (> ".hr_bytes($myvar{'join_buffer_size'}).", or always use indexes with joins)"); + push(@generalrec,"Adjust your join queries to always utilize indexes"); + } else { + # For the sake of space, we will be quiet here + # No joins have run without indexes + } + + # Temporary tables + if ($mystat{'Created_tmp_tables'} > 0) { + if ($mycalc{'pct_temp_disk'} > 25 && $mycalc{'max_tmp_table_size'} < 256*1024*1024) { + badprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% (".hr_num($mystat{'Created_tmp_disk_tables'})." on disk / ".hr_num($mystat{'Created_tmp_disk_tables'} + $mystat{'Created_tmp_tables'})." total)\n"; + push(@adjvars,"tmp_table_size (> ".hr_bytes_rnd($myvar{'tmp_table_size'}).")"); + push(@adjvars,"max_heap_table_size (> ".hr_bytes_rnd($myvar{'max_heap_table_size'}).")"); + push(@generalrec,"When making adjustments, make tmp_table_size/max_heap_table_size equal"); + push(@generalrec,"Reduce your SELECT DISTINCT queries without LIMIT clauses"); + } elsif ($mycalc{'pct_temp_disk'} > 25 && $mycalc{'max_tmp_table_size'} >= 256) { + badprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% (".hr_num($mystat{'Created_tmp_disk_tables'})." on disk / ".hr_num($mystat{'Created_tmp_disk_tables'} + $mystat{'Created_tmp_tables'})." total)\n"; + push(@generalrec,"Temporary table size is already large - reduce result set size"); + push(@generalrec,"Reduce your SELECT DISTINCT queries without LIMIT clauses"); + } else { + goodprint "Temporary tables created on disk: $mycalc{'pct_temp_disk'}% (".hr_num($mystat{'Created_tmp_disk_tables'})." on disk / ".hr_num($mystat{'Created_tmp_disk_tables'} + $mystat{'Created_tmp_tables'})." total)\n"; + } + } else { + # For the sake of space, we will be quiet here + # No temporary tables have been created + } + + # Thread cache + if ($myvar{'thread_cache_size'} eq 0) { + badprint "Thread cache is disabled\n"; + push(@generalrec,"Set thread_cache_size to 4 as a starting value"); + push(@adjvars,"thread_cache_size (start at 4)"); + } else { + if ($mycalc{'thread_cache_hit_rate'} <= 50) { + badprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}% (".hr_num($mystat{'Threads_created'})." created / ".hr_num($mystat{'Connections'})." connections)\n"; + push(@adjvars,"thread_cache_size (> $myvar{'thread_cache_size'})"); + } else { + goodprint "Thread cache hit rate: $mycalc{'thread_cache_hit_rate'}% (".hr_num($mystat{'Threads_created'})." created / ".hr_num($mystat{'Connections'})." connections)\n"; + } + } + + # Table cache + if ($mystat{'Open_tables'} > 0) { + if ($mycalc{'table_cache_hit_rate'} < 20) { + badprint "Table cache hit rate: $mycalc{'table_cache_hit_rate'}% (".hr_num($mystat{'Open_tables'})." open / ".hr_num($mystat{'Opened_tables'})." opened)\n"; + if (mysql_version_ge(5, 1)) { + push(@adjvars,"table_cache (> ".$myvar{'table_open_cache'}.")"); + } else { + push(@adjvars,"table_cache (> ".$myvar{'table_cache'}.")"); + } + push(@generalrec,"Increase table_cache gradually to avoid file descriptor limits"); + } else { + goodprint "Table cache hit rate: $mycalc{'table_cache_hit_rate'}% (".hr_num($mystat{'Open_tables'})." open / ".hr_num($mystat{'Opened_tables'})." opened)\n"; + } + } + + # Open files + if (defined $mycalc{'pct_files_open'}) { + if ($mycalc{'pct_files_open'} > 85) { + badprint "Open file limit used: $mycalc{'pct_files_open'}% (".hr_num($mystat{'Open_files'})."/".hr_num($myvar{'open_files_limit'}).")\n"; + push(@adjvars,"open_files_limit (> ".$myvar{'open_files_limit'}.")"); + } else { + goodprint "Open file limit used: $mycalc{'pct_files_open'}% (".hr_num($mystat{'Open_files'})."/".hr_num($myvar{'open_files_limit'}).")\n"; + } + } + + # Table locks + if (defined $mycalc{'pct_table_locks_immediate'}) { + if ($mycalc{'pct_table_locks_immediate'} < 95) { + badprint "Table locks acquired immediately: $mycalc{'pct_table_locks_immediate'}%\n"; + push(@generalrec,"Optimize queries and/or use InnoDB to reduce lock wait"); + } else { + goodprint "Table locks acquired immediately: $mycalc{'pct_table_locks_immediate'}% (".hr_num($mystat{'Table_locks_immediate'})." immediate / ".hr_num($mystat{'Table_locks_waited'}+$mystat{'Table_locks_immediate'})." locks)\n"; + } + } + + # Performance options + if (!mysql_version_ge(4, 1)) { + push(@generalrec,"Upgrade to MySQL 4.1+ to use concurrent MyISAM inserts"); + } elsif ($myvar{'concurrent_insert'} eq "OFF") { + push(@generalrec,"Enable concurrent_insert by setting it to 'ON'"); + } elsif ($myvar{'concurrent_insert'} eq 0) { + push(@generalrec,"Enable concurrent_insert by setting it to 1"); + } + if ($mycalc{'pct_aborted_connections'} > 5) { + badprint "Connections aborted: ".$mycalc{'pct_aborted_connections'}."%\n"; + push(@generalrec,"Your applications are not closing MySQL connections properly"); + } + + # InnoDB + if (defined $myvar{'have_innodb'} && $myvar{'have_innodb'} eq "YES" && defined $enginestats{'InnoDB'}) { + if ($myvar{'innodb_buffer_pool_size'} > $enginestats{'InnoDB'}) { + goodprint "InnoDB data size / buffer pool: ".hr_bytes($enginestats{'InnoDB'})."/".hr_bytes($myvar{'innodb_buffer_pool_size'})."\n"; + } else { + badprint "InnoDB data size / buffer pool: ".hr_bytes($enginestats{'InnoDB'})."/".hr_bytes($myvar{'innodb_buffer_pool_size'})."\n"; + push(@adjvars,"innodb_buffer_pool_size (>= ".hr_bytes_rnd($enginestats{'InnoDB'}).")"); + } + } +} + +# Take the two recommendation arrays and display them at the end of the output +sub make_recommendations { + print "\n-------- Recommendations -----------------------------------------------------\n"; + if (@generalrec > 0) { + print "General recommendations:\n"; + foreach (@generalrec) { print " ".$_."\n"; } + } + if (@adjvars > 0) { + print "Variables to adjust:\n"; + if ($mycalc{'pct_physical_memory'} > 90) { + print " *** MySQL's maximum memory usage is dangerously high ***\n". + " *** Add RAM before increasing MySQL buffer variables ***\n"; + } + foreach (@adjvars) { print " ".$_."\n"; } + } + if (@generalrec == 0 && @adjvars ==0) { + print "No additional performance recommendations are available.\n" + } + print "\n"; +} + +# --------------------------------------------------------------------------- +# BEGIN 'MAIN' +# --------------------------------------------------------------------------- +print "\n >> MySQLTuner $tunerversion - Major Hayden \n". + " >> Bug reports, feature requests, and downloads at http://mysqltuner.com/\n". + " >> Run with '--help' for additional options and output filtering\n"; +mysql_setup; # Gotta login first +os_setup; # Set up some OS variables +get_all_vars; # Toss variables/status into hashes +validate_tuner_version; # Check current MySQLTuner version +validate_mysql_version; # Check current MySQL version +check_architecture; # Suggest 64-bit upgrade +check_storage_engines; # Show enabled storage engines +security_recommendations; # Display some security recommendations +calculations; # Calculate everything we need +mysql_stats; # Print the server stats +make_recommendations; # Make recommendations based on stats +# --------------------------------------------------------------------------- +# END 'MAIN' +# --------------------------------------------------------------------------- + +# Local variables: +# indent-tabs-mode: t +# cperl-indent-level: 8 +# perl-indent-level: 8 +# End: diff --git a/deployment/modules/mysql/lib/puppet/parser/functions/mysql_deepmerge.rb b/deployment/modules/mysql/lib/puppet/parser/functions/mysql_deepmerge.rb new file mode 100644 index 000000000..dadad540c --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/parser/functions/mysql_deepmerge.rb @@ -0,0 +1,52 @@ +module Puppet::Parser::Functions + newfunction(:mysql_deepmerge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| + Recursively merges two or more hashes together and returns the resulting hash. + + For example: + + $hash1 = {'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } } + $hash2 = {'two' => 'dos', 'three' => { 'five' => 5 } } + $merged_hash = mysql_deepmerge($hash1, $hash2) + # The resulting hash is equivalent to: + # $merged_hash = { 'one' => 1, 'two' => 'dos', 'three' => { 'four' => 4, 'five' => 5 } } + + When there is a duplicate key that is a hash, they are recursively merged. + When there is a duplicate key that is not a hash, the key in the rightmost hash will "win." + + ENDHEREDOC + + if args.length < 2 + raise Puppet::ParseError, ("mysql_deepmerge(): wrong number of arguments (#{args.length}; must be at least 2)") + end + + result = Hash.new + args.each do |arg| + next if arg.is_a? String and arg.empty? # empty string is synonym for puppet's undef + # If the argument was not a hash, skip it. + unless arg.is_a?(Hash) + raise Puppet::ParseError, "mysql_deepmerge: unexpected argument type #{arg.class}, only expects hash arguments" + end + + # Now we have to traverse our hash assigning our non-hash values + # to the matching keys in our result while following our hash values + # and repeating the process. + overlay( result, arg ) + end + return( result ) + end +end + +def overlay( hash1, hash2 ) + hash2.each do |key, value| + if( value.is_a?(Hash) ) + if( ! hash1.has_key?( key ) or ! hash1[key].is_a?(Hash)) + hash1[key] = value + else + overlay( hash1[key], value ) + end + else + hash1[key] = value + end + end +end + diff --git a/deployment/modules/mysql/lib/puppet/parser/functions/mysql_password.rb b/deployment/modules/mysql/lib/puppet/parser/functions/mysql_password.rb new file mode 100644 index 000000000..f057a3139 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/parser/functions/mysql_password.rb @@ -0,0 +1,15 @@ +# hash a string as mysql's "PASSWORD()" function would do it +require 'digest/sha1' + +module Puppet::Parser::Functions + newfunction(:mysql_password, :type => :rvalue, :doc => <<-EOS + Returns the mysql password hash from the clear text password. + EOS + ) do |args| + + raise(Puppet::ParseError, 'mysql_password(): Wrong number of arguments ' + + "given (#{args.size} for 1)") if args.size != 1 + + '*' + Digest::SHA1.hexdigest(Digest::SHA1.digest(args[0])).upcase + end +end diff --git a/deployment/modules/mysql/lib/puppet/parser/functions/mysql_strip_hash.rb b/deployment/modules/mysql/lib/puppet/parser/functions/mysql_strip_hash.rb new file mode 100644 index 000000000..8e850d02a --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/parser/functions/mysql_strip_hash.rb @@ -0,0 +1,21 @@ +module Puppet::Parser::Functions + newfunction(:mysql_strip_hash, :type => :rvalue, :arity => 1, :doc => <<-EOS +TEMPORARY FUNCTION: EXPIRES 2014-03-10 +When given a hash this function strips out all blank entries. +EOS + ) do |args| + + hash = args[0] + unless hash.is_a?(Hash) + raise(Puppet::ParseError, 'mysql_strip_hash(): Requires hash to work with') + end + + # Filter out all the top level blanks. + hash.reject{|k,v| v == ''}.each do |k,v| + if v.is_a?(Hash) + v.reject!{|ki,vi| vi == '' } + end + end + + end +end diff --git a/deployment/modules/mysql/lib/puppet/provider/database/mysql.rb b/deployment/modules/mysql/lib/puppet/provider/database/mysql.rb new file mode 100644 index 000000000..2c9c93b89 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/provider/database/mysql.rb @@ -0,0 +1,52 @@ +Puppet::Type.type(:database).provide(:mysql) do + desc 'Manages MySQL database.' + + defaultfor :kernel => 'Linux' + + optional_commands :mysql => 'mysql' + optional_commands :mysqladmin => 'mysqladmin' + + def self.defaults_file + if File.file?("#{Facter.value(:root_home)}/.my.cnf") + "--defaults-extra-file=#{Facter.value(:root_home)}/.my.cnf" + else + nil + end + end + + def defaults_file + self.class.defaults_file + end + + def self.instances + mysql([defaults_file, '-NBe', 'show databases'].compact).split("\n").collect do |name| + new(:name => name) + end + end + + def create + mysql([defaults_file, '-NBe', "create database `#{@resource[:name]}` character set #{resource[:charset]}"].compact) + end + + def destroy + mysqladmin([defaults_file, '-f', 'drop', @resource[:name]].compact) + end + + def charset + mysql([defaults_file, '-NBe', "show create database `#{resource[:name]}`"].compact).match(/.*?(\S+)\s(?:COLLATE.*)?\*\//)[1] + end + + def charset=(value) + mysql([defaults_file, '-NBe', "alter database `#{resource[:name]}` CHARACTER SET #{value}"].compact) + end + + def exists? + begin + mysql([defaults_file, '-NBe', 'show databases'].compact).match(/^#{@resource[:name]}$/) + rescue => e + debug(e.message) + return nil + end + end + +end diff --git a/deployment/modules/mysql/lib/puppet/provider/database_grant/mysql.rb b/deployment/modules/mysql/lib/puppet/provider/database_grant/mysql.rb new file mode 100644 index 000000000..075dddc08 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/provider/database_grant/mysql.rb @@ -0,0 +1,210 @@ +# A grant is either global or per-db. This can be distinguished by the syntax +# of the name: +# user@host => global +# user@host/db => per-db + +Puppet::Type.type(:database_grant).provide(:mysql) do + + desc 'Uses mysql as database.' + + defaultfor :kernel => 'Linux' + + optional_commands :mysql => 'mysql' + optional_commands :mysqladmin => 'mysqladmin' + + def self.prefetch(resources) + @user_privs = query_user_privs + @db_privs = query_db_privs + end + + def self.user_privs + @user_privs || query_user_privs + end + + def self.db_privs + @db_privs || query_db_privs + end + + def user_privs + self.class.user_privs + end + + def db_privs + self.class.db_privs + end + + def self.query_user_privs + results = mysql([defaults_file, 'mysql', '-Be', 'describe user'].compact) + column_names = results.split(/\n/).map { |l| l.chomp.split(/\t/)[0] } + @user_privs = column_names.delete_if { |e| !( e =~/_priv$/) } + end + + def self.query_db_privs + results = mysql([defaults_file, 'mysql', '-Be', 'describe db'].compact) + column_names = results.split(/\n/).map { |l| l.chomp.split(/\t/)[0] } + @db_privs = column_names.delete_if { |e| !(e =~/_priv$/) } + end + + def mysql_flush + mysqladmin([defaults_file, 'flush-privileges'].compact) + end + + # this parses the + def split_name(string) + matches = /^([^@]*)@([^\/]*)(\/(.*))?$/.match(string).captures.compact + case matches.length + when 2 + { + :type => :user, + :user => matches[0], + :host => matches[1] + } + when 4 + { + :type => :db, + :user => matches[0], + :host => matches[1], + :db => matches[3] + } + end + end + + def create_row + unless @resource.should(:privileges).empty? + name = split_name(@resource[:name]) + case name[:type] + when :user + mysql([defaults_file, 'mysql', '-e', "INSERT INTO user (host, user) VALUES ('%s', '%s')" % [ + name[:host], name[:user], + ]].compact) + when :db + mysql([defaults_file, 'mysql', '-e', "INSERT INTO db (host, user, db) VALUES ('%s', '%s', '%s')" % [ + name[:host], name[:user], name[:db], + ]].compact) + end + mysql_flush + end + end + + def destroy + mysql([defaults_file, 'mysql', '-e', "REVOKE ALL ON '%s'.* FROM '%s@%s'" % [ @resource[:privileges], @resource[:database], @resource[:name], @resource[:host] ]].compact) + end + + def row_exists? + name = split_name(@resource[:name]) + fields = [:user, :host] + if name[:type] == :db + fields << :db + end + not mysql([defaults_file, 'mysql', '-NBe', "SELECT '1' FROM %s WHERE %s" % [ name[:type], fields.map do |f| "%s='%s'" % [f, name[f]] end.join(' AND ')]].compact).empty? + end + + def all_privs_set? + all_privs = case split_name(@resource[:name])[:type] + when :user + user_privs + when :db + db_privs + end + all_privs = all_privs.collect do |p| p.downcase end.sort.join('|') + privs = privileges.collect do |p| p.downcase end.sort.join('|') + + all_privs == privs + end + + def privileges + name = split_name(@resource[:name]) + privs = '' + + case name[:type] + when :user + privs = mysql([defaults_file, 'mysql', '-Be', "select * from mysql.user where user='%s' and host='%s'" % [ name[:user], name[:host] ]].compact) + when :db + privs = mysql([defaults_file, 'mysql', '-Be', "select * from mysql.db where user='%s' and host='%s' and db='%s'" % [ name[:user], name[:host], name[:db] ]].compact) + end + + if privs.match(/^$/) + privs = [] # no result, no privs + else + # returns a line with field names and a line with values, each tab-separated + privs = privs.split(/\n/).map! do |l| l.chomp.split(/\t/) end + # transpose the lines, so we have key/value pairs + privs = privs[0].zip(privs[1]) + privs = privs.select do |p| p[0].match(/_priv$/) and p[1] == 'Y' end + end + + privs.collect do |p| p[0] end + end + + def privileges=(privs) + unless row_exists? + create_row + end + + # puts "Setting privs: ", privs.join(", ") + name = split_name(@resource[:name]) + stmt = '' + where = '' + all_privs = [] + case name[:type] + when :user + stmt = 'update user set ' + where = " where user='%s' and host='%s'" % [ name[:user], name[:host] ] + all_privs = user_privs + when :db + stmt = 'update db set ' + where = " where user='%s' and host='%s' and db='%s'" % [ name[:user], name[:host], name[:db] ] + all_privs = db_privs + end + + if privs[0].downcase == 'all' + privs = all_privs + end + + # Downcase the requested priviliges for case-insensitive selection + # we don't map! here because the all_privs object has to remain in + # the same case the DB gave it to us in + privs = privs.map { |p| p.downcase } + + # puts "stmt:", stmt + set = all_privs.collect do |p| "%s = '%s'" % [p, privs.include?(p.downcase) ? 'Y' : 'N'] end.join(', ') + # puts "set:", set + stmt = stmt << set << where + + validate_privs privs, all_privs + mysql([defaults_file, 'mysql', '-Be', stmt].compact) + mysql_flush + end + + def validate_privs(set_privs, all_privs) + all_privs = all_privs.collect { |p| p.downcase } + set_privs = set_privs.collect { |p| p.downcase } + invalid_privs = Array.new + hints = Array.new + # Test each of the user provided privs to see if they exist in all_privs + set_privs.each do |priv| + invalid_privs << priv unless all_privs.include?(priv) + hints << "#{priv}_priv" if all_privs.include?("#{priv}_priv") + end + unless invalid_privs.empty? + # Print a decently helpful and gramatically correct error message + hints = "Did you mean '#{hints.join(',')}'?" unless hints.empty? + p = invalid_privs.size > 1 ? ['s', 'are not valid'] : ['', 'is not valid'] + detail = ["The privilege#{p[0]} '#{invalid_privs.join(',')}' #{p[1]}."] + fail [detail, hints].join(' ') + end + end + + # Optional defaults file + def self.defaults_file + if File.file?("#{Facter.value(:root_home)}/.my.cnf") + "--defaults-extra-file=#{Facter.value(:root_home)}/.my.cnf" + else + nil + end + end + def defaults_file + self.class.defaults_file + end + +end diff --git a/deployment/modules/mysql/lib/puppet/provider/database_user/mysql.rb b/deployment/modules/mysql/lib/puppet/provider/database_user/mysql.rb new file mode 100644 index 000000000..bb4781716 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/provider/database_user/mysql.rb @@ -0,0 +1,76 @@ +Puppet::Type.type(:database_user).provide(:mysql) do + + desc 'manage users for a mysql database.' + + defaultfor :kernel => 'Linux' + + commands :mysql => 'mysql' + commands :mysqladmin => 'mysqladmin' + + def self.instances + users = mysql([defaults_file, 'mysql', '-BNe' "select concat(User, '@',Host) as User from mysql.user"].compact).split("\n") + users.select{ |user| user =~ /.+@/ }.collect do |name| + new(:name => name) + end + end + + def create + merged_name = @resource[:name].sub('@', "'@'") + password_hash = @resource.value(:password_hash) + max_user_connections = @resource.value(:max_user_connections) || 0 + + mysql([defaults_file, 'mysql', '-e', "grant usage on *.* to '#{merged_name}' identified by PASSWORD + '#{password_hash}' with max_user_connections #{max_user_connections}"].compact) + + exists? ? (return true) : (return false) + end + + def destroy + merged_name = @resource[:name].sub('@', "'@'") + mysql([defaults_file, 'mysql', '-e', "drop user '#{merged_name}'"].compact) + + exists? ? (return false) : (return true) + end + + def password_hash + mysql([defaults_file, 'mysql', '-NBe', "select password from mysql.user where CONCAT(user, '@', host) = '#{@resource[:name]}'"].compact).chomp + end + + def password_hash=(string) + mysql([defaults_file, 'mysql', '-e', "SET PASSWORD FOR '%s' = '%s'" % [ @resource[:name].sub('@', "'@'"), string ] ].compact) + + password_hash == string ? (return true) : (return false) + end + + def max_user_connections + mysql([defaults_file, "mysql", "-NBe", "select max_user_connections from mysql.user where CONCAT(user, '@', host) = '#{@resource[:name]}'"].compact).chomp + end + + def max_user_connections=(int) + mysql([defaults_file, "mysql", "-e", "grant usage on *.* to '%s' with max_user_connections #{int}" % [ @resource[:name].sub("@", "'@'")] ].compact).chomp + + max_user_connections == int ? (return true) : (return false) + end + + def exists? + not mysql([defaults_file, 'mysql', '-NBe', "select '1' from mysql.user where CONCAT(user, '@', host) = '%s'" % @resource.value(:name)].compact).empty? + end + + def flush + @property_hash.clear + mysqladmin([defaults_file, 'flush-privileges'].compact) + end + + # Optional defaults file + def self.defaults_file + if File.file?("#{Facter.value(:root_home)}/.my.cnf") + "--defaults-extra-file=#{Facter.value(:root_home)}/.my.cnf" + else + nil + end + end + def defaults_file + self.class.defaults_file + end + +end diff --git a/deployment/modules/mysql/lib/puppet/provider/mysql.rb b/deployment/modules/mysql/lib/puppet/provider/mysql.rb new file mode 100644 index 000000000..fb9e406b7 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/provider/mysql.rb @@ -0,0 +1,67 @@ +class Puppet::Provider::Mysql < Puppet::Provider + + # Without initvars commands won't work. + initvars + commands :mysql => 'mysql' + commands :mysqladmin => 'mysqladmin' + + # Optional defaults file + def self.defaults_file + if File.file?("#{Facter.value(:root_home)}/.my.cnf") + "--defaults-extra-file=#{Facter.value(:root_home)}/.my.cnf" + else + nil + end + end + + def defaults_file + self.class.defaults_file + end + + def self.users + mysql([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"].compact).split("\n") + end + + # Take root@localhost and munge it to 'root'@'localhost' + def self.cmd_user(user) + "'#{user.sub('@', "'@'")}'" + end + + # Take root.* and return ON `root`.* + def self.cmd_table(table) + table_string = '' + + # We can't escape *.* so special case this. + if table == '*.*' + table_string << '*.*' + else + table_string << table.sub(/^(.*)(\..*)/, '`\1`\2') + end + table_string + end + + def self.cmd_privs(privileges) + if privileges.include?('ALL') + return 'ALL PRIVILEGES' + else + priv_string = '' + privileges.each do |priv| + priv_string << "#{priv}, " + end + end + # Remove trailing , from the last element. + priv_string.sub(/, $/, '') + end + + # Take in potential options and build up a query string with them. + def self.cmd_options(options) + option_string = '' + options.each do |opt| + if opt == 'GRANT' + option_string << ' WITH GRANT OPTION' + end + end + option_string + end + +end diff --git a/deployment/modules/mysql/lib/puppet/provider/mysql_database/mysql.rb b/deployment/modules/mysql/lib/puppet/provider/mysql_database/mysql.rb new file mode 100644 index 000000000..ef95819fe --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/provider/mysql_database/mysql.rb @@ -0,0 +1,68 @@ +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'mysql')) +Puppet::Type.type(:mysql_database).provide(:mysql, :parent => Puppet::Provider::Mysql) do + desc 'Manages MySQL databases.' + + commands :mysql => 'mysql' + + def self.instances + mysql([defaults_file, '-NBe', 'show databases'].compact).split("\n").collect do |name| + attributes = {} + mysql([defaults_file, '-NBe', 'show variables like "%_database"', name].compact).split("\n").each do |line| + k,v = line.split(/\s/) + attributes[k] = v + end + new(:name => name, + :ensure => :present, + :charset => attributes['character_set_database'], + :collate => attributes['collation_database'] + ) + end + end + + # We iterate over each mysql_database entry in the catalog and compare it against + # the contents of the property_hash generated by self.instances + def self.prefetch(resources) + databases = instances + resources.keys.each do |database| + if provider = databases.find { |db| db.name == database } + resources[database].provider = provider + end + end + end + + def create + mysql([defaults_file, '-NBe', "create database `#{@resource[:name]}` character set #{@resource[:charset]} collate #{@resource[:collate]}"].compact) + + @property_hash[:ensure] = :present + @property_hash[:charset] = @resource[:charset] + @property_hash[:collate] = @resource[:collate] + + exists? ? (return true) : (return false) + end + + def destroy + mysql([defaults_file, '-NBe', "drop database `#{@resource[:name]}`"].compact) + + @property_hash.clear + exists? ? (return false) : (return true) + end + + def exists? + @property_hash[:ensure] == :present || false + end + + mk_resource_methods + + def charset=(value) + mysql([defaults_file, '-NBe', "alter database `#{resource[:name]}` CHARACTER SET #{value}"].compact) + @property_hash[:charset] = value + charset == value ? (return true) : (return false) + end + + def collate=(value) + mysql([defaults_file, '-NBe', "alter database `#{resource[:name]}` COLLATE #{value}"].compact) + @property_hash[:collate] = value + collate == value ? (return true) : (return false) + end + +end diff --git a/deployment/modules/mysql/lib/puppet/provider/mysql_grant/mysql.rb b/deployment/modules/mysql/lib/puppet/provider/mysql_grant/mysql.rb new file mode 100644 index 000000000..c63321618 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/provider/mysql_grant/mysql.rb @@ -0,0 +1,115 @@ +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'mysql')) +Puppet::Type.type(:mysql_grant).provide(:mysql, :parent => Puppet::Provider::Mysql) do + + desc 'Set grants for users in MySQL.' + + def self.instances + instances = [] + users.select{ |user| user =~ /.+@/ }.collect do |user| + user_string = self.cmd_user(user) + query = "SHOW GRANTS FOR #{user_string};" + grants = mysql([defaults_file, "-NBe", query].compact) + # Once we have the list of grants generate entries for each. + grants.each_line do |grant| + # Match the munges we do in the type. + munged_grant = grant.delete("'").delete("`") + # Matching: GRANT (SELECT, UPDATE) PRIVILEGES ON (*.*) TO ('root')@('127.0.0.1') (WITH GRANT OPTION) + if match = munged_grant.match(/^GRANT\s(.+)\sON\s(.+)\sTO\s(.*)@(.*?)(\s.*)$/) + privileges, table, user, host, rest = match.captures + # Once we split privileges up on the , we need to make sure we + # shortern ALL PRIVILEGES to just all. + stripped_privileges = privileges.split(',').map do |priv| + priv == 'ALL PRIVILEGES' ? 'ALL' : priv.lstrip.rstrip + end + # Same here, but to remove OPTION leaving just GRANT. + options = rest.match(/WITH\s(.*)\sOPTION$/).captures if rest.include?('WITH') + # We need to return an array of instances so capture these + instances << new( + :name => "#{user}@#{host}/#{table}", + :ensure => :present, + :privileges => stripped_privileges.sort, + :table => table, + :user => "#{user}@#{host}", + :options => options + ) + end + end + end + return instances + end + + def self.prefetch(resources) + users = instances + resources.keys.each do |name| + if provider = users.find { |user| user.name == name } + resources[name].provider = provider + end + end + end + + def grant(user, table, privileges, options) + user_string = self.class.cmd_user(user) + priv_string = self.class.cmd_privs(privileges) + table_string = self.class.cmd_table(table) + query = "GRANT #{priv_string}" + query << " ON #{table_string}" + query << " TO #{user_string}" + query << self.class.cmd_options(options) unless options.nil? + mysql([defaults_file, '-e', query].compact) + end + + def create + grant(@resource[:user], @resource[:table], @resource[:privileges], @resource[:options]) + + @property_hash[:ensure] = :present + @property_hash[:table] = @resource[:table] + @property_hash[:user] = @resource[:user] + @property_hash[:options] = @resource[:options] if @resource[:options] + @property_hash[:privileges] = @resource[:privileges] + + exists? ? (return true) : (return false) + end + + def revoke(user, table) + user_string = self.class.cmd_user(user) + table_string = self.class.cmd_table(table) + + query = "REVOKE ALL ON #{table_string} FROM #{user_string}" + mysql([defaults_file, '-e', query].compact) + end + + def destroy + revoke(@property_hash[:user], @property_hash[:table]) + @property_hash.clear + + exists? ? (return false) : (return true) + end + + def exists? + @property_hash[:ensure] == :present || false + end + + def flush + @property_hash.clear + mysql([defaults_file, '-NBe', 'FLUSH PRIVILEGES'].compact) + end + + mk_resource_methods + + def privileges=(privileges) + revoke(@property_hash[:user], @property_hash[:table]) + grant(@property_hash[:user], @property_hash[:table], privileges, @property_hash[:options]) + @property_hash[:privileges] = privileges + + self.privileges + end + + def options=(options) + revoke(@property_hash[:user], @property_hash[:table]) + grant(@property_hash[:user], @property_hash[:table], @property_hash[:privileges], options) + @property_hash[:options] = options + + self.options + end + +end diff --git a/deployment/modules/mysql/lib/puppet/provider/mysql_user/mysql.rb b/deployment/modules/mysql/lib/puppet/provider/mysql_user/mysql.rb new file mode 100644 index 000000000..7bf451368 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/provider/mysql_user/mysql.rb @@ -0,0 +1,115 @@ +require File.expand_path(File.join(File.dirname(__FILE__), '..', 'mysql')) +Puppet::Type.type(:mysql_user).provide(:mysql, :parent => Puppet::Provider::Mysql) do + + desc 'manage users for a mysql database.' + commands :mysql => 'mysql' + + # Build a property_hash containing all the discovered information about MySQL + # users. + def self.instances + users = mysql([defaults_file, '-NBe', + "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"].compact).split("\n") + # To reduce the number of calls to MySQL we collect all the properties in + # one big swoop. + users.collect do |name| + query = "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, PASSWORD FROM mysql.user WHERE CONCAT(user, '@', host) = '#{name}'" + @max_user_connections, @max_connections_per_hour, @max_queries_per_hour, + @max_updates_per_hour, @password = mysql([defaults_file, "-NBe", query].compact).split(/\s/) + + new(:name => name, + :ensure => :present, + :password_hash => @password, + :max_user_connections => @max_user_connections, + :max_connections_per_hour => @max_connections_per_hour, + :max_queries_per_hour => @max_queries_per_hour, + :max_updates_per_hour => @max_updates_per_hour + ) + end + end + + # We iterate over each mysql_user entry in the catalog and compare it against + # the contents of the property_hash generated by self.instances + def self.prefetch(resources) + users = instances + resources.keys.each do |name| + if provider = users.find { |user| user.name == name } + resources[name].provider = provider + end + end + end + + def create + merged_name = @resource[:name].sub('@', "'@'") + password_hash = @resource.value(:password_hash) + max_user_connections = @resource.value(:max_user_connections) || 0 + max_connections_per_hour = @resource.value(:max_connections_per_hour) || 0 + max_queries_per_hour = @resource.value(:max_queries_per_hour) || 0 + max_updates_per_hour = @resource.value(:max_updates_per_hour) || 0 + + mysql([defaults_file, '-e', "GRANT USAGE ON *.* TO '#{merged_name}' IDENTIFIED BY PASSWORD '#{password_hash}' WITH MAX_USER_CONNECTIONS #{max_user_connections} MAX_CONNECTIONS_PER_HOUR #{max_connections_per_hour} MAX_QUERIES_PER_HOUR #{max_queries_per_hour} MAX_UPDATES_PER_HOUR #{max_updates_per_hour}"].compact) + + @property_hash[:ensure] = :present + @property_hash[:password_hash] = password_hash + @property_hash[:max_user_connections] = max_user_connections + @property_hash[:max_connections_per_hour] = max_connections_per_hour + @property_hash[:max_queries_per_hour] = max_queries_per_hour + @property_hash[:max_updates_per_hour] = max_updates_per_hour + + exists? ? (return true) : (return false) + end + + def destroy + merged_name = @resource[:name].sub('@', "'@'") + mysql([defaults_file, '-e', "DROP USER '#{merged_name}'"].compact) + + @property_hash.clear + exists? ? (return false) : (return true) + end + + def exists? + @property_hash[:ensure] == :present || false + end + + ## + ## MySQL user properties + ## + + # Generates method for all properties of the property_hash + mk_resource_methods + + def password_hash=(string) + merged_name = @resource[:name].sub('@', "'@'") + mysql([defaults_file, '-e', "SET PASSWORD FOR '#{merged_name}' = '#{string}'"].compact) + + password_hash == string ? (return true) : (return false) + end + + def max_user_connections=(int) + merged_name = @resource[:name].sub('@', "'@'") + mysql([defaults_file, '-e', "GRANT USAGE ON *.* TO '#{merged_name}' WITH MAX_USER_CONNECTIONS #{int}"].compact).chomp + + max_user_connections == int ? (return true) : (return false) + end + + def max_connections_per_hour=(int) + merged_name = @resource[:name].sub('@', "'@'") + mysql([defaults_file, '-e', "GRANT USAGE ON *.* TO '#{merged_name}' WITH MAX_CONNECTIONS_PER_HOUR #{int}"].compact).chomp + + max_connections_per_hour == int ? (return true) : (return false) + end + + def max_queries_per_hour=(int) + merged_name = @resource[:name].sub('@', "'@'") + mysql([defaults_file, '-e', "GRANT USAGE ON *.* TO '#{merged_name}' WITH MAX_QUERIES_PER_HOUR #{int}"].compact).chomp + + max_queries_per_hour == int ? (return true) : (return false) + end + + def max_updates_per_hour=(int) + merged_name = @resource[:name].sub('@', "'@'") + mysql([defaults_file, '-e', "GRANT USAGE ON *.* TO '#{merged_name}' WITH MAX_UPDATES_PER_HOUR #{int}"].compact).chomp + + max_updates_per_hour == int ? (return true) : (return false) + end + +end diff --git a/deployment/modules/mysql/lib/puppet/type/database.rb b/deployment/modules/mysql/lib/puppet/type/database.rb new file mode 100644 index 000000000..b02fb1099 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/type/database.rb @@ -0,0 +1,21 @@ +# This has to be a separate type to enable collecting +Puppet::Type.newtype(:database) do + @doc = 'Manage databases.' + + ensurable + + newparam(:name, :namevar=>true) do + desc 'The name of the database.' + validate do |value| + Puppet.warning("database has been deprecated in favor of mysql_database.") + true + end + end + + newproperty(:charset) do + desc 'The characterset to use for a database' + defaultto :utf8 + newvalue(/^\S+$/) + end + +end diff --git a/deployment/modules/mysql/lib/puppet/type/database_grant.rb b/deployment/modules/mysql/lib/puppet/type/database_grant.rb new file mode 100644 index 000000000..7fdad8231 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/type/database_grant.rb @@ -0,0 +1,79 @@ +# This has to be a separate type to enable collecting +Puppet::Type.newtype(:database_grant) do + @doc = "Manage a database user's rights." + #ensurable + + autorequire :database do + # puts "Starting db autoreq for %s" % self[:name] + reqs = [] + matches = self[:name].match(/^([^@]+)@([^\/]+)\/(.+)$/) + unless matches.nil? + reqs << matches[3] + end + # puts "Autoreq: '%s'" % reqs.join(" ") + reqs + end + + autorequire :database_user do + # puts "Starting user autoreq for %s" % self[:name] + reqs = [] + matches = self[:name].match(/^([^@]+)@([^\/]+).*$/) + unless matches.nil? + reqs << '%s@%s' % [ matches[1], matches[2] ] + end + # puts "Autoreq: '%s'" % reqs.join(" ") + reqs + end + + newparam(:name, :namevar=>true) do + desc 'The primary key: either user@host for global privilges or user@host/database for database specific privileges' + validate do |value| + Puppet.warning("database_grant has been deprecated in favor of mysql_grant.") + true + end + end + + newproperty(:privileges, :array_matching => :all) do + desc 'The privileges the user should have. The possible values are implementation dependent.' + + def should_to_s(newvalue = @should) + if newvalue + unless newvalue.is_a?(Array) + newvalue = [ newvalue ] + end + newvalue.collect do |v| v.downcase end.sort.join ', ' + else + nil + end + end + + def is_to_s(currentvalue = @is) + if currentvalue + unless currentvalue.is_a?(Array) + currentvalue = [ currentvalue ] + end + currentvalue.collect do |v| v.downcase end.sort.join ', ' + else + nil + end + end + + # use the sorted outputs for comparison + def insync?(is) + if defined? @should and @should + case self.should_to_s + when 'all' + self.provider.all_privs_set? + when self.is_to_s(is) + true + else + false + end + else + true + end + end + end + +end + diff --git a/deployment/modules/mysql/lib/puppet/type/database_user.rb b/deployment/modules/mysql/lib/puppet/type/database_user.rb new file mode 100644 index 000000000..9a9d5fbc7 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/type/database_user.rb @@ -0,0 +1,31 @@ +# This has to be a separate type to enable collecting +Puppet::Type.newtype(:database_user) do + @doc = 'Manage a database user. This includes management of users password as well as privileges' + + ensurable + + newparam(:name, :namevar=>true) do + desc "The name of the user. This uses the 'username@hostname' or username@hostname." + validate do |value| + Puppet.warning("database has been deprecated in favor of mysql_user.") + # https://dev.mysql.com/doc/refman/5.1/en/account-names.html + # Regex should problably be more like this: /^[`'"]?[^`'"]*[`'"]?@[`'"]?[\w%\.]+[`'"]?$/ + raise(ArgumentError, "Invalid database user #{value}") unless value =~ /[\w-]*@[\w%\.:]+/ + username = value.split('@')[0] + if username.size > 16 + raise ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters' + end + end + end + + newproperty(:password_hash) do + desc 'The password hash of the user. Use mysql_password() for creating such a hash.' + newvalue(/\w+/) + end + + newproperty(:max_user_connections) do + desc "Max concurrent connections for the user. 0 means no (or global) limit." + newvalue(/\d+/) + end + +end diff --git a/deployment/modules/mysql/lib/puppet/type/mysql_database.rb b/deployment/modules/mysql/lib/puppet/type/mysql_database.rb new file mode 100644 index 000000000..3e8518c96 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/type/mysql_database.rb @@ -0,0 +1,22 @@ +Puppet::Type.newtype(:mysql_database) do + @doc = 'Manage MySQL databases.' + + ensurable + + newparam(:name, :namevar => true) do + desc 'The name of the MySQL database to manage.' + end + + newproperty(:charset) do + desc 'The CHARACTER SET setting for the database' + defaultto :utf8 + newvalue(/^\S+$/) + end + + newproperty(:collate) do + desc 'The COLLATE setting for the database' + defaultto :utf8_general_ci + newvalue(/^\S+$/) + end + +end diff --git a/deployment/modules/mysql/lib/puppet/type/mysql_grant.rb b/deployment/modules/mysql/lib/puppet/type/mysql_grant.rb new file mode 100644 index 000000000..e6fb75de7 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/type/mysql_grant.rb @@ -0,0 +1,72 @@ +# This has to be a separate type to enable collecting +Puppet::Type.newtype(:mysql_grant) do + @doc = "Manage a MySQL user's rights." + ensurable + + autorequire(:file) { '/root/.my.cnf' } + + def initialize(*args) + super + # Forcibly munge any privilege with 'ALL' in the array to exist of just + # 'ALL'. This can't be done in the munge in the property as that iterates + # over the array and there's no way to replace the entire array before it's + # returned to the provider. + if self[:ensure] == :present and Array(self[:privileges]).count > 1 and self[:privileges].to_s.include?('ALL') + self[:privileges] = 'ALL' + end + # Sort the privileges array in order to ensure the comparision in the provider + # self.instances method match. Otherwise this causes it to keep resetting the + # privileges. + self[:privileges] = Array(self[:privileges]).sort! + end + + validate do + fail('privileges parameter is required.') if self[:ensure] == :present and self[:privileges].nil? + fail('table parameter is required.') if self[:ensure] == :present and self[:table].nil? + fail('user parameter is required.') if self[:ensure] == :present and self[:user].nil? + end + + newparam(:name, :namevar => true) do + desc 'Name to describe the grant.' + + munge do |value| + value.delete("'") + end + end + + newproperty(:privileges, :array_matching => :all) do + desc 'Privileges for user' + + munge do |value| + value.upcase + end + end + + newproperty(:table) do + desc 'Table to apply privileges to.' + + munge do |value| + value.delete("`") + end + + newvalues(/.*\..*/) + end + + newproperty(:user) do + desc 'User to operate on.' + validate do |value| + # https://dev.mysql.com/doc/refman/5.1/en/account-names.html + # Regex should problably be more like this: /^[`'"]?[^`'"]*[`'"]?@[`'"]?[\w%\.]+[`'"]?$/ + raise(ArgumentError, "Invalid user #{value}") unless value =~ /[\w-]*@[\w%\.:]+/ + username = value.split('@')[0] + if username.size > 16 + raise ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters' + end + end + end + + newproperty(:options, :array_matching => :all) do + desc 'Options to grant.' + end + +end diff --git a/deployment/modules/mysql/lib/puppet/type/mysql_user.rb b/deployment/modules/mysql/lib/puppet/type/mysql_user.rb new file mode 100644 index 000000000..38564a948 --- /dev/null +++ b/deployment/modules/mysql/lib/puppet/type/mysql_user.rb @@ -0,0 +1,45 @@ +# This has to be a separate type to enable collecting +Puppet::Type.newtype(:mysql_user) do + @doc = 'Manage a MySQL user. This includes management of users password as well as privileges.' + + ensurable + + newparam(:name, :namevar => true) do + desc "The name of the user. This uses the 'username@hostname' or username@hostname." + validate do |value| + # https://dev.mysql.com/doc/refman/5.1/en/account-names.html + # Regex should problably be more like this: /^[`'"]?[^`'"]*[`'"]?@[`'"]?[\w%\.]+[`'"]?$/ + raise(ArgumentError, "Invalid database user #{value}") unless value =~ /[\w-]*@[\w%\.:]+/ + username = value.split('@')[0] + if username.size > 16 + raise ArgumentError, 'MySQL usernames are limited to a maximum of 16 characters' + end + end + end + + newproperty(:password_hash) do + desc 'The password hash of the user. Use mysql_password() for creating such a hash.' + newvalue(/\w+/) + end + + newproperty(:max_user_connections) do + desc "Max concurrent connections for the user. 0 means no (or global) limit." + newvalue(/\d+/) + end + + newproperty(:max_connections_per_hour) do + desc "Max connections per hour for the user. 0 means no (or global) limit." + newvalue(/\d+/) + end + + newproperty(:max_queries_per_hour) do + desc "Max queries per hour for the user. 0 means no (or global) limit." + newvalue(/\d+/) + end + + newproperty(:max_updates_per_hour) do + desc "Max updates per hour for the user. 0 means no (or global) limit." + newvalue(/\d+/) + end + +end diff --git a/deployment/modules/mysql/manifests/backup.pp b/deployment/modules/mysql/manifests/backup.pp new file mode 100644 index 000000000..680a5744d --- /dev/null +++ b/deployment/modules/mysql/manifests/backup.pp @@ -0,0 +1,31 @@ +# Deprecated class +class mysql::backup ( + $backupuser, + $backuppassword, + $backupdir, + $backupcompress = true, + $backuprotate = 30, + $delete_before_dump = false, + $backupdatabases = [], + $file_per_database = false, + $ensure = 'present', + $time = ['23', '5'], +) { + + crit("This class has been deprecated and callers should directly call + mysql::server::backup now.") + + class { 'mysql::server::backup': + ensure => $ensure, + backupuser => $backupuser, + backuppassword => $backuppassword, + backupdir => $backupdir, + backupcompress => $backupcompress, + backuprotate => $backuprotate, + delete_before_dump => $delete_before_dump, + backupdatabases => $backupdatabases, + file_per_database => $file_per_database, + time => $time, + } + +} diff --git a/deployment/modules/mysql/manifests/bindings.pp b/deployment/modules/mysql/manifests/bindings.pp new file mode 100644 index 000000000..88c490339 --- /dev/null +++ b/deployment/modules/mysql/manifests/bindings.pp @@ -0,0 +1,33 @@ +# See README.md. +class mysql::bindings ( + # Boolean to determine if we should include the classes. + $java_enable = false, + $perl_enable = false, + $php_enable = false, + $python_enable = false, + $ruby_enable = false, + # Settings for the various classes. + $java_package_ensure = $mysql::params::java_package_ensure, + $java_package_name = $mysql::params::java_package_name, + $java_package_provider = $mysql::params::java_package_provider, + $perl_package_ensure = $mysql::params::perl_package_ensure, + $perl_package_name = $mysql::params::perl_package_name, + $perl_package_provider = $mysql::params::perl_package_provider, + $php_package_ensure = $mysql::params::php_package_ensure, + $php_package_name = $mysql::params::php_package_name, + $php_package_provider = $mysql::params::php_package_provider, + $python_package_ensure = $mysql::params::python_package_ensure, + $python_package_name = $mysql::params::python_package_name, + $python_package_provider = $mysql::params::python_package_provider, + $ruby_package_ensure = $mysql::params::ruby_package_ensure, + $ruby_package_name = $mysql::params::ruby_package_name, + $ruby_package_provider = $mysql::params::ruby_package_provider +) inherits mysql::params { + + if $java_enable { include '::mysql::bindings::java' } + if $perl_enable { include '::mysql::bindings::perl' } + if $php_enable { include '::mysql::bindings::php' } + if $python_enable { include '::mysql::bindings::python' } + if $ruby_enable { include '::mysql::bindings::ruby' } + +} diff --git a/deployment/modules/mysql/manifests/bindings/java.pp b/deployment/modules/mysql/manifests/bindings/java.pp new file mode 100644 index 000000000..d08083733 --- /dev/null +++ b/deployment/modules/mysql/manifests/bindings/java.pp @@ -0,0 +1,10 @@ +# Private class +class mysql::bindings::java { + + package { 'mysql-connector-java': + ensure => $mysql::bindings::java_package_ensure, + name => $mysql::bindings::java_package_name, + provider => $mysql::bindings::java_package_provider, + } + +} diff --git a/deployment/modules/mysql/manifests/bindings/perl.pp b/deployment/modules/mysql/manifests/bindings/perl.pp new file mode 100644 index 000000000..58c76f4b3 --- /dev/null +++ b/deployment/modules/mysql/manifests/bindings/perl.pp @@ -0,0 +1,10 @@ +# Private class +class mysql::bindings::perl { + + package{ 'perl_mysql': + ensure => $mysql::bindings::perl_package_ensure, + name => $mysql::bindings::perl_package_name, + provider => $mysql::bindings::perl_package_provider, + } + +} diff --git a/deployment/modules/mysql/manifests/bindings/php.pp b/deployment/modules/mysql/manifests/bindings/php.pp new file mode 100644 index 000000000..81d08d3aa --- /dev/null +++ b/deployment/modules/mysql/manifests/bindings/php.pp @@ -0,0 +1,10 @@ +# Private class: See README.md +class mysql::bindings::php { + + package { 'php-mysql': + ensure => $mysql::bindings::php_package_ensure, + name => $mysql::bindings::php_package_name, + provider => $mysql::bindings::php_package_provider, + } + +} diff --git a/deployment/modules/mysql/manifests/bindings/python.pp b/deployment/modules/mysql/manifests/bindings/python.pp new file mode 100644 index 000000000..96a3882b3 --- /dev/null +++ b/deployment/modules/mysql/manifests/bindings/python.pp @@ -0,0 +1,10 @@ +# Private class +class mysql::bindings::python { + + package { 'python-mysqldb': + ensure => $mysql::bindings::python_package_ensure, + name => $mysql::bindings::python_package_name, + provider => $mysql::bindings::python_package_provider, + } + +} diff --git a/deployment/modules/mysql/manifests/bindings/ruby.pp b/deployment/modules/mysql/manifests/bindings/ruby.pp new file mode 100644 index 000000000..f916f54c2 --- /dev/null +++ b/deployment/modules/mysql/manifests/bindings/ruby.pp @@ -0,0 +1,10 @@ +# Private class +class mysql::bindings::ruby { + + package{ 'ruby_mysql': + ensure => $mysql::bindings::ruby_package_ensure, + name => $mysql::bindings::ruby_package_name, + provider => $mysql::bindings::ruby_package_provider, + } + +} diff --git a/deployment/modules/mysql/manifests/client.pp b/deployment/modules/mysql/manifests/client.pp new file mode 100644 index 000000000..59487f700 --- /dev/null +++ b/deployment/modules/mysql/manifests/client.pp @@ -0,0 +1,27 @@ +# +class mysql::client ( + $bindings_enable = $mysql::params::bindings_enable, + $package_ensure = $mysql::params::client_package_ensure, + $package_name = $mysql::params::client_package_name, +) inherits mysql::params { + + include '::mysql::client::install' + + if $bindings_enable { + class { 'mysql::bindings': + java_enable => true, + perl_enable => true, + php_enable => true, + python_enable => true, + ruby_enable => true, + } + } + + + # Anchor pattern workaround to avoid resources of mysql::client::install to + # "float off" outside mysql::client + anchor { 'mysql::client::start': } -> + Class['mysql::client::install'] -> + anchor { 'mysql::client::end': } + +} diff --git a/deployment/modules/mysql/manifests/client/install.pp b/deployment/modules/mysql/manifests/client/install.pp new file mode 100644 index 000000000..a443f5320 --- /dev/null +++ b/deployment/modules/mysql/manifests/client/install.pp @@ -0,0 +1,8 @@ +class mysql::client::install { + + package { 'mysql_client': + ensure => $mysql::client::package_ensure, + name => $mysql::client::package_name, + } + +} diff --git a/deployment/modules/mysql/manifests/db.pp b/deployment/modules/mysql/manifests/db.pp new file mode 100644 index 000000000..d406a07d5 --- /dev/null +++ b/deployment/modules/mysql/manifests/db.pp @@ -0,0 +1,59 @@ +# See README.md for details. +define mysql::db ( + $user, + $password, + $charset = 'utf8', + $collate = 'utf8_general_ci', + $host = 'localhost', + $grant = 'ALL', + $sql = '', + $enforce_sql = false, + $ensure = 'present' +) { + #input validation + validate_re($ensure, '^(present|absent)$', + "${ensure} is not supported for ensure. Allowed values are 'present' and 'absent'.") + $table = "${name}.*" + + include '::mysql::client' + + mysql_database { $name: + ensure => $ensure, + charset => $charset, + collate => $collate, + provider => 'mysql', + require => [ Class['mysql::server'], Class['mysql::client'] ], + before => Mysql_user["${user}@${host}"], + } + + $user_resource = { + ensure => $ensure, + password_hash => mysql_password($password), + provider => 'mysql', + require => Class['mysql::server'], + } + ensure_resource('mysql_user', "${user}@${host}", $user_resource) + + if $ensure == 'present' { + mysql_grant { "${user}@${host}/${table}": + privileges => $grant, + provider => 'mysql', + user => "${user}@${host}", + table => $table, + require => [ Mysql_user["${user}@${host}"], Class['mysql::server'] ], + } + + $refresh = ! $enforce_sql + + if $sql { + exec{ "${name}-import": + command => "/usr/bin/mysql ${name} < ${sql}", + logoutput => true, + environment => "HOME=${::root_home}", + refreshonly => $refresh, + require => Mysql_grant["${user}@${host}/${table}"], + subscribe => Mysql_database[$name], + } + } + } +} diff --git a/deployment/modules/mysql/manifests/init.pp b/deployment/modules/mysql/manifests/init.pp new file mode 100644 index 000000000..eba5c2063 --- /dev/null +++ b/deployment/modules/mysql/manifests/init.pp @@ -0,0 +1,100 @@ +# +class mysql( + $basedir = '', + $bind_address = '', + $client_package_ensure = '', + $client_package_name = '', + $config_file = '', + $config_template = '', + $datadir = '', + $default_engine = '', + $etc_root_password = '', + $log_error = '', + $manage_config_file = '', + $manage_service = '', + $max_allowed_packet = '', + $max_connections = '', + $old_root_password = '', + $package_ensure = '', + $php_package_name = '', + $pidfile = '', + $port = '', + $purge_conf_dir = '', + $restart = '', + $root_group = '', + $root_password = '', + $server_package_name = '', + $service_name = '', + $service_provider = '', + $socket = '', + $ssl = '', + $ssl_ca = '', + $ssl_cert = '', + $ssl_key = '', + $tmpdir = '', + $attempt_compatibility_mode = false, +) { + + if $attempt_compatibility_mode { + notify { "An attempt has been made below to automatically apply your custom + settings to mysql::server. Please verify this works in a safe test + environment.": } + + $override_options = { + 'client' => { + 'port' => $port, + 'socket' => $socket + }, + 'mysqld_safe' => { + 'log_error' => $log_error, + 'socket' => $socket, + }, + 'mysqld' => { + 'basedir' => $basedir, + 'bind_address' => $bind_address, + 'datadir' => $datadir, + 'log_error' => $log_error, + 'max_allowed_packet' => $max_allowed_packet, + 'max_connections' => $max_connections, + 'pid_file' => $pidfile, + 'port' => $port, + 'socket' => $socket, + 'ssl-ca' => $ssl_ca, + 'ssl-cert' => $ssl_cert, + 'ssl-key' => $ssl_key, + 'tmpdir' => $tmpdir, + }, + 'mysqldump' => { + 'max_allowed_packet' => $max_allowed_packet, + }, + 'config_file' => $config_file, + 'etc_root_password' => $etc_root_password, + 'manage_config_file' => $manage_config_file, + 'old_root_password' => $old_root_password, + 'purge_conf_dir' => $purge_conf_dir, + 'restart' => $restart, + 'root_group' => $root_group, + 'root_password' => $root_password, + 'service_name' => $service_name, + 'ssl' => $ssl + } + $filtered_options = mysql_strip_hash($override_options) + validate_hash($filtered_options) + notify { $filtered_options: } + class { 'mysql::server': + override_options => $filtered_options, + } + + } else { + fail("ERROR: This class has been deprecated and the functionality moved + into mysql::server. If you run mysql::server without correctly calling + mysql:: server with the new override_options hash syntax you will revert + your MySQL to the stock settings. Do not proceed without removing this + class and using mysql::server correctly. + + If you are brave you may set attempt_compatibility_mode in this class which + attempts to automap the previous settings to appropriate calls to + mysql::server") + } + +} diff --git a/deployment/modules/mysql/manifests/params.pp b/deployment/modules/mysql/manifests/params.pp new file mode 100644 index 000000000..58bcc5669 --- /dev/null +++ b/deployment/modules/mysql/manifests/params.pp @@ -0,0 +1,230 @@ +# Private class: See README.md. +class mysql::params { + + $manage_config_file = true + $old_root_password = '' + $purge_conf_dir = false + $restart = false + $root_password = 'UNSET' + $server_package_ensure = 'present' + $server_service_manage = true + $server_service_enabled = true + # mysql::bindings + $bindings_enable = false + $java_package_ensure = 'present' + $java_package_provider = undef + $perl_package_ensure = 'present' + $perl_package_provider = undef + $php_package_ensure = 'present' + $php_package_provider = undef + $python_package_ensure = 'present' + $python_package_provider = undef + $ruby_package_ensure = 'present' + $ruby_package_provider = undef + + + case $::osfamily { + 'RedHat': { + if $::operatingsystem == 'Fedora' and (is_integer($::operatingsystemrelease) and $::operatingsystemrelease >= 19 or $::operatingsystemrelease == "Rawhide") { + $client_package_name = 'mariadb' + $server_package_name = 'mariadb-server' + } else { + $client_package_name = 'mysql' + $server_package_name = 'mysql-server' + } + $basedir = '/usr' + $config_file = '/etc/my.cnf' + $datadir = '/var/lib/mysql' + $log_error = '/var/log/mysqld.log' + $pidfile = '/var/run/mysqld/mysqld.pid' + $root_group = 'root' + $server_service_name = 'mysqld' + $socket = '/var/lib/mysql/mysql.sock' + $ssl_ca = '/etc/mysql/cacert.pem' + $ssl_cert = '/etc/mysql/server-cert.pem' + $ssl_key = '/etc/mysql/server-key.pem' + $tmpdir = '/tmp' + # mysql::bindings + $java_package_name = 'mysql-connector-java' + $perl_package_name = 'perl-DBD-MySQL' + $php_package_name = 'php-mysql' + $python_package_name = 'MySQL-python' + $ruby_package_name = 'ruby-mysql' + } + + 'Suse': { + $client_package_name = $::operatingsystem ? { + /OpenSuSE/ => 'mysql-community-server-client', + /(SLES|SLED)/ => 'mysql-client', + } + $server_package_name = $::operatingsystem ? { + /OpenSuSE/ => 'mysql-community-server', + /(SLES|SLED)/ => 'mysql', + } + $basedir = '/usr' + $config_file = '/etc/my.cnf' + $datadir = '/var/lib/mysql' + $log_error = $::operatingsystem ? { + /OpenSuSE/ => '/var/log/mysql/mysqld.log', + /(SLES|SLED)/ => '/var/log/mysqld.log', + } + $pidfile = $::operatingsystem ? { + /OpenSuSE/ => '/var/run/mysql/mysqld.pid', + /(SLES|SLED)/ => '/var/lib/mysql/mysqld.pid', + } + $root_group = 'root' + $server_service_name = 'mysql' + $socket = $::operatingsystem ? { + /OpenSuSE/ => '/var/run/mysql/mysql.sock', + /(SLES|SLED)/ => '/var/lib/mysql/mysql.sock', + } + $ssl_ca = '/etc/mysql/cacert.pem' + $ssl_cert = '/etc/mysql/server-cert.pem' + $ssl_key = '/etc/mysql/server-key.pem' + $tmpdir = '/tmp' + # mysql::bindings + $java_package_name = 'mysql-connector-java' + $perl_package_name = 'perl-DBD-mysql' + $php_package_name = 'apache2-mod_php5' + $python_package_name = 'python-mysql' + $ruby_package_name = $::operatingsystem ? { + /OpenSuSE/ => 'rubygem-mysql', + /(SLES|SLED)/ => 'ruby-mysql', + } + } + + 'Debian': { + $client_package_name = 'mysql-client' + $server_package_name = 'mysql-server' + + $basedir = '/usr' + $config_file = '/etc/mysql/my.cnf' + $datadir = '/var/lib/mysql' + $log_error = '/var/log/mysql/error.log' + $pidfile = '/var/run/mysqld/mysqld.pid' + $root_group = 'root' + $server_service_name = 'mysql' + $socket = '/var/run/mysqld/mysqld.sock' + $ssl_ca = '/etc/mysql/cacert.pem' + $ssl_cert = '/etc/mysql/server-cert.pem' + $ssl_key = '/etc/mysql/server-key.pem' + $tmpdir = '/tmp' + # mysql::bindings + $java_package_name = 'libmysql-java' + $perl_package_name = 'libdbd-mysql-perl' + $php_package_name = 'php5-mysql' + $python_package_name = 'python-mysqldb' + $ruby_package_name = 'libmysql-ruby' + } + + 'FreeBSD': { + $client_package_name = 'databases/mysql55-client' + $server_package_name = 'databases/mysql55-server' + $basedir = '/usr/local' + $config_file = '/var/db/mysql/my.cnf' + $datadir = '/var/db/mysql' + $log_error = "/var/db/mysql/${::hostname}.err" + $pidfile = '/var/db/mysql/mysql.pid' + $root_group = 'wheel' + $server_service_name = 'mysql-server' + $socket = '/tmp/mysql.sock' + $ssl_ca = undef + $ssl_cert = undef + $ssl_key = undef + $tmpdir = '/tmp' + # mysql::bindings + $java_package_name = 'databases/mysql-connector-java' + $perl_package_name = 'p5-DBD-mysql' + $php_package_name = 'php5-mysql' + $python_package_name = 'databases/py-MySQLdb' + $ruby_package_name = 'databases/ruby-mysql' + } + + default: { + case $::operatingsystem { + 'Amazon': { + $client_package_name = 'mysql' + $server_package_name = 'mysql-server' + $basedir = '/usr' + $config_file = '/etc/my.cnf' + $datadir = '/var/lib/mysql' + $log_error = '/var/log/mysqld.log' + $pidfile = '/var/run/mysqld/mysqld.pid' + $root_group = 'root' + $server_service_name = 'mysqld' + $socket = '/var/lib/mysql/mysql.sock' + $ssl_ca = '/etc/mysql/cacert.pem' + $ssl_cert = '/etc/mysql/server-cert.pem' + $ssl_key = '/etc/mysql/server-key.pem' + $tmpdir = '/tmp' + # mysql::bindings + $java_package_name = 'mysql-connector-java' + $perl_package_name = 'perl-DBD-MySQL' + $php_package_name = 'php-mysql' + $python_package_name = 'MySQL-python' + $ruby_package_name = 'ruby-mysql' + } + + default: { + fail("Unsupported osfamily: ${::osfamily} operatingsystem: ${::operatingsystem}, module ${module_name} only support osfamily RedHat, Debian, and FreeBSD, or operatingsystem Amazon") + } + } + } + } + + case $::operatingsystem { + 'Ubuntu': { + $service_provider = upstart + } + default: { + $service_provider = undef + } + } + + $default_options = { + 'client' => { + 'port' => '3306', + 'socket' => $mysql::params::socket, + }, + 'mysqld_safe' => { + 'nice' => '0', + 'log_error' => $mysql::params::log_error, + 'socket' => $mysql::params::socket, + }, + 'mysqld' => { + 'basedir' => $mysql::params::basedir, + 'bind_address' => '127.0.0.1', + 'datadir' => $mysql::params::datadir, + 'expire_logs_days' => '10', + 'key_buffer' => '16M', + 'log_error' => $mysql::params::log_error, + 'max_allowed_packet' => '16M', + 'max_binlog_size' => '100M', + 'max_connections' => '151', + 'myisam_recover' => 'BACKUP', + 'pid_file' => $mysql::params::pidfile, + 'port' => '3306', + 'query_cache_limit' => '1M', + 'query_cache_size' => '16M', + 'skip-external-locking' => true, + 'socket' => $mysql::params::socket, + 'ssl' => false, + 'ssl-ca' => $mysql::params::ssl_ca, + 'ssl-cert' => $mysql::params::ssl_cert, + 'ssl-key' => $mysql::params::ssl_key, + 'thread_cache_size' => '8', + 'thread_stack' => '256K', + 'tmpdir' => $mysql::params::tmpdir, + 'user' => 'mysql', + }, + 'mysqldump' => { + 'max_allowed_packet' => '16M', + 'quick' => true, + 'quote-names' => true, + }, + 'isamchk' => { + 'key_buffer' => '16M', + }, + } + +} diff --git a/deployment/modules/mysql/manifests/server.pp b/deployment/modules/mysql/manifests/server.pp new file mode 100644 index 000000000..372e644d2 --- /dev/null +++ b/deployment/modules/mysql/manifests/server.pp @@ -0,0 +1,69 @@ +# Class: mysql::server: See README.md for documentation. +class mysql::server ( + $config_file = $mysql::params::config_file, + $manage_config_file = $mysql::params::manage_config_file, + $old_root_password = $mysql::params::old_root_password, + $override_options = {}, + $package_ensure = $mysql::params::server_package_ensure, + $package_name = $mysql::params::server_package_name, + $purge_conf_dir = $mysql::params::purge_conf_dir, + $remove_default_accounts = false, + $restart = $mysql::params::restart, + $root_group = $mysql::params::root_group, + $root_password = $mysql::params::root_password, + $service_enabled = $mysql::params::server_service_enabled, + $service_manage = $mysql::params::server_service_manage, + $service_name = $mysql::params::server_service_name, + $service_provider = $mysql::params::server_service_provider, + $users = {}, + $grants = {}, + $databases = {}, + + # Deprecated parameters + $enabled = undef, + $manage_service = undef +) inherits mysql::params { + + # Deprecated parameters. + if $enabled { + crit('This parameter has been renamed to service_enabled.') + $real_service_enabled = $enabled + } else { + $real_service_enabled = $service_enabled + } + if $manage_service { + crit('This parameter has been renamed to service_manage.') + $real_service_manage = $manage_service + } else { + $real_service_manage = $service_manage + } + + # Create a merged together set of options. Rightmost hashes win over left. + $options = mysql_deepmerge($mysql::params::default_options, $override_options) + + Class['mysql::server::root_password'] -> Mysql::Db <| |> + + include '::mysql::server::install' + include '::mysql::server::config' + include '::mysql::server::service' + include '::mysql::server::root_password' + include '::mysql::server::providers' + + if $remove_default_accounts { + class { '::mysql::server::account_security': + require => Anchor['mysql::server::end'], + } + } + + anchor { 'mysql::server::start': } + anchor { 'mysql::server::end': } + + Anchor['mysql::server::start'] -> + Class['mysql::server::install'] -> + Class['mysql::server::config'] -> + Class['mysql::server::service'] -> + Class['mysql::server::root_password'] -> + Class['mysql::server::providers'] -> + Anchor['mysql::server::end'] + +} diff --git a/deployment/modules/mysql/manifests/server/account_security.pp b/deployment/modules/mysql/manifests/server/account_security.pp new file mode 100644 index 000000000..36d943757 --- /dev/null +++ b/deployment/modules/mysql/manifests/server/account_security.pp @@ -0,0 +1,22 @@ +class mysql::server::account_security { + mysql_user { + [ "root@${::fqdn}", + 'root@127.0.0.1', + 'root@::1', + "@${::fqdn}", + '@localhost', + '@%']: + ensure => 'absent', + require => Anchor['mysql::server::end'], + } + if ($::fqdn != $::hostname) { + mysql_user { ["root@${::hostname}", "@${::hostname}"]: + ensure => 'absent', + require => Anchor['mysql::server::end'], + } + } + mysql_database { 'test': + ensure => 'absent', + require => Anchor['mysql::server::end'], + } +} diff --git a/deployment/modules/mysql/manifests/server/backup.pp b/deployment/modules/mysql/manifests/server/backup.pp new file mode 100644 index 000000000..8470660ef --- /dev/null +++ b/deployment/modules/mysql/manifests/server/backup.pp @@ -0,0 +1,56 @@ +# See README.me for usage. +class mysql::server::backup ( + $backupuser, + $backuppassword, + $backupdir, + $backupcompress = true, + $backuprotate = 30, + $delete_before_dump = false, + $backupdatabases = [], + $file_per_database = false, + $ensure = 'present', + $time = ['23', '5'], +) { + + mysql_user { "${backupuser}@localhost": + ensure => $ensure, + password_hash => mysql_password($backuppassword), + provider => 'mysql', + require => Class['mysql::server::config'], + } + + mysql_grant { "${backupuser}@localhost/*.*": + ensure => present, + user => "${backupuser}@localhost", + table => '*.*', + privileges => [ 'SELECT', 'RELOAD', 'LOCK TABLES', 'SHOW VIEW' ], + require => Mysql_user["${backupuser}@localhost"], + } + + cron { 'mysql-backup': + ensure => $ensure, + command => '/usr/local/sbin/mysqlbackup.sh', + user => 'root', + hour => $time[0], + minute => $time[1], + require => File['mysqlbackup.sh'], + } + + file { 'mysqlbackup.sh': + ensure => $ensure, + path => '/usr/local/sbin/mysqlbackup.sh', + mode => '0700', + owner => 'root', + group => 'root', + content => template('mysql/mysqlbackup.sh.erb'), + } + + file { 'mysqlbackupdir': + ensure => 'directory', + path => $backupdir, + mode => '0700', + owner => 'root', + group => 'root', + } + +} diff --git a/deployment/modules/mysql/manifests/server/config.pp b/deployment/modules/mysql/manifests/server/config.pp new file mode 100644 index 000000000..3e85cfa4e --- /dev/null +++ b/deployment/modules/mysql/manifests/server/config.pp @@ -0,0 +1,31 @@ +# See README.me for options. +class mysql::server::config { + + $options = $mysql::server::options + + File { + owner => 'root', + group => $mysql::server::root_group, + mode => '0400', + notify => Class['mysql::server::service'], + } + + file { '/etc/mysql': + ensure => directory, + mode => '0755', + } + + file { '/etc/mysql/conf.d': + ensure => directory, + mode => '0755', + recurse => $mysql::server::purge_conf_dir, + purge => $mysql::server::purge_conf_dir, + } + + if $mysql::server::manage_config_file { + file { $mysql::server::config_file: + content => template('mysql/my.cnf.erb'), + mode => '0644', + } + } +} diff --git a/deployment/modules/mysql/manifests/server/install.pp b/deployment/modules/mysql/manifests/server/install.pp new file mode 100644 index 000000000..dcb04cb12 --- /dev/null +++ b/deployment/modules/mysql/manifests/server/install.pp @@ -0,0 +1,9 @@ +# +class mysql::server::install { + + package { 'mysql-server': + ensure => $mysql::server::package_ensure, + name => $mysql::server::package_name, + } + +} diff --git a/deployment/modules/mysql/manifests/server/monitor.pp b/deployment/modules/mysql/manifests/server/monitor.pp new file mode 100644 index 000000000..9e86b92c7 --- /dev/null +++ b/deployment/modules/mysql/manifests/server/monitor.pp @@ -0,0 +1,24 @@ +#This is a helper class to add a monitoring user to the database +class mysql::server::monitor ( + $mysql_monitor_username, + $mysql_monitor_password, + $mysql_monitor_hostname +) { + + Anchor['mysql::server::end'] -> Class['mysql::server::monitor'] + + mysql_user { "${mysql_monitor_username}@${mysql_monitor_hostname}": + ensure => present, + password_hash => mysql_password($mysql_monitor_password), + require => Class['mysql::server::service'], + } + + mysql_grant { "${mysql_monitor_username}@${mysql_monitor_hostname}/*.*": + ensure => present, + user => "${mysql_monitor_username}@${mysql_monitor_hostname}", + table => '*.*', + privileges => [ 'PROCESS', 'SUPER' ], + require => Mysql_user["${mysql_monitor_username}@${mysql_monitor_hostname}"], + } + +} diff --git a/deployment/modules/mysql/manifests/server/mysqltuner.pp b/deployment/modules/mysql/manifests/server/mysqltuner.pp new file mode 100644 index 000000000..23d19a558 --- /dev/null +++ b/deployment/modules/mysql/manifests/server/mysqltuner.pp @@ -0,0 +1,9 @@ +# +class mysql::server::mysqltuner($ensure='present') { + # mysql performance tester + file { '/usr/local/bin/mysqltuner': + ensure => $ensure, + mode => '0550', + source => 'puppet:///modules/mysql/mysqltuner.pl', + } +} diff --git a/deployment/modules/mysql/manifests/server/providers.pp b/deployment/modules/mysql/manifests/server/providers.pp new file mode 100644 index 000000000..b651172fc --- /dev/null +++ b/deployment/modules/mysql/manifests/server/providers.pp @@ -0,0 +1,8 @@ +# Convenience class to call each of the three providers with the corresponding +# hashes provided in mysql::server. +# See README.md for details. +class mysql::server::providers { + create_resources('mysql_user', $mysql::server::users) + create_resources('mysql_grant', $mysql::server::grants) + create_resources('mysql_database', $mysql::server::databases) +} diff --git a/deployment/modules/mysql/manifests/server/root_password.pp b/deployment/modules/mysql/manifests/server/root_password.pp new file mode 100644 index 000000000..e75412dab --- /dev/null +++ b/deployment/modules/mysql/manifests/server/root_password.pp @@ -0,0 +1,21 @@ +# +class mysql::server::root_password { + + $options = $mysql::server::options + + # manage root password if it is set + if $mysql::server::root_password != 'UNSET' { + mysql_user { 'root@localhost': + ensure => present, + password_hash => mysql_password($mysql::server::root_password), + } + + file { "${::root_home}/.my.cnf": + content => template('mysql/my.cnf.pass.erb'), + owner => 'root', + mode => '0600', + require => Mysql_user['root@localhost'], + } + } + +} diff --git a/deployment/modules/mysql/manifests/server/service.pp b/deployment/modules/mysql/manifests/server/service.pp new file mode 100644 index 000000000..c60e03662 --- /dev/null +++ b/deployment/modules/mysql/manifests/server/service.pp @@ -0,0 +1,19 @@ +# +class mysql::server::service { + + if $mysql::server::real_service_enabled { + $service_ensure = 'running' + } else { + $service_ensure = 'stopped' + } + + if $mysql::server::real_service_manage { + service { 'mysqld': + ensure => $service_ensure, + name => $mysql::server::service_name, + enable => $mysql::server::real_service_enabled, + provider => $mysql::server::service_provider, + } + } + +} diff --git a/deployment/modules/mysql/metadata.json b/deployment/modules/mysql/metadata.json new file mode 100644 index 000000000..ae8584318 --- /dev/null +++ b/deployment/modules/mysql/metadata.json @@ -0,0 +1,289 @@ +{ + "name": "puppetlabs-mysql", + "version": "2.1.0", + "summary": "Mysql module", + "author": "Puppet Labs", + "description": "Mysql module", + "dependencies": [ + { + "name": "puppetlabs/stdlib", + "version_requirement": "\u003e\u003d 2.2.1" + } + ], + "types": [ + { + "properties": [ + { + "name": "password_hash", + "doc": "The password hash of the user. Use mysql_password() for creating such a hash." + }, + { + "name": "max_user_connections", + "doc": "Max concurrent connections for the user. 0 means no (or global) limit." + } + ], + "parameters": [ + { + "name": "name", + "doc": "The name of the user. This uses the \u0027username@hostname\u0027 or username@hostname." + } + ], + "providers": [ + { + "name": "mysql", + "doc": "manage users for a mysql database." + } + ], + "name": "database_user", + "doc": "Manage a database user. This includes management of users password as well as privileges" + }, + { + "properties": [ + { + "name": "charset", + "doc": "The CHARACTER SET setting for the database" + }, + { + "name": "collate", + "doc": "The COLLATE setting for the database" + } + ], + "parameters": [ + { + "name": "name", + "doc": "The name of the MySQL database to manage." + } + ], + "providers": [ + { + "name": "mysql", + "doc": "Manages MySQL databases." + } + ], + "name": "mysql_database", + "doc": "Manage MySQL databases." + }, + { + "properties": [ + { + "name": "password_hash", + "doc": "The password hash of the user. Use mysql_password() for creating such a hash." + }, + { + "name": "max_user_connections", + "doc": "Max concurrent connections for the user. 0 means no (or global) limit." + }, + { + "name": "max_connections_per_hour", + "doc": "Max connections per hour for the user. 0 means no (or global) limit." + }, + { + "name": "max_queries_per_hour", + "doc": "Max queries per hour for the user. 0 means no (or global) limit." + }, + { + "name": "max_updates_per_hour", + "doc": "Max updates per hour for the user. 0 means no (or global) limit." + } + ], + "parameters": [ + { + "name": "name", + "doc": "The name of the user. This uses the \u0027username@hostname\u0027 or username@hostname." + } + ], + "providers": [ + { + "name": "mysql", + "doc": "manage users for a mysql database." + } + ], + "name": "mysql_user", + "doc": "Manage a MySQL user. This includes management of users password as well as privileges." + }, + { + "properties": [ + { + "name": "charset", + "doc": "The characterset to use for a database" + } + ], + "parameters": [ + { + "name": "name", + "doc": "The name of the database." + } + ], + "providers": [ + { + "name": "mysql", + "doc": "Manages MySQL database." + } + ], + "name": "database", + "doc": "Manage databases." + }, + { + "properties": [ + { + "name": "privileges", + "doc": "The privileges the user should have. The possible values are implementation dependent." + } + ], + "parameters": [ + { + "name": "name", + "doc": "The primary key: either user@host for global privilges or user@host/database for database specific privileges" + } + ], + "providers": [ + { + "name": "mysql", + "doc": "Uses mysql as database." + } + ], + "name": "database_grant", + "doc": "Manage a database user\u0027s rights." + }, + { + "properties": [ + { + "name": "privileges", + "doc": "Privileges for user" + }, + { + "name": "table", + "doc": "Table to apply privileges to." + }, + { + "name": "user", + "doc": "User to operate on." + }, + { + "name": "options", + "doc": "Options to grant." + } + ], + "parameters": [ + { + "name": "name", + "doc": "Name to describe the grant." + } + ], + "providers": [ + { + "name": "mysql", + "doc": "Set grants for users in MySQL." + } + ], + "name": "mysql_grant", + "doc": "Manage a MySQL user\u0027s rights." + } + ], + "checksums": { + ".bundle/config": "7f1c988748783d2a8d455376eed1470c", + ".fixtures.yml": "754de171830d3a00220cdc85bcb794a0", + ".forge-release/pom.xml": "c650a84961ad88de03192e23b63b3549", + ".forge-release/publish": "1c1d6dd64ef52246db485eb5459aa941", + ".forge-release/settings.xml": "06d768a57d582fe1ee078b563427e750", + ".forge-release/validate": "7fffde8112f42a1ec986d49ba80ac219", + ".nodeset.yml": "f2b857f9fc7a701ff118e28591c12925", + ".travis.yml": "35fe54be03fbc47ce9b015b22240e683", + "CHANGELOG": "0955be7c90f16e48ae9749641170ca69", + "Gemfile": "4d0813cea67347e0abb409f53f814155", + "Gemfile.lock": "9ee04c7900f8209895e1acee1664ce7d", + "LICENSE": "6089b6bd1f0d807edb8bdfd76da0b038", + "Modulefile": "8faf920c294adde182c9087cf1113db3", + "README.md": "9afcf56a8845ec7e06739bb74478929e", + "Rakefile": "0428ea3759a4692c91604396c406a9c1", + "TODO": "88ca4024a37992b46c34cb46e4ac39e6", + "files/mysqltuner.pl": "65056d1386e04fdf22a1fee556c1b9fc", + "lib/puppet/parser/functions/mysql_deepmerge.rb": "6f20428e15e98f2368ee63a56412a7c3", + "lib/puppet/parser/functions/mysql_password.rb": "a4c8ec72dede069508dbc266131b06a3", + "lib/puppet/parser/functions/mysql_strip_hash.rb": "3efe69f1eb189b2913e178b8472aaede", + "lib/puppet/provider/database/mysql.rb": "66e7506c4823bb5ea150ca3c1b62bc98", + "lib/puppet/provider/database_grant/mysql.rb": "163fd7c65bc3e1371393f3d5c8d6ae10", + "lib/puppet/provider/database_user/mysql.rb": "47f13b62d5bb05ae7184e50a6a38a13c", + "lib/puppet/provider/mysql.rb": "e8eb4be7cead5b8627ccaea1f435c95a", + "lib/puppet/provider/mysql_database/mysql.rb": "466af4dc5e7689b47a9322f4d8a9b3f2", + "lib/puppet/provider/mysql_grant/mysql.rb": "f27f8cc23f74ce59a49172d8e6a0d5dc", + "lib/puppet/provider/mysql_user/mysql.rb": "87aee13a24a2d01ed34e3b91b9297e40", + "lib/puppet/type/database.rb": "7b4b49b841d41541ce719d1a051ee94b", + "lib/puppet/type/database_grant.rb": "66fce5df0f3f4111fe37f094965f6f93", + "lib/puppet/type/database_user.rb": "b2a87e3854324fb0ae407a1fbad5802a", + "lib/puppet/type/mysql_database.rb": "e21a38611edc6cba5454889170bc0ebc", + "lib/puppet/type/mysql_grant.rb": "9e34c78952e5fcc073f089e58ab35cf3", + "lib/puppet/type/mysql_user.rb": "ddb054a5fd03689ae4325fbe003a41d3", + "manifests/backup.pp": "dfa324a48d47935a8423b102458c6516", + "manifests/bindings.pp": "5976e9b74a29cc3a102f49867709a08f", + "manifests/bindings/java.pp": "6a581f1da1690d436ae14832af551ca2", + "manifests/bindings/perl.pp": "e765d0792afacbe72cf3e65804b78fe7", + "manifests/bindings/php.pp": "09017ca0adefbb8bf894393371cfad94", + "manifests/bindings/python.pp": "50c22f04074695f17ea383b307d01ea3", + "manifests/bindings/ruby.pp": "99f7c01e468136c8e699fcbb36d037fa", + "manifests/client.pp": "ab5a3ece8f5c4cc2174532472bdc5afe", + "manifests/client/install.pp": "381f70bfbaac921d631e3b115d8ae264", + "manifests/db.pp": "0dd59f8d1578c25a2517d4fda862624b", + "manifests/init.pp": "52ad9ac01674695edaf62cc1c48ef4f8", + "manifests/params.pp": "033b2e0f88f15b2d8aab3b08ed470abd", + "manifests/server.pp": "1bafcd02849a12efaa2271e55380393b", + "manifests/server/account_security.pp": "c793a434142ddaa6a529ed59739368fb", + "manifests/server/backup.pp": "ff6239ff4e2c46f42ec9b34a805c6718", + "manifests/server/config.pp": "dcc92deb6e2e100bf150016a8fb2a42d", + "manifests/server/install.pp": "8666481a3ea12e9f76c47dfa558c09e6", + "manifests/server/monitor.pp": "a63731018c171de9e441009d453dcac8", + "manifests/server/mysqltuner.pp": "4b19b075ecb7a7054cac237e5f50ed16", + "manifests/server/providers.pp": "87a019dce5bbb6b18c9aa61b5f99134c", + "manifests/server/root_password.pp": "73738c1b6ee42b896db5356575c95af6", + "manifests/server/service.pp": "e79e2206b06d41956fb6d87fc1d20aa0", + "spec/classes/mysql_bindings_spec.rb": "cfc90d020af62a2315129c84f6acc7d9", + "spec/classes/mysql_client_spec.rb": "1849bea122f7282153cbc46ca04aa851", + "spec/classes/mysql_server_account_security_spec.rb": "e223281077baa230fb6b7387f56af6d8", + "spec/classes/mysql_server_backup_spec.rb": "4c7e64b955bf1df76aead3bf93c2ae1c", + "spec/classes/mysql_server_monitor_spec.rb": "2bf20049616769424afd4a5137e25511", + "spec/classes/mysql_server_mysqltuner_spec.rb": "7a098808c21e3f08cd26237a96acc878", + "spec/classes/mysql_server_spec.rb": "bc2dccc7ea00340a048ac91d602c1ac0", + "spec/defines/mysql_db_spec.rb": "26b348846df5013819c7c9f18090ffc4", + "spec/spec.opts": "a600ded995d948e393fbe2320ba8e51c", + "spec/spec_helper.rb": "92fefec2bd21423ec2aece165375678b", + "spec/spec_helper_system.rb": "30ef76d722878ce9049203e753663335", + "spec/system/mysql_account_delete_spec.rb": "ff8d45ad704f7e3c5fdcae7a4be2ea6e", + "spec/system/mysql_backup_spec.rb": "e30ef8f335f216afa489077643f57c98", + "spec/system/mysql_bindings_spec.rb": "1e8cb8b2eb50ee3a7f663d6bc979ae2d", + "spec/system/mysql_db_spec.rb": "798771e3185a52fdc29513bf4eb33d15", + "spec/system/mysql_server_monitor_spec.rb": "5f282becde15a434aee3f56c99e61ca2", + "spec/system/mysql_server_root_password_spec.rb": "3e8fd20f19e0803dcd20cdac5f0179c8", + "spec/system/mysql_server_spec.rb": "f3039e1e7737712ca45d7e14e2cad28f", + "spec/system/types/mysql_grant_spec.rb": "7224f1d7d44e63a5d3a44b43cc38be5d", + "spec/system/types/mysql_user_spec.rb": "63f1d4c5136291b3cfba33a07e8bb37d", + "spec/unit/mysql_password_spec.rb": "7e1f9c635cb9dd4143054e096515006b", + "spec/unit/puppet/functions/mysql_deepmerge_spec.rb": "6b33280aa390e1e7788168df65499fd5", + "spec/unit/puppet/provider/database/mysql_spec.rb": "3bb92bdaaddfd54e7700012b2418f1ba", + "spec/unit/puppet/provider/database_grant/mysql_spec.rb": "261c22e57374b6651b87fcac86c9b563", + "spec/unit/puppet/provider/database_user/mysql_spec.rb": "50709cf2cf3f852a56de1856222b9b1f", + "spec/unit/puppet/provider/mysql_database/mysql_spec.rb": "86bfe78acaefd34ed195742e9aff5896", + "spec/unit/puppet/provider/mysql_user/mysql_spec.rb": "d59edf286efa51990d0db1c0307e91ea", + "spec/unit/puppet/type/mysql_database_spec.rb": "0b32abc822e7613bdbb46f0a35c5b999", + "spec/unit/puppet/type/mysql_user_spec.rb": "1a20ac660f54f9976bb5a0c03c339efc", + "templates/my.cnf.erb": "0cb43aad4d2c5903cad87bffa3569348", + "templates/my.cnf.pass.erb": "30b24a3f29fcc644bd3a73929305cda0", + "templates/my.conf.cnf.erb": "5ebda0d5d774b2a51c25c43fbfed544a", + "templates/mysqlbackup.sh.erb": "b5ca36fac16da99ec88344addd03b997", + "tests/backup.pp": "caae4da564c1f663341bbe50915a5f7d", + "tests/bindings.pp": "dda8795d67098b66aa65e81ccc48ed73", + "tests/init.pp": "6b34827ac4731829c8a117f0b3fb8167", + "tests/java.pp": "0ad9de4f9f2c049642bcf08124757085", + "tests/mysql_database.pp": "2a85cd95a9952e3d93aa05f8f236551e", + "tests/mysql_grant.pp": "cd42336a6c7b2d27f5d5d6d0e310ee1a", + "tests/mysql_user.pp": "7aa29740f3b6cd8a7041d59af2d595cc", + "tests/perl.pp": "6e496f19eaae83c90ce8b93236d44bca", + "tests/python.pp": "b093828acfed9c14e25ebdd60d90c282", + "tests/ruby.pp": "6c5071fcaf731995c9b8e31e00eaffa0", + "tests/server.pp": "72e22552a95b9a5e4a349dbfc13639dc", + "tests/server/account_security.pp": "47f79d7ae9eac2bf2134db27abf1db37", + "tests/server/config.pp": "619b4220138a12c6cb5f10af9867d8a1" + }, + "source": "git://github.com/puppetlabs/puppetlabs-mysql.git", + "project_page": "http://github.com/puppetlabs/puppetlabs-mysql", + "license": "Apache 2.0" +} \ No newline at end of file diff --git a/deployment/modules/mysql/spec/classes/mysql_bindings_spec.rb b/deployment/modules/mysql/spec/classes/mysql_bindings_spec.rb new file mode 100644 index 000000000..8ec4428bb --- /dev/null +++ b/deployment/modules/mysql/spec/classes/mysql_bindings_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper' + +describe 'mysql::bindings' do + let(:params) {{ + 'java_enable' => true, + 'perl_enable' => true, + 'php_enable' => true, + 'python_enable' => true, + 'ruby_enable' => true, + }} + + shared_examples 'bindings' do |osfamily, operatingsystem, java_name, perl_name, php_name, python_name, ruby_name| + let :facts do + { :osfamily => osfamily, :operatingsystem => operatingsystem, :root_home => '/root'} + end + it { should contain_package('mysql-connector-java').with( + :name => java_name, + :ensure => 'present' + )} + it { should contain_package('perl_mysql').with( + :name => perl_name, + :ensure => 'present' + )} + it { should contain_package('python-mysqldb').with( + :name => python_name, + :ensure => 'present' + )} + it { should contain_package('ruby_mysql').with( + :name => ruby_name, + :ensure => 'present' + )} + end + + context 'Debian' do + it_behaves_like 'bindings', 'Debian', 'Debian', 'libmysql-java', 'libdbd-mysql-perl', 'php5-mysql', 'python-mysqldb', 'libmysql-ruby' + it_behaves_like 'bindings', 'Debian', 'Ubuntu', 'libmysql-java', 'libdbd-mysql-perl', 'php5-mysql', 'python-mysqldb', 'libmysql-ruby' + end + + context 'freebsd' do + it_behaves_like 'bindings', 'FreeBSD', 'FreeBSD', 'databases/mysql-connector-java', 'p5-DBD-mysql', 'databases/php5-mysql', 'databases/py-MySQLdb', 'databases/ruby-mysql' + end + + context 'redhat' do + it_behaves_like 'bindings', 'RedHat', 'RedHat', 'mysql-connector-java', 'perl-DBD-MySQL', 'php-mysql', 'MySQL-python', 'ruby-mysql' + it_behaves_like 'bindings', 'RedHat', 'OpenSuSE', 'mysql-connector-java', 'perl-DBD-MySQL', 'php-mysql', 'MySQL-python', 'ruby-mysql' + end + + describe 'on any other os' do + let :facts do + {:osfamily => 'foo', :root_home => '/root'} + end + + it 'should fail' do + expect { subject }.to raise_error(/Unsupported osfamily: foo/) + end + end + +end diff --git a/deployment/modules/mysql/spec/classes/mysql_client_spec.rb b/deployment/modules/mysql/spec/classes/mysql_client_spec.rb new file mode 100644 index 000000000..d7386d17a --- /dev/null +++ b/deployment/modules/mysql/spec/classes/mysql_client_spec.rb @@ -0,0 +1,16 @@ +describe 'mysql::client' do + let(:facts) {{ :osfamily => 'RedHat' }} + + context 'with defaults' do + it { should_not contain_class('mysql::bindings') } + it { should contain_package('mysql_client') } + end + + context 'with bindings enabled' do + let(:params) {{ :bindings_enable => true }} + + it { should contain_class('mysql::bindings') } + it { should contain_package('mysql_client') } + end + +end diff --git a/deployment/modules/mysql/spec/classes/mysql_server_account_security_spec.rb b/deployment/modules/mysql/spec/classes/mysql_server_account_security_spec.rb new file mode 100644 index 000000000..1d0e7506c --- /dev/null +++ b/deployment/modules/mysql/spec/classes/mysql_server_account_security_spec.rb @@ -0,0 +1,41 @@ +require 'spec_helper' + +describe 'mysql::server::account_security' do + + let :facts do { + :fqdn => 'myhost.mydomain', + :hostname => 'myhost', + :root_home => '/root' + } + end + + it 'should remove Mysql_User[root@myhost.mydomain]' do + should contain_mysql_user('root@myhost.mydomain').with_ensure('absent') + end + it 'should remove Mysql_User[root@myhost]' do + should contain_mysql_user('root@myhost').with_ensure('absent') + end + it 'should remove Mysql_User[root@127.0.0.1]' do + should contain_mysql_user('root@127.0.0.1').with_ensure('absent') + end + it 'should remove Mysql_User[root@::1]' do + should contain_mysql_user('root@::1').with_ensure('absent') + end + it 'should remove Mysql_User[@myhost.mydomain]' do + should contain_mysql_user('@myhost.mydomain').with_ensure('absent') + end + it 'should remove Mysql_User[@myhost]' do + should contain_mysql_user('@myhost').with_ensure('absent') + end + it 'should remove Mysql_User[@localhost]' do + should contain_mysql_user('@localhost').with_ensure('absent') + end + it 'should remove Mysql_User[@%]' do + should contain_mysql_user('@%').with_ensure('absent') + end + + it 'should remove Mysql_database[test]' do + should contain_mysql_database('test').with_ensure('absent') + end + +end diff --git a/deployment/modules/mysql/spec/classes/mysql_server_backup_spec.rb b/deployment/modules/mysql/spec/classes/mysql_server_backup_spec.rb new file mode 100644 index 000000000..e0fa36036 --- /dev/null +++ b/deployment/modules/mysql/spec/classes/mysql_server_backup_spec.rb @@ -0,0 +1,112 @@ +require 'spec_helper' + +describe 'mysql::server::backup' do + + let(:default_params) { + { 'backupuser' => 'testuser', + 'backuppassword' => 'testpass', + 'backupdir' => '/tmp', + 'backuprotate' => '25', + 'delete_before_dump' => true, + } + } + context 'standard conditions' do + let(:params) { default_params } + + it { should contain_mysql_user('testuser@localhost')} + + it { should contain_mysql_grant('testuser@localhost/*.*').with( + :privileges => ["SELECT", "RELOAD", "LOCK TABLES", "SHOW VIEW"] + )} + + it { should contain_cron('mysql-backup').with( + :command => '/usr/local/sbin/mysqlbackup.sh', + :ensure => 'present' + )} + + it { should contain_file('mysqlbackup.sh').with( + :path => '/usr/local/sbin/mysqlbackup.sh', + :ensure => 'present' + ) } + + it { should contain_file('mysqlbackupdir').with( + :path => '/tmp', + :ensure => 'directory' + )} + + it 'should have compression by default' do + verify_contents(subject, 'mysqlbackup.sh', [ + ' --all-databases | bzcat -zc > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql.bz2', + ]) + end + + it 'should have 25 days of rotation' do + # MySQL counts from 0 I guess. + should contain_file('mysqlbackup.sh').with_content(/.*ROTATE=24.*/) + end + end + + context 'with compression disabled' do + let(:params) do + { :backupcompress => false }.merge(default_params) + end + + it { should contain_file('mysqlbackup.sh').with( + :path => '/usr/local/sbin/mysqlbackup.sh', + :ensure => 'present' + ) } + + it 'should be able to disable compression' do + verify_contents(subject, 'mysqlbackup.sh', [ + ' --all-databases > ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql', + ]) + end + end + + context 'with database list specified' do + let(:params) do + { :backupdatabases => ['mysql'] }.merge(default_params) + end + + it { should contain_file('mysqlbackup.sh').with( + :path => '/usr/local/sbin/mysqlbackup.sh', + :ensure => 'present' + ) } + + it 'should have a backup file for each database' do + content = catalogue.resource('file','mysqlbackup.sh').send(:parameters)[:content] + content.should match(' mysql | bzcat -zc \${DIR}\\\${PREFIX}mysql_`date') +# verify_contents(subject, 'mysqlbackup.sh', [ +# ' mysql | bzcat -zc ${DIR}/${PREFIX}mysql_`date +%Y%m%d-%H%M%S`.sql', +# ]) + end + end + + context 'with file per database' do + let(:params) do + default_params.merge({ :file_per_database => true }) + end + + it 'should loop through backup all databases' do + verify_contents(subject, 'mysqlbackup.sh', [ + 'mysql -s -r -N -e \'SHOW DATABASES\' | while read dbname', + 'do', + ' mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \\', + ' ${dbname} | bzcat -zc > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql.bz2', + 'done', + ]) + end + + context 'with compression disabled' do + let(:params) do + default_params.merge({ :file_per_database => true, :backupcompress => false }) + end + + it 'should loop through backup all databases without compression' do + verify_contents(subject, 'mysqlbackup.sh', [ + ' ${dbname} > ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql', + ]) + end + end + end +end diff --git a/deployment/modules/mysql/spec/classes/mysql_server_monitor_spec.rb b/deployment/modules/mysql/spec/classes/mysql_server_monitor_spec.rb new file mode 100644 index 000000000..8df9530f0 --- /dev/null +++ b/deployment/modules/mysql/spec/classes/mysql_server_monitor_spec.rb @@ -0,0 +1,31 @@ +require 'spec_helper' +describe 'mysql::server::monitor' do + let :facts do + { :osfamily => 'Debian', :root_home => '/root' } + end + let :pre_condition do + "include 'mysql::server'" + end + + let :default_params do + { + :mysql_monitor_username => 'monitoruser', + :mysql_monitor_password => 'monitorpass', + :mysql_monitor_hostname => 'monitorhost', + } + end + + let :params do + default_params + end + + it { should contain_mysql_user('monitoruser@monitorhost')} + + it { should contain_mysql_grant('monitoruser@monitorhost/*.*').with( + :ensure => 'present', + :user => 'monitoruser@monitorhost', + :table => '*.*', + :privileges => ["PROCESS", "SUPER"], + :require => 'Mysql_user[monitoruser@monitorhost]' + )} +end diff --git a/deployment/modules/mysql/spec/classes/mysql_server_mysqltuner_spec.rb b/deployment/modules/mysql/spec/classes/mysql_server_mysqltuner_spec.rb new file mode 100644 index 000000000..7e9499a65 --- /dev/null +++ b/deployment/modules/mysql/spec/classes/mysql_server_mysqltuner_spec.rb @@ -0,0 +1,5 @@ +describe 'mysql::server::mysqltuner' do + + it { should contain_file('/usr/local/bin/mysqltuner') } + +end diff --git a/deployment/modules/mysql/spec/classes/mysql_server_spec.rb b/deployment/modules/mysql/spec/classes/mysql_server_spec.rb new file mode 100644 index 000000000..19ce57b38 --- /dev/null +++ b/deployment/modules/mysql/spec/classes/mysql_server_spec.rb @@ -0,0 +1,162 @@ +require 'spec_helper' +describe 'mysql::server' do + let(:facts) {{:osfamily => 'RedHat', :root_home => '/root'}} + + context 'with defaults' do + it { should contain_class('mysql::server::install') } + it { should contain_class('mysql::server::config') } + it { should contain_class('mysql::server::service') } + it { should contain_class('mysql::server::root_password') } + it { should contain_class('mysql::server::providers') } + end + + # make sure that overriding the mysqld settings keeps the defaults for everything else + context 'with overrides' do + let(:params) {{ :override_options => { 'mysqld' => { 'socket' => '/var/lib/mysql/mysql.sock' } } }} + it do + should contain_file('/etc/my.cnf').with({ + :mode => '0644', + }).with_content(/basedir/) + end + end + + context 'with remove_default_accounts set' do + let (:params) {{ :remove_default_accounts => true }} + it { should contain_class('mysql::server::account_security') } + end + + context 'mysql::server::install' do + let(:params) {{ :package_ensure => 'present', :name => 'mysql-server' }} + it do + should contain_package('mysql-server').with({ + :ensure => :present, + :name => 'mysql-server', + }) + end + end + + context 'mysql::server::config' do + it do + should contain_file('/etc/mysql').with({ + :ensure => :directory, + :mode => '0755', + }) + end + + it do + should contain_file('/etc/mysql/conf.d').with({ + :ensure => :directory, + :mode => '0755', + }) + end + + it do + should contain_file('/etc/my.cnf').with({ + :mode => '0644', + }) + end + end + + context 'mysql::server::service' do + context 'with defaults' do + it { should contain_service('mysqld') } + end + + context 'service_enabled set to false' do + let(:params) {{ :service_enabled => false }} + + it do + should contain_service('mysqld').with({ + :ensure => :stopped + }) + end + end + end + + context 'mysql::server::root_password' do + describe 'when defaults' do + it { should_not contain_mysql_user('root@localhost') } + it { should_not contain_file('/root/.my.cnf') } + end + describe 'when set' do + let(:params) {{:root_password => 'SET' }} + it { should contain_mysql_user('root@localhost') } + it { should contain_file('/root/.my.cnf') } + end + + end + + context 'mysql::server::providers' do + describe 'with users' do + let(:params) {{:users => { + 'foo@localhost' => { + 'max_connections_per_hour' => '1', + 'max_queries_per_hour' => '2', + 'max_updates_per_hour' => '3', + 'max_user_connections' => '4', + 'password_hash' => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF' + }, + 'foo2@localhost' => {} + }}} + it { should contain_mysql_user('foo@localhost').with( + :max_connections_per_hour => '1', + :max_queries_per_hour => '2', + :max_updates_per_hour => '3', + :max_user_connections => '4', + :password_hash => '*F3A2A51A9B0F2BE2468926B4132313728C250DBF' + )} + it { should contain_mysql_user('foo2@localhost').with( + :max_connections_per_hour => nil, + :max_queries_per_hour => nil, + :max_updates_per_hour => nil, + :max_user_connections => nil, + :password_hash => '' + )} + end + + describe 'with grants' do + let(:params) {{:grants => { + 'foo@localhost/somedb.*' => { + 'user' => 'foo@localhost', + 'table' => 'somedb.*', + 'privileges' => ["SELECT", "UPDATE"], + 'options' => ["GRANT"], + }, + 'foo2@localhost/*.*' => { + 'user' => 'foo2@localhost', + 'table' => '*.*', + 'privileges' => ["SELECT"], + }, + }}} + it { should contain_mysql_grant('foo@localhost/somedb.*').with( + :user => 'foo@localhost', + :table => 'somedb.*', + :privileges => ["SELECT", "UPDATE"], + :options => ["GRANT"] + )} + it { should contain_mysql_grant('foo2@localhost/*.*').with( + :user => 'foo2@localhost', + :table => '*.*', + :privileges => ["SELECT"], + :options => nil + )} + end + + describe 'with databases' do + let(:params) {{:databases => { + 'somedb' => { + 'charset' => 'latin1', + 'collate' => 'latin1', + }, + 'somedb2' => {} + }}} + it { should contain_mysql_database('somedb').with( + :charset => 'latin1', + :collate => 'latin1' + )} + it { should contain_mysql_database('somedb2')} + end + + end + +end diff --git a/deployment/modules/mysql/spec/defines/mysql_db_spec.rb b/deployment/modules/mysql/spec/defines/mysql_db_spec.rb new file mode 100644 index 000000000..a7ee31ff8 --- /dev/null +++ b/deployment/modules/mysql/spec/defines/mysql_db_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +describe 'mysql::db', :type => :define do + let(:facts) {{ :osfamily => 'RedHat' }} + let(:title) { 'test_db' } + + let(:params) { + { 'user' => 'testuser', + 'password' => 'testpass', + } + } + + it 'should report an error when ensure is not present or absent' do + params.merge!({'ensure' => 'invalid_val'}) + expect { subject }.to raise_error(Puppet::Error, + /invalid_val is not supported for ensure\. Allowed values are 'present' and 'absent'\./) + end + + it 'should not notify the import sql exec if no sql script was provided' do + should contain_mysql_database('test_db').without_notify + end + + it 'should subscribe to database if sql script is given' do + params.merge!({'sql' => 'test_sql'}) + should contain_exec('test_db-import').with_subscribe('Mysql_database[test_db]') + end + + it 'should only import sql script on creation if not enforcing' do + params.merge!({'sql' => 'test_sql', 'enforce_sql' => false}) + should contain_exec('test_db-import').with_refreshonly(true) + end + + it 'should import sql script on creation if enforcing' do + params.merge!({'sql' => 'test_sql', 'enforce_sql' => true}) + should contain_exec('test_db-import').with_refreshonly(false) + end + + it 'should not create database and database user' do + params.merge!({'ensure' => 'absent', 'host' => 'localhost'}) + should contain_mysql_database('test_db').with_ensure('absent') + should contain_mysql_user('testuser@localhost').with_ensure('absent') + end + + it 'should create with an appropriate collate and charset' do + params.merge!({'charset' => 'utf8', 'collate' => 'utf8_danish_ci'}) + should contain_mysql_database('test_db').with({ + 'charset' => 'utf8', + 'collate' => 'utf8_danish_ci', + }) + end +end diff --git a/deployment/modules/mysql/spec/spec.opts b/deployment/modules/mysql/spec/spec.opts new file mode 100644 index 000000000..91cd6427e --- /dev/null +++ b/deployment/modules/mysql/spec/spec.opts @@ -0,0 +1,6 @@ +--format +s +--colour +--loadby +mtime +--backtrace diff --git a/deployment/modules/mysql/spec/spec_helper.rb b/deployment/modules/mysql/spec/spec_helper.rb new file mode 100644 index 000000000..1fd2563f5 --- /dev/null +++ b/deployment/modules/mysql/spec/spec_helper.rb @@ -0,0 +1,5 @@ +require 'simplecov' +SimpleCov.start do + add_filter "/spec/" +end +require 'puppetlabs_spec_helper/module_spec_helper' diff --git a/deployment/modules/mysql/spec/spec_helper_system.rb b/deployment/modules/mysql/spec/spec_helper_system.rb new file mode 100644 index 000000000..39516ecb8 --- /dev/null +++ b/deployment/modules/mysql/spec/spec_helper_system.rb @@ -0,0 +1,28 @@ +require 'rspec-system/spec_helper' +require 'rspec-system-puppet/helpers' +require 'rspec-system-serverspec/helpers' + +include RSpecSystemPuppet::Helpers + +include Serverspec::Helper::RSpecSystem +include Serverspec::Helper::DetectOS + +RSpec.configure do |c| + # Project root + proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..')) + + # Enable colour + c.tty = true + + c.include RSpecSystemPuppet::Helpers + + # This is where we 'setup' the nodes before running our tests + c.before :suite do + # Install puppet + puppet_install + + # Install modules and dependencies + puppet_module_install(:source => proj_root, :module_name => 'mysql') + shell('puppet module install puppetlabs-stdlib') + end +end diff --git a/deployment/modules/mysql/spec/system/mysql_account_delete_spec.rb b/deployment/modules/mysql/spec/system/mysql_account_delete_spec.rb new file mode 100644 index 000000000..11f776a05 --- /dev/null +++ b/deployment/modules/mysql/spec/system/mysql_account_delete_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_system' + +describe 'mysql::server::account_security class' do + + describe 'running puppet code' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'mysql::server': remove_default_accounts => true } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + + describe 'accounts' do + it 'should delete accounts' do + shell("mysql -e 'show grants for root@127.0.01;'") do |s| + s.exit_code.should == 1 + end + end + + it 'should delete databases' do + shell("mysql -e 'show databases;' |grep test") do |s| + s.exit_code.should == 1 + end + end + end + end + +end diff --git a/deployment/modules/mysql/spec/system/mysql_backup_spec.rb b/deployment/modules/mysql/spec/system/mysql_backup_spec.rb new file mode 100644 index 000000000..f071c7a8c --- /dev/null +++ b/deployment/modules/mysql/spec/system/mysql_backup_spec.rb @@ -0,0 +1,77 @@ +require 'spec_helper_system' + +describe 'mysql::server::backup class' do + context 'should work with no errors' do + pp = <<-EOS + class { 'mysql::server': override_options => { 'root_password' => 'password' } } + mysql::db { 'backup1': + user => 'backup', + password => 'secret', + } + + class { 'mysql::server::backup': + backupuser => 'myuser', + backuppassword => 'mypassword', + backupdir => '/tmp/backups', + backupcompress => true, + } + EOS + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + + context 'should run mysqlbackup.sh with no errors' do + context shell("/usr/local/sbin/mysqlbackup.sh") do + its(:exit_code) { should be_zero } + end + end + + context 'should dump all databases to single file' do + describe command('ls /tmp/backups/ | grep -c "mysql_backup_[0-9][0-9]*-[0-9][0-9]*.sql.bz2"') do + it { should return_stdout /1/ } + it { should return_exit_status 0 } + end + end + end + + + context 'should create one file per database' do + pp = <<-EOS + class { 'mysql::server': override_options => { 'root_password' => 'password' } } + mysql::db { 'backup1': + user => 'backup', + password => 'secret', + } + + class { 'mysql::server::backup': + backupuser => 'myuser', + backuppassword => 'mypassword', + backupdir => '/tmp/backups', + backupcompress => true, + file_per_database => true, + } + EOS + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + + context shell("/usr/local/sbin/mysqlbackup.sh") do + its(:exit_code) { should be_zero } + end + + describe command('ls /tmp/backups/ | grep -c "mysql_backup_backup1_[0-9][0-9]*-[0-9][0-9]*.sql.bz2"') do + it { should return_stdout /1/ } + it { should return_exit_status 0 } + end + end +end diff --git a/deployment/modules/mysql/spec/system/mysql_bindings_spec.rb b/deployment/modules/mysql/spec/system/mysql_bindings_spec.rb new file mode 100644 index 000000000..694cf574d --- /dev/null +++ b/deployment/modules/mysql/spec/system/mysql_bindings_spec.rb @@ -0,0 +1,90 @@ +require 'spec_helper_system' + +describe 'mysql::bindings class' do + let(:os) { + node.facts['osfamily'] + } + + case node.facts['osfamily'] + when 'RedHat' + java_package = 'mysql-connector-java' + perl_package = 'perl-DBD-MySQL' + python_package = 'MySQL-python' + ruby_package = 'ruby-mysql' + when 'Suse' + java_package = 'mysql-connector-java' + perl_package = 'perl-DBD-MySQL' + python_package = 'python-mysql' + case node.facts['operatingsystem'] + when /OpenSuSE/ + ruby_package = 'rubygem-mysql' + when /(SLES|SLED)/ + ruby_package = 'ruby-mysql' + end + when 'Debian' + java_package = 'libmysql-java' + perl_package = 'libdbd-mysql-perl' + python_package = 'python-mysqldb' + ruby_package = 'libmysql-ruby' + when 'FreeBSD' + java_package = 'databases/mysql-connector-java' + perl_package = 'p5-DBD-mysql' + python_package = 'databases/py-MySQLdb' + ruby_package = 'ruby-mysql' + else + case node.facts['operatingsystem'] + when 'Amazon' + java_package = 'mysql-connector-java' + perl_package = 'perl-DBD-MySQL' + python_package = 'MySQL-python' + ruby_package = 'ruby-mysql' + end + end + + describe 'running puppet code' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'mysql::bindings': } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + end + + describe 'enabling bindings' do + it 'should work with no errors' do + puppet_apply(%{ + class { 'mysql::bindings': + java_enable => true, + perl_enable => true, + python_enable => true, + ruby_enable => true, + } + }) + end + + describe package(java_package) do + it { should be_installed } + end + + describe package(perl_package) do + it { should be_installed } + end + + describe package(python_package) do + it { should be_installed } + end + + describe package(ruby_package) do + it { should be_installed } + end + + end + +end diff --git a/deployment/modules/mysql/spec/system/mysql_db_spec.rb b/deployment/modules/mysql/spec/system/mysql_db_spec.rb new file mode 100644 index 000000000..49299e1dd --- /dev/null +++ b/deployment/modules/mysql/spec/system/mysql_db_spec.rb @@ -0,0 +1,61 @@ +require 'spec_helper_system' + +describe 'mysql::db define' do + describe 'creating a database' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'mysql::server': override_options => { 'root_password' => 'password' } } + mysql::db { 'spec1': + user => 'root1', + password => 'password', + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + [0,2].should include r.exit_code + r.refresh + r.exit_code.should be_zero + end + end + + it 'should have the database' do + shell("mysql -e 'show databases;'|grep spec1") do |s| + s.exit_code.should be_zero + end + end + end + + describe 'creating a database with post-sql' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'mysql::server': override_options => { 'root_password' => 'password' } } + file { '/tmp/spec.sql': + ensure => file, + content => 'CREATE TABLE table1 (id int);', + before => Mysql::Db['spec2'], + } + mysql::db { 'spec2': + user => 'root1', + password => 'password', + sql => '/tmp/spec.sql', + } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + [0,2].should include r.exit_code + r.refresh + r.exit_code.should be_zero + end + end + + it 'should have the table' do + shell("mysql -e 'show tables;' spec2|grep table1") do |s| + s.exit_code.should == 0 + end + end + end +end diff --git a/deployment/modules/mysql/spec/system/mysql_server_monitor_spec.rb b/deployment/modules/mysql/spec/system/mysql_server_monitor_spec.rb new file mode 100644 index 000000000..b7ebd0dff --- /dev/null +++ b/deployment/modules/mysql/spec/system/mysql_server_monitor_spec.rb @@ -0,0 +1,30 @@ +require 'spec_helper_system' + +describe 'mysql::server::monitor class' do + context 'should work with no errors' do + pp = <<-EOS + class { 'mysql::server': root_password => 'password' } + + class { 'mysql::server::monitor': + mysql_monitor_username => 'monitoruser', + mysql_monitor_password => 'monitorpass', + mysql_monitor_hostname => 'localhost', + } + EOS + + context puppet_apply(pp) do + its(:stderr) { should be_empty } + its(:exit_code) { should_not == 1 } + its(:refresh) { should be_nil } + its(:stderr) { should be_empty } + its(:exit_code) { should be_zero } + end + + context 'should run mysqladmin ping with no errors' do + describe command("mysqladmin -u monitoruser -pmonitorpass -h localhost ping") do + it { should return_stdout /mysqld is alive/ } + it { should return_exit_status 0 } + end + end + end +end diff --git a/deployment/modules/mysql/spec/system/mysql_server_root_password_spec.rb b/deployment/modules/mysql/spec/system/mysql_server_root_password_spec.rb new file mode 100644 index 000000000..0c7c3336b --- /dev/null +++ b/deployment/modules/mysql/spec/system/mysql_server_root_password_spec.rb @@ -0,0 +1,71 @@ +require 'spec_helper_system' + +describe 'mysql::server::root_password class' do + + describe 'reset' do + it 'shuts down mysql' do + pp = <<-EOS + class { 'mysql::server': service_enabled => false } + EOS + + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + end + end + + it 'deletes the /root/.my.cnf password' do + shell('rm -rf /root/.my.cnf') + end + + it 'deletes all databases' do + case node.facts['osfamily'] + when 'Redhat' + shell('rm -rf `grep datadir /etc/my.cnf | cut -d" " -f 3`/*') + when 'Debian' + shell('rm -rf `grep datadir /etc/mysql/my.cnf | cut -d" " -f 3`/*') + shell('mysql_install_db') + end + end + + it 'starts up mysql' do + pp = <<-EOS + class { 'mysql::server': service_enabled => true } + EOS + + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + end + end + end + + describe 'when unset' do + it 'should work' do + pp = <<-EOS + class { 'mysql::server': root_password => 'test' } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + end + + describe 'when set' do + it 'should work' do + pp = <<-EOS + class { 'mysql::server': root_password => 'new', old_root_password => 'test' } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + end + +end diff --git a/deployment/modules/mysql/spec/system/mysql_server_spec.rb b/deployment/modules/mysql/spec/system/mysql_server_spec.rb new file mode 100644 index 000000000..bb8707762 --- /dev/null +++ b/deployment/modules/mysql/spec/system/mysql_server_spec.rb @@ -0,0 +1,85 @@ +require 'spec_helper_system' + +describe 'mysql class' do + case node.facts['osfamily'] + when 'RedHat' + package_name = 'mysql-server' + service_name = 'mysqld' + mycnf = '/etc/my.cnf' + when 'Suse' + package_name = 'mysql-community-server' + service_name = 'mysql' + mycnf = '/etc/my.cnf' + when 'Debian' + package_name = 'mysql-server' + service_name = 'mysql' + mycnf = '/etc/mysql/my.cnf' + end + + describe 'running puppet code' do + # Using puppet_apply as a helper + it 'should work with no errors' do + pp = <<-EOS + class { 'mysql::server': } + EOS + + # Run it twice and test for idempotency + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + + describe package(package_name) do + it { should be_installed } + end + + describe service(service_name) do + it { should be_running } + it { should be_enabled } + end + end + + describe 'mycnf' do + it 'should contain sensible values' do + pp = <<-EOS + class { 'mysql::server': } + EOS + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + end + end + + describe file(mycnf) do + it { should contain 'key_buffer = 16M' } + it { should contain 'max_binlog_size = 100M' } + it { should contain 'query_cache_size = 16M' } + end + end + + describe 'my.cnf changes' do + it 'sets values' do + pp = <<-EOS + class { 'mysql::server': + override_options => { 'mysqld' => + { 'key_buffer' => '32M', + 'max_binlog_size' => '200M', + 'query_cache_size' => '32M', + } + } + } + EOS + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + end + end + + describe file(mycnf) do + it { should contain 'key_buffer = 32M' } + it { should contain 'max_binlog_size = 200M' } + it { should contain 'query_cache_size = 32M' } + end + end + +end diff --git a/deployment/modules/mysql/spec/system/types/mysql_grant_spec.rb b/deployment/modules/mysql/spec/system/types/mysql_grant_spec.rb new file mode 100644 index 000000000..a3bdf8282 --- /dev/null +++ b/deployment/modules/mysql/spec/system/types/mysql_grant_spec.rb @@ -0,0 +1,314 @@ +require 'spec_helper_system' + +describe 'mysql_grant' do + + describe 'setup' do + it 'setup mysql::server' do + pp = <<-EOS + class { 'mysql::server': } + EOS + + puppet_apply(pp) + end + end + + describe 'missing privileges for user' do + it 'should fail' do + pp = <<-EOS + mysql_grant { 'test1@tester/test.*': + ensure => 'present', + table => 'test.*', + user => 'test1@tester', + } + EOS + + puppet_apply(pp) do |r| + r.stderr.should =~ /privileges parameter is required/ + end + end + + it 'should not find the user' do + shell("mysql -NBe \"SHOW GRANTS FOR test1@tester\"") do |r| + r.stderr.should =~ /There is no such grant defined for user 'test1' on host 'tester'/ + r.exit_code.should eq 1 + end + end + end + + describe 'missing table for user' do + it 'should fail' do + pp = <<-EOS + mysql_grant { 'atest@tester/test.*': + ensure => 'present', + user => 'atest@tester', + privileges => ['ALL'], + } + EOS + + puppet_apply(pp) do |r| + r.exit_code.should eq 1 + end + end + + it 'should not find the user' do + shell("mysql -NBe \"SHOW GRANTS FOR atest@tester\"") do |r| + r.stderr.should =~ /There is no such grant defined for user 'atest' on host 'tester'/ + r.exit_code.should eq 1 + end + end + end + + describe 'adding privileges' do + it 'should work without errors' do + pp = <<-EOS + mysql_grant { 'test2@tester/test.*': + ensure => 'present', + table => 'test.*', + user => 'test2@tester', + privileges => ['SELECT', 'UPDATE'], + } + EOS + + puppet_apply(pp) + end + + it 'should find the user' do + shell("mysql -NBe \"SHOW GRANTS FOR test2@tester\"") do |r| + r.stdout.should =~ /GRANT SELECT, UPDATE.*TO 'test2'@'tester'/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + end + end + + describe 'adding option' do + it 'should work without errors' do + pp = <<-EOS + mysql_grant { 'test3@tester/test.*': + ensure => 'present', + table => 'test.*', + user => 'test3@tester', + options => ['GRANT'], + privileges => ['SELECT', 'UPDATE'], + } + EOS + + puppet_apply(pp) + end + + it 'should find the user' do + shell("mysql -NBe \"SHOW GRANTS FOR test3@tester\"") do |r| + r.stdout.should =~ /GRANT SELECT, UPDATE ON `test`.* TO 'test3'@'tester' WITH GRANT OPTION$/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + end + end + + describe 'adding all privileges without table' do + it 'should fail' do + pp = <<-EOS + mysql_grant { 'test4@tester/test.*': + ensure => 'present', + user => 'test4@tester', + options => ['GRANT'], + privileges => ['SELECT', 'UPDATE', 'ALL'], + } + EOS + + puppet_apply(pp) do |r| + r.stderr.should =~ /table parameter is required./ + end + end + + end + + + describe 'adding all privileges' do + it 'should only try to apply ALL' do + pp = <<-EOS + mysql_grant { 'test4@tester/test.*': + ensure => 'present', + table => 'test.*', + user => 'test4@tester', + options => ['GRANT'], + privileges => ['SELECT', 'UPDATE', 'ALL'], + } + EOS + + puppet_apply(pp) + end + + it 'should find the user' do + shell("mysql -NBe \"SHOW GRANTS FOR test4@tester\"") do |r| + r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test4'@'tester' WITH GRANT OPTION/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + end + end + + # Test combinations of user@host to ensure all cases work. + describe 'short hostname' do + it 'should apply' do + pp = <<-EOS + mysql_grant { 'test@short/test.*': + ensure => 'present', + table => 'test.*', + user => 'test@short', + privileges => 'ALL', + } + mysql_grant { 'test@long.hostname.com/test.*': + ensure => 'present', + table => 'test.*', + user => 'test@long.hostname.com', + privileges => 'ALL', + } + mysql_grant { 'test@192.168.5.6/test.*': + ensure => 'present', + table => 'test.*', + user => 'test@192.168.5.6', + privileges => 'ALL', + } + mysql_grant { 'test@2607:f0d0:1002:0051:0000:0000:0000:0004/test.*': + ensure => 'present', + table => 'test.*', + user => 'test@2607:f0d0:1002:0051:0000:0000:0000:0004', + privileges => 'ALL', + } + mysql_grant { 'test@::1/128/test.*': + ensure => 'present', + table => 'test.*', + user => 'test@::1/128', + privileges => 'ALL', + } + EOS + + puppet_apply(pp) + end + + it 'finds short hostname' do + shell("mysql -NBe \"SHOW GRANTS FOR test@short\"") do |r| + r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'short'/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + end + it 'finds long hostname' do + shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'long.hostname.com'\"") do |r| + r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'long.hostname.com'/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + end + it 'finds ipv4' do + shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'192.168.5.6'\"") do |r| + r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'192.168.5.6'/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + end + it 'finds ipv6' do + shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'\"") do |r| + r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'2607:f0d0:1002:0051:0000:0000:0000:0004'/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + end + it 'finds short ipv6' do + shell("mysql -NBe \"SHOW GRANTS FOR 'test'@'::1/128'\"") do |r| + r.stdout.should =~ /GRANT ALL PRIVILEGES ON `test`.* TO 'test'@'::1\/128'/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + end + end + + describe 'complex test' do + it 'setup mysql::server' do + pp = <<-EOS + $dbSubnet = '10.10.10.%' + + mysql_database { 'foo': + ensure => present, + } + + exec { 'mysql-create-table': + command => '/usr/bin/mysql -NBe "CREATE TABLE foo.bar (name VARCHAR(20))"', + environment => "HOME=${::root_home}", + unless => '/usr/bin/mysql -NBe "SELECT 1 FROM foo.bar LIMIT 1;"', + require => Mysql_database['foo'], + } + + Mysql_grant { + ensure => present, + options => ['GRANT'], + privileges => ['ALL'], + table => '*.*', + require => [ Mysql_database['foo'], Exec['mysql-create-table'] ], + } + + mysql_grant { "user1@${dbSubnet}/*.*": + user => "user1@${dbSubnet}", + } + mysql_grant { "user2@${dbSubnet}/foo.bar": + privileges => ['SELECT', 'INSERT', 'UPDATE'], + user => "user2@${dbSubnet}", + table => 'foo.bar', + } + mysql_grant { "user3@${dbSubnet}/foo.*": + privileges => ['SELECT', 'INSERT', 'UPDATE'], + user => "user3@${dbSubnet}", + table => 'foo.*', + } + mysql_grant { 'web@%/*.*': + user => 'web@%', + } + mysql_grant { "web@${dbSubnet}/*.*": + user => "web@${dbSubnet}", + } + mysql_grant { "web@${fqdn}/*.*": + user => "web@${fqdn}", + } + mysql_grant { 'web@localhost/*.*': + user => 'web@localhost', + } + EOS + + puppet_apply(pp) do |r| + r.exit_code.should_not == 1 + r.refresh + r.exit_code.should be_zero + end + end + end + + describe 'lower case privileges' do + it 'create ALL privs' do + pp = <<-EOS + mysql_grant { 'lowercase@localhost/*.*': + user => 'lowercase@localhost', + privileges => 'ALL', + table => '*.*', + } + EOS + + puppet_apply(pp) + end + + it 'create lowercase all privs' do + pp = <<-EOS + mysql_grant { 'lowercase@localhost/*.*': + user => 'lowercase@localhost', + privileges => 'all', + table => '*.*', + } + EOS + + puppet_apply(pp) do |r| + r.exit_code.should be_zero + end + end + end + +end diff --git a/deployment/modules/mysql/spec/system/types/mysql_user_spec.rb b/deployment/modules/mysql/spec/system/types/mysql_user_spec.rb new file mode 100644 index 000000000..7aaa9797e --- /dev/null +++ b/deployment/modules/mysql/spec/system/types/mysql_user_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper_system' + +describe 'mysql_user' do + + describe 'setup' do + it 'should work with no errors' do + pp = <<-EOS + class { 'mysql::server': } + EOS + + puppet_apply(pp) + end + end + + describe 'adding user' do + it 'should work without errors' do + pp = <<-EOS + mysql_user { 'ashp@localhost': + password_hash => '6f8c114b58f2ce9e', + } + EOS + + puppet_apply(pp) + end + + it 'should find the user' do + shell("mysql -NBe \"select '1' from mysql.user where CONCAT(user, '@', host) = 'ashp@localhost'\"") do |r| + r.stdout.should =~ /^1$/ + r.stderr.should be_empty + r.exit_code.should be_zero + end + end + end + +end diff --git a/deployment/modules/mysql/spec/unit/mysql_password_spec.rb b/deployment/modules/mysql/spec/unit/mysql_password_spec.rb new file mode 100644 index 000000000..073691004 --- /dev/null +++ b/deployment/modules/mysql/spec/unit/mysql_password_spec.rb @@ -0,0 +1,27 @@ +require 'spec_helper' + +describe 'the mysql_password function' do + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it 'should exist' do + Puppet::Parser::Functions.function('mysql_password').should == 'function_mysql_password' + end + + it 'should raise a ParseError if there is less than 1 arguments' do + lambda { scope.function_mysql_password([]) }.should( raise_error(Puppet::ParseError)) + end + + it 'should raise a ParseError if there is more than 1 arguments' do + lambda { scope.function_mysql_password(%w(foo bar)) }.should( raise_error(Puppet::ParseError)) + end + + it 'should convert password into a hash' do + result = scope.function_mysql_password(%w(password)) + result.should(eq('*2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19')) + end + +end diff --git a/deployment/modules/mysql/spec/unit/puppet/functions/mysql_deepmerge_spec.rb b/deployment/modules/mysql/spec/unit/puppet/functions/mysql_deepmerge_spec.rb new file mode 100644 index 000000000..92577b184 --- /dev/null +++ b/deployment/modules/mysql/spec/unit/puppet/functions/mysql_deepmerge_spec.rb @@ -0,0 +1,77 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:mysql_deepmerge) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + describe 'when calling mysql_deepmerge from puppet' do + it "should not compile when no arguments are passed" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = '$x = mysql_deepmerge()' + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + + it "should not compile when 1 argument is passed" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = "$my_hash={'one' => 1}\n$x = mysql_deepmerge($my_hash)" + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + end + + describe 'when calling mysql_deepmerge on the scope instance' do + it 'should require all parameters are hashes' do + expect { new_hash = scope.function_mysql_deepmerge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/) + expect { new_hash = scope.function_mysql_deepmerge([{}, 2])}.to raise_error(Puppet::ParseError, /unexpected argument type Fixnum/) + end + + it 'should accept empty strings as puppet undef' do + expect { new_hash = scope.function_mysql_deepmerge([{}, ''])}.not_to raise_error + end + + it 'should be able to mysql_deepmerge two hashes' do + new_hash = scope.function_mysql_deepmerge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}]) + new_hash['one'].should == '1' + new_hash['two'].should == '2' + new_hash['three'].should == '2' + end + + it 'should mysql_deepmerge multiple hashes' do + hash = scope.function_mysql_deepmerge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) + hash['one'].should == '3' + end + + it 'should accept empty hashes' do + scope.function_mysql_deepmerge([{},{},{}]).should == {} + end + + it 'should mysql_deepmerge subhashes' do + hash = scope.function_mysql_deepmerge([{'one' => 1}, {'two' => 2, 'three' => { 'four' => 4 } }]) + hash['one'].should == 1 + hash['two'].should == 2 + hash['three'].should == { 'four' => 4 } + end + + it 'should append to subhashes' do + hash = scope.function_mysql_deepmerge([{'one' => { 'two' => 2 } }, { 'one' => { 'three' => 3 } }]) + hash['one'].should == { 'two' => 2, 'three' => 3 } + end + + it 'should append to subhashes 2' do + hash = scope.function_mysql_deepmerge([{'one' => 1, 'two' => 2, 'three' => { 'four' => 4 } }, {'two' => 'dos', 'three' => { 'five' => 5 } }]) + hash['one'].should == 1 + hash['two'].should == 'dos' + hash['three'].should == { 'four' => 4, 'five' => 5 } + end + + it 'should append to subhashes 3' do + hash = scope.function_mysql_deepmerge([{ 'key1' => { 'a' => 1, 'b' => 2 }, 'key2' => { 'c' => 3 } }, { 'key1' => { 'b' => 99 } }]) + hash['key1'].should == { 'a' => 1, 'b' => 99 } + hash['key2'].should == { 'c' => 3 } + end + end +end diff --git a/deployment/modules/mysql/spec/unit/puppet/provider/database/mysql_spec.rb b/deployment/modules/mysql/spec/unit/puppet/provider/database/mysql_spec.rb new file mode 100644 index 000000000..e2557fc35 --- /dev/null +++ b/deployment/modules/mysql/spec/unit/puppet/provider/database/mysql_spec.rb @@ -0,0 +1,86 @@ +require 'spec_helper' + +provider_class = Puppet::Type.type(:database).provider(:mysql) + +describe provider_class do + subject { provider_class } + + let(:root_home) { '/root' } + let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' } + + let(:raw_databases) do + <<-SQL_OUTPUT +information_schema +mydb +mysql +performance_schema +test + SQL_OUTPUT + end + + let(:parsed_databases) { %w(information_schema mydb mysql performance_schema test) } + + before :each do + @resource = Puppet::Type::Database.new( + { :charset => 'utf8', :name => 'new_database' } + ) + @provider = provider_class.new(@resource) + Facter.stubs(:value).with(:root_home).returns(root_home) + Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql') + subject.stubs(:which).with('mysql').returns('/usr/bin/mysql') + subject.stubs(:defaults_file).returns('--defaults-extra-file=/root/.my.cnf') + end + + describe 'self.instances' do + it 'returns an array of databases' do + subject.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns(raw_databases) + + databases = subject.instances.collect {|x| x.name } + parsed_databases.should match_array(databases) + end + end + + describe 'create' do + it 'makes a user' do + subject.expects(:mysql).with([defaults_file, '-NBe', "create database `#{@resource[:name]}` character set #{@resource[:charset]}"]) + @provider.create + end + end + + describe 'destroy' do + it 'removes a user if present' do + subject.expects(:mysqladmin).with([defaults_file, '-f', 'drop', "#{@resource[:name]}"]) + @provider.destroy + end + end + + describe 'charset' do + it 'returns a charset' do + subject.expects(:mysql).with([defaults_file, '-NBe', "show create database `#{@resource[:name]}`"]).returns('mydbCREATE DATABASE `mydb` /*!40100 DEFAULT CHARACTER SET utf8 */') + @provider.charset.should == 'utf8' + end + end + + describe 'charset=' do + it 'changes the charset' do + subject.expects(:mysql).with([defaults_file, '-NBe', "alter database `#{@resource[:name]}` CHARACTER SET blah"]).returns('0') + + @provider.charset=('blah') + end + end + + describe 'exists?' do + it 'checks if user exists' do + subject.expects(:mysql).with([defaults_file, '-NBe', 'show databases']).returns('information_schema\nmydb\nmysql\nperformance_schema\ntest') + @provider.exists? + end + end + + describe 'self.defaults_file' do + it 'sets --defaults-extra-file' do + File.stubs(:file?).with('#{root_home}/.my.cnf').returns(true) + @provider.defaults_file.should == '--defaults-extra-file=/root/.my.cnf' + end + end + +end diff --git a/deployment/modules/mysql/spec/unit/puppet/provider/database_grant/mysql_spec.rb b/deployment/modules/mysql/spec/unit/puppet/provider/database_grant/mysql_spec.rb new file mode 100644 index 000000000..4d9484d04 --- /dev/null +++ b/deployment/modules/mysql/spec/unit/puppet/provider/database_grant/mysql_spec.rb @@ -0,0 +1,95 @@ +require 'puppet' +require 'mocha/api' +require 'spec_helper' +RSpec.configure do |config| + config.mock_with :mocha +end +provider_class = Puppet::Type.type(:database_grant).provider(:mysql) +describe provider_class do + let(:root_home) { '/root' } + + before :each do + @resource = Puppet::Type::Database_grant.new( + { :privileges => 'all', :provider => 'mysql', :name => 'user@host'} + ) + @provider = provider_class.new(@resource) + Facter.stubs(:value).with(:root_home).returns(root_home) + File.stubs(:file?).with("#{root_home}/.my.cnf").returns(true) + end + + it 'should query privileges from the database' do + provider_class.expects(:mysql) .with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'describe user']).returns <<-EOT +Field Type Null Key Default Extra +Host char(60) NO PRI +User char(16) NO PRI +Password char(41) NO +Select_priv enum('N','Y') NO N +Insert_priv enum('N','Y') NO N +Update_priv enum('N','Y') NO N +EOT + provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', 'describe db']).returns <<-EOT +Field Type Null Key Default Extra +Host char(60) NO PRI +Db char(64) NO PRI +User char(16) NO PRI +Select_priv enum('N','Y') NO N +Insert_priv enum('N','Y') NO N +Update_priv enum('N','Y') NO N +EOT + provider_class.user_privs.should == %w(Select_priv Insert_priv Update_priv) + provider_class.db_privs.should == %w(Select_priv Insert_priv Update_priv) + end + + it 'should query set privileges' do + provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "select * from mysql.user where user='user' and host='host'"]).returns <<-EOT +Host User Password Select_priv Insert_priv Update_priv +host user Y N Y +EOT + @provider.privileges.should == %w(Select_priv Update_priv) + end + + it 'should recognize when all privileges are set' do + provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "select * from mysql.user where user='user' and host='host'"]).returns <<-EOT +Host User Password Select_priv Insert_priv Update_priv +host user Y Y Y +EOT + @provider.all_privs_set?.should == true + end + + it 'should recognize when all privileges are not set' do + provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "select * from mysql.user where user='user' and host='host'"]).returns <<-EOT +Host User Password Select_priv Insert_priv Update_priv +host user Y N Y +EOT + @provider.all_privs_set?.should == false + end + + it 'should be able to set all privileges' do + provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n" + provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user='user' and host='host'"]) + provider_class.expects(:mysqladmin).with(%W(--defaults-extra-file=#{root_home}/.my.cnf flush-privileges)) + @provider.privileges=(%w(all)) + end + + it 'should be able to set partial privileges' do + provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n" + provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'N', Update_priv = 'Y' where user='user' and host='host'"]) + provider_class.expects(:mysqladmin).with(%W(--defaults-extra-file=#{root_home}/.my.cnf flush-privileges)) + @provider.privileges=(%w(Select_priv Update_priv)) + end + + it 'should be case insensitive' do + provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n" + provider_class.expects(:mysql).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'Y', Update_priv = 'Y' where user='user' and host='host'"]) + provider_class.expects(:mysqladmin).with(["--defaults-extra-file=#{root_home}/.my.cnf", 'flush-privileges']) + @provider.privileges=(%w(SELECT_PRIV insert_priv UpDaTe_pRiV)) + end + + it 'should not pass --defaults-extra-file if $root_home/.my.cnf is absent' do + File.stubs(:file?).with("#{root_home}/.my.cnf").returns(false) + provider_class.expects(:mysql).with(['mysql', '-NBe', "SELECT '1' FROM user WHERE user='user' AND host='host'"]).returns "1\n" + provider_class.expects(:mysql).with(['mysql', '-Be', "update user set Select_priv = 'Y', Insert_priv = 'N', Update_priv = 'Y' where user='user' and host='host'"]) + provider_class.expects(:mysqladmin).with(%w(flush-privileges)) + @provider.privileges=(%w(Select_priv Update_priv)) + end +end diff --git a/deployment/modules/mysql/spec/unit/puppet/provider/database_user/mysql_spec.rb b/deployment/modules/mysql/spec/unit/puppet/provider/database_user/mysql_spec.rb new file mode 100644 index 000000000..0939fdd22 --- /dev/null +++ b/deployment/modules/mysql/spec/unit/puppet/provider/database_user/mysql_spec.rb @@ -0,0 +1,119 @@ +require 'spec_helper' + +provider_class = Puppet::Type.type(:database_user).provider(:mysql) + +describe provider_class do + subject { provider_class } + + let(:root_home) { '/root' } + let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' } + let(:newhash) { '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5' } + + let(:raw_users) do + <<-SQL_OUTPUT +root@127.0.0.1 +root@::1 +@localhost +debian-sys-maint@localhost +root@localhost +usvn_user@localhost +@vagrant-ubuntu-raring-64 + SQL_OUTPUT + end + + let(:parsed_users) { %w(root@127.0.0.1 root@::1 debian-sys-maint@localhost root@localhost usvn_user@localhost) } + + before :each do + # password hash = mypass + @resource = Puppet::Type::Database_user.new( + { :password_hash => '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4', + :name => 'joe@localhost', + :max_user_connections => '10' + } + ) + @provider = provider_class.new(@resource) + Facter.stubs(:value).with(:root_home).returns(root_home) + Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql') + subject.stubs(:which).with('mysql').returns('/usr/bin/mysql') + subject.stubs(:defaults_file).returns('--defaults-extra-file=/root/.my.cnf') + end + + describe 'self.instances' do + it 'returns an array of users' do + subject.stubs(:mysql).with([defaults_file, 'mysql', "-BNeselect concat(User, '@',Host) as User from mysql.user"]).returns(raw_users) + + usernames = subject.instances.collect {|x| x.name } + parsed_users.should match_array(usernames) + end + end + + describe 'create' do + it 'makes a user' do + subject.expects(:mysql).with([defaults_file, 'mysql', '-e', "grant usage on *.* to 'joe'@'localhost' identified by PASSWORD + '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' with max_user_connections 10"]) + @provider.expects(:exists?).returns(true) + @provider.create.should be_true + end + end + + describe 'destroy' do + it 'removes a user if present' do + subject.expects(:mysql).with([defaults_file, 'mysql', '-e', "drop user 'joe'@'localhost'"]) + @provider.expects(:exists?).returns(false) + @provider.destroy.should be_true + end + end + + describe 'password_hash' do + it 'returns a hash' do + subject.expects(:mysql).with([defaults_file, 'mysql', '-NBe', "select password from mysql.user where CONCAT(user, '@', host) = 'joe@localhost'"]).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4') + @provider.password_hash.should == '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' + end + end + + describe 'password_hash=' do + it 'changes the hash' do + subject.expects(:mysql).with([defaults_file, 'mysql', '-e', "SET PASSWORD FOR 'joe'@'localhost' = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') + + @provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') + @provider.password_hash=('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') + end + end + + describe 'max_user_connections' do + it 'returns max user connections' do + subject.expects(:mysql).with([defaults_file, 'mysql', '-NBe', "select max_user_connections from mysql.user where CONCAT(user, '@', host) = 'joe@localhost'"]).returns('10') + @provider.max_user_connections.should == '10' + end + end + + describe 'max_user_connections=' do + it 'changes max user connections' do + subject.expects(:mysql).with([defaults_file, 'mysql', '-e', "grant usage on *.* to 'joe'@'localhost' with max_user_connections 42"]).returns('0') + @provider.expects(:max_user_connections).returns('42') + @provider.max_user_connections=('42') + end + end + + describe 'exists?' do + it 'checks if user exists' do + subject.expects(:mysql).with([defaults_file, 'mysql', '-NBe', "select '1' from mysql.user where CONCAT(user, '@', host) = 'joe@localhost'"]).returns('1') + @provider.exists?.should be_true + end + end + + describe 'flush' do + it 'removes cached privileges' do + subject.expects(:mysqladmin).with([defaults_file, 'flush-privileges']) + @provider.flush + end + end + + describe 'self.defaults_file' do + it 'sets --defaults-extra-file' do + File.stubs(:file?).with('#{root_home}/.my.cnf').returns(true) + @provider.defaults_file.should == '--defaults-extra-file=/root/.my.cnf' + end + end + +end diff --git a/deployment/modules/mysql/spec/unit/puppet/provider/mysql_database/mysql_spec.rb b/deployment/modules/mysql/spec/unit/puppet/provider/mysql_database/mysql_spec.rb new file mode 100644 index 000000000..4daba6336 --- /dev/null +++ b/deployment/modules/mysql/spec/unit/puppet/provider/mysql_database/mysql_spec.rb @@ -0,0 +1,118 @@ +require 'spec_helper' + +describe Puppet::Type.type(:mysql_database).provider(:mysql) do + + let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' } + + let(:raw_databases) do + <<-SQL_OUTPUT +information_schema +mydb +mysql +performance_schema +test + SQL_OUTPUT + end + + let(:parsed_databases) { %w(information_schema mydb mysql performance_schema test) } + + let(:resource) { Puppet::Type.type(:mysql_database).new( + { :ensure => :present, + :charset => 'latin1', + :collate => 'latin1_swedish_ci', + :name => 'new_database', + :provider => described_class.name + } + )} + let(:provider) { resource.provider } + + before :each do + Facter.stubs(:value).with(:root_home).returns('/root') + Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql') + File.stubs(:file?).with('/root/.my.cnf').returns(true) + provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns('new_database') + provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show variables like "%_database"', 'new_database']).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") + end + + let(:instance) { provider.class.instances.first } + + describe 'self.instances' do + it 'returns an array of databases' do + provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show databases']).returns(raw_databases) + raw_databases.each_line do |db| + provider.class.stubs(:mysql).with([defaults_file, '-NBe', 'show variables like "%_database"', db.chomp]).returns("character_set_database latin1\ncollation_database latin1_swedish_ci\nskip_show_database OFF") + end + databases = provider.class.instances.collect {|x| x.name } + parsed_databases.should match_array(databases) + end + end + + describe 'self.prefetch' do + it 'exists' do + provider.class.instances + provider.class.prefetch({}) + end + end + + describe 'create' do + it 'makes a database' do + provider.expects(:mysql).with([defaults_file, '-NBe', "create database `#{resource[:name]}` character set #{resource[:charset]} collate #{resource[:collate]}"]) + provider.expects(:exists?).returns(true) + provider.create.should be_true + end + end + + describe 'destroy' do + it 'removes a database if present' do + provider.expects(:mysql).with([defaults_file, '-NBe', "drop database `#{resource[:name]}`"]) + provider.expects(:exists?).returns(false) + provider.destroy.should be_true + end + end + + describe 'exists?' do + it 'checks if database exists' do + instance.exists?.should be_true + end + end + + describe 'self.defaults_file' do + it 'sets --defaults-extra-file' do + File.stubs(:file?).with('/root/.my.cnf').returns(true) + provider.defaults_file.should eq '--defaults-extra-file=/root/.my.cnf' + end + it 'fails if file missing' do + File.stubs(:file?).with('/root/.my.cnf').returns(false) + provider.defaults_file.should be_nil + end + end + + describe 'charset' do + it 'returns a charset' do + instance.charset.should == 'latin1' + end + end + + describe 'charset=' do + it 'changes the charset' do + provider.expects(:mysql).with([defaults_file, '-NBe', "alter database `#{resource[:name]}` CHARACTER SET blah"]).returns('0') + + provider.charset=('blah') + end + end + + describe 'collate' do + it 'returns a collate' do + instance.collate.should == 'latin1_swedish_ci' + end + end + + describe 'collate=' do + it 'changes the collate' do + provider.expects(:mysql).with([defaults_file, '-NBe', "alter database `#{resource[:name]}` COLLATE blah"]).returns('0') + + provider.collate=('blah') + end + end + +end diff --git a/deployment/modules/mysql/spec/unit/puppet/provider/mysql_user/mysql_spec.rb b/deployment/modules/mysql/spec/unit/puppet/provider/mysql_user/mysql_spec.rb new file mode 100644 index 000000000..34639c920 --- /dev/null +++ b/deployment/modules/mysql/spec/unit/puppet/provider/mysql_user/mysql_spec.rb @@ -0,0 +1,130 @@ +require 'spec_helper' + +describe Puppet::Type.type(:mysql_user).provider(:mysql) do + let(:defaults_file) { '--defaults-extra-file=/root/.my.cnf' } + let(:newhash) { '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5' } + + let(:raw_users) do + <<-SQL_OUTPUT +root@127.0.0.1 +root@::1 +@localhost +debian-sys-maint@localhost +root@localhost +usvn_user@localhost +@vagrant-ubuntu-raring-64 + SQL_OUTPUT + end + + let(:parsed_users) { %w(root@127.0.0.1 root@::1 @localhost debian-sys-maint@localhost root@localhost usvn_user@localhost @vagrant-ubuntu-raring-64) } + + let(:resource) { Puppet::Type.type(:mysql_user).new( + { :ensure => :present, + :password_hash => '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4', + :name => 'joe@localhost', + :max_user_connections => '10', + :max_connections_per_hour => '10', + :max_queries_per_hour => '10', + :max_updates_per_hour => '10', + :provider => described_class.name + } + )} + let(:provider) { resource.provider } + + before :each do + # Set up the stubs for an instances call. + Facter.stubs(:value).with(:root_home).returns('/root') + Puppet::Util.stubs(:which).with('mysql').returns('/usr/bin/mysql') + File.stubs(:file?).with('/root/.my.cnf').returns(true) + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns('joe@localhost') + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, PASSWORD FROM mysql.user WHERE CONCAT(user, '@', host) = 'joe@localhost'"]).returns('10 10 10 10 *6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4') + end + + let(:instance) { provider.class.instances.first } + + describe 'self.instances' do + it 'returns an array of users' do + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT CONCAT(User, '@',Host) AS User FROM mysql.user"]).returns(raw_users) + parsed_users.each do |user| + provider.class.stubs(:mysql).with([defaults_file, '-NBe', "SELECT MAX_USER_CONNECTIONS, MAX_CONNECTIONS, MAX_QUESTIONS, MAX_UPDATES, PASSWORD FROM mysql.user WHERE CONCAT(user, '@', host) = '#{user}'"]).returns('10 10 10 10 ') + end + + usernames = provider.class.instances.collect {|x| x.name } + parsed_users.should match_array(usernames) + end + end + + describe 'self.prefetch' do + it 'exists' do + provider.class.instances + provider.class.prefetch({}) + end + end + + describe 'create' do + it 'makes a user' do + provider.expects(:mysql).with([defaults_file, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' IDENTIFIED BY PASSWORD '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' WITH MAX_USER_CONNECTIONS 10 MAX_CONNECTIONS_PER_HOUR 10 MAX_QUERIES_PER_HOUR 10 MAX_UPDATES_PER_HOUR 10"]) + provider.expects(:exists?).returns(true) + provider.create.should be_true + end + end + + describe 'destroy' do + it 'removes a user if present' do + provider.expects(:mysql).with([defaults_file, '-e', "DROP USER 'joe'@'localhost'"]) + provider.expects(:exists?).returns(false) + provider.destroy.should be_true + end + end + + describe 'exists?' do + it 'checks if user exists' do + instance.exists?.should be_true + end + end + + describe 'self.defaults_file' do + it 'sets --defaults-extra-file' do + File.stubs(:file?).with('/root/.my.cnf').returns(true) + provider.defaults_file.should eq '--defaults-extra-file=/root/.my.cnf' + end + it 'fails if file missing' do + File.expects(:file?).with('/root/.my.cnf').returns(false) + provider.defaults_file.should be_nil + end + end + + describe 'password_hash' do + it 'returns a hash' do + instance.password_hash.should == '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF4' + end + end + + describe 'password_hash=' do + it 'changes the hash' do + provider.expects(:mysql).with([defaults_file, '-e', "SET PASSWORD FOR 'joe'@'localhost' = '*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5'"]).returns('0') + + provider.expects(:password_hash).returns('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') + provider.password_hash=('*6C8989366EAF75BB670AD8EA7A7FC1176A95CEF5') + end + end + + ['max_user_connections', 'max_connections_per_hour', 'max_queries_per_hour', + 'max_updates_per_hour'].each do |property| + + describe property do + it "returns #{property}" do + instance.send("#{property}".to_sym).should == '10' + end + end + + describe "#{property}=" do + it "changes #{property}" do + provider.expects(:mysql).with([defaults_file, '-e', "GRANT USAGE ON *.* TO 'joe'@'localhost' WITH #{property.upcase} 42"]).returns('0') + provider.expects(property.to_sym).returns('42') + provider.send("#{property}=".to_sym, '42') + end + end + end + +end diff --git a/deployment/modules/mysql/spec/unit/puppet/type/mysql_database_spec.rb b/deployment/modules/mysql/spec/unit/puppet/type/mysql_database_spec.rb new file mode 100644 index 000000000..e2ebd90d4 --- /dev/null +++ b/deployment/modules/mysql/spec/unit/puppet/type/mysql_database_spec.rb @@ -0,0 +1,29 @@ +require 'puppet' +require 'puppet/type/mysql_database' +describe Puppet::Type.type(:mysql_database) do + + before :each do + @user = Puppet::Type.type(:mysql_database).new(:name => 'test', :charset => 'utf8', :collate => 'utf8_blah_ci') + end + + it 'should accept a database name' do + @user[:name].should == 'test' + end + + it 'should accept a charset' do + @user[:charset] = 'latin1' + @user[:charset].should == 'latin1' + end + + it 'should accept a collate' do + @user[:collate] = 'latin1_swedish_ci' + @user[:collate].should == 'latin1_swedish_ci' + end + + it 'should require a name' do + expect { + Puppet::Type.type(:mysql_database).new({}) + }.to raise_error(Puppet::Error, 'Title or name must be provided') + end + +end diff --git a/deployment/modules/mysql/spec/unit/puppet/type/mysql_user_spec.rb b/deployment/modules/mysql/spec/unit/puppet/type/mysql_user_spec.rb new file mode 100644 index 000000000..62aad7aef --- /dev/null +++ b/deployment/modules/mysql/spec/unit/puppet/type/mysql_user_spec.rb @@ -0,0 +1,30 @@ +require 'puppet' +require 'puppet/type/mysql_user' +describe Puppet::Type.type(:mysql_user) do + + before :each do + @user = Puppet::Type.type(:mysql_user).new(:name => 'foo@localhost', :password_hash => 'pass') + end + + it 'should accept a user name' do + @user[:name].should == 'foo@localhost' + end + + it 'should fail with a long user name' do + expect { + Puppet::Type.type(:mysql_user).new({:name => '12345678901234567@localhost', :password_hash => 'pass'}) + }.to raise_error /MySQL usernames are limited to a maximum of 16 characters/ + end + + it 'should accept a password' do + @user[:password_hash] = 'foo' + @user[:password_hash].should == 'foo' + end + + it 'should require a name' do + expect { + Puppet::Type.type(:mysql_user).new({}) + }.to raise_error(Puppet::Error, 'Title or name must be provided') + end + +end diff --git a/deployment/modules/mysql/templates/my.cnf.erb b/deployment/modules/mysql/templates/my.cnf.erb new file mode 100644 index 000000000..826cf7d88 --- /dev/null +++ b/deployment/modules/mysql/templates/my.cnf.erb @@ -0,0 +1,17 @@ +<% @options.sort.map do |k,v| -%> +<% if v.is_a?(Hash) -%> +[<%= k %>] +<% @options[k].sort.map do |ki, vi| -%> +<% if vi == true -%> +<%= ki %> +<% elsif vi and vi != '' -%> +<%= ki %> = <%= vi %> +<% elsif vi -%> +<%= ki %> +<% end -%> +<% end -%> + +<% end -%> +<% end -%> + +!includedir /etc/mysql/conf.d/ diff --git a/deployment/modules/mysql/templates/my.cnf.pass.erb b/deployment/modules/mysql/templates/my.cnf.pass.erb new file mode 100644 index 000000000..99663fccd --- /dev/null +++ b/deployment/modules/mysql/templates/my.cnf.pass.erb @@ -0,0 +1,7 @@ +[client] +user=root +host=localhost +<% unless scope.lookupvar('mysql::server::root_password') == 'UNSET' -%> +password='<%= scope.lookupvar('mysql::server::root_password') %>' +<% end -%> +socket=<%= @options['client']['socket'] -%> diff --git a/deployment/modules/mysql/templates/my.conf.cnf.erb b/deployment/modules/mysql/templates/my.conf.cnf.erb new file mode 100644 index 000000000..04d297429 --- /dev/null +++ b/deployment/modules/mysql/templates/my.conf.cnf.erb @@ -0,0 +1,17 @@ +### MANAGED BY PUPPET ### +<% @settings.sort.each do |section, content| -%> +[<%= section %>] +<% content.sort.each do |key, values| -%> +<% [values].flatten.sort.each do |value| -%> +<%= !value ? '#' : '' %><%= key -%><%= + case value + when true, false + '' + else + " = #{value}" + end +%> +<% end -%> +<% end -%> + +<% end -%> diff --git a/deployment/modules/mysql/templates/mysqlbackup.sh.erb b/deployment/modules/mysql/templates/mysqlbackup.sh.erb new file mode 100644 index 000000000..4752d1026 --- /dev/null +++ b/deployment/modules/mysql/templates/mysqlbackup.sh.erb @@ -0,0 +1,57 @@ +#!/bin/bash +# +# MySQL Backup Script +# Dumps mysql databases to a file for another backup tool to pick up. +# +# MySQL code: +# GRANT SELECT, RELOAD, LOCK TABLES ON *.* TO 'user'@'localhost' +# IDENTIFIED BY 'password'; +# FLUSH PRIVILEGES; +# +##### START CONFIG ################################################### + +USER=<%= @backupuser %> +PASS=<%= @backuppassword %> +DIR=<%= @backupdir %> +ROTATE=<%= [ Integer(@backuprotate) - 1, 0 ].max %> + +PREFIX=mysql_backup_ + +##### STOP CONFIG #################################################### +PATH=/usr/bin:/usr/sbin:/bin:/sbin + +set -o pipefail + +cleanup() +{ + find "${DIR}/" -maxdepth 1 -type f -name "${PREFIX}*.sql*" -mtime +${ROTATE} -print0 | xargs -0 -r rm -f +} + +<% if @delete_before_dump -%> +cleanup + +<% end -%> +<% if @backupdatabases.empty? -%> +<% if @file_per_database -%> +mysql -s -r -N -e 'SHOW DATABASES' | while read dbname +do + mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \ + ${dbname} <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}${dbname}_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> +done +<% else -%> +mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \ + --all-databases <% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> +<% end -%> +<% else -%> +<% @backupdatabases.each do |db| -%> +mysqldump -u${USER} -p${PASS} --opt --flush-logs --single-transaction \ + <%= db %><% if @backupcompress %>| bzcat -zc <% end %>> ${DIR}/${PREFIX}<%= db %>_`date +%Y%m%d-%H%M%S`.sql<% if @backupcompress %>.bz2<% end %> +<% end -%> +<% end -%> + +<% unless @delete_before_dump -%> +if [ $? -eq 0 ] ; then + cleanup +fi +<% end -%> + diff --git a/deployment/modules/mysql/tests/backup.pp b/deployment/modules/mysql/tests/backup.pp new file mode 100644 index 000000000..cb669e6db --- /dev/null +++ b/deployment/modules/mysql/tests/backup.pp @@ -0,0 +1,8 @@ +class { 'mysql::server': + config_hash => {'root_password' => 'password'} +} +class { 'mysql::backup': + backupuser => 'myuser', + backuppassword => 'mypassword', + backupdir => '/tmp/backups', +} diff --git a/deployment/modules/mysql/tests/bindings.pp b/deployment/modules/mysql/tests/bindings.pp new file mode 100644 index 000000000..83af3713a --- /dev/null +++ b/deployment/modules/mysql/tests/bindings.pp @@ -0,0 +1,3 @@ +class { 'mysql::bindings': + php_enable => 'true', +} diff --git a/deployment/modules/mysql/tests/init.pp b/deployment/modules/mysql/tests/init.pp new file mode 100644 index 000000000..846121b7d --- /dev/null +++ b/deployment/modules/mysql/tests/init.pp @@ -0,0 +1 @@ +include mysql diff --git a/deployment/modules/mysql/tests/java.pp b/deployment/modules/mysql/tests/java.pp new file mode 100644 index 000000000..0fc009a6d --- /dev/null +++ b/deployment/modules/mysql/tests/java.pp @@ -0,0 +1 @@ +class { 'mysql::java':} diff --git a/deployment/modules/mysql/tests/mysql_database.pp b/deployment/modules/mysql/tests/mysql_database.pp new file mode 100644 index 000000000..8747f707d --- /dev/null +++ b/deployment/modules/mysql/tests/mysql_database.pp @@ -0,0 +1,12 @@ +class { 'mysql::server': + config_hash => {'root_password' => 'password'} +} +database{ ['test1', 'test2', 'test3']: + ensure => present, + charset => 'utf8', + require => Class['mysql::server'], +} +database{ 'test4': + ensure => present, + charset => 'latin1', +} diff --git a/deployment/modules/mysql/tests/mysql_grant.pp b/deployment/modules/mysql/tests/mysql_grant.pp new file mode 100644 index 000000000..20fe78d6a --- /dev/null +++ b/deployment/modules/mysql/tests/mysql_grant.pp @@ -0,0 +1,5 @@ +mysql_grant{'test1@localhost/redmine.*': + user => 'test1@localhost', + table => 'redmine.*', + privileges => ['UPDATE'], +} diff --git a/deployment/modules/mysql/tests/mysql_user.pp b/deployment/modules/mysql/tests/mysql_user.pp new file mode 100644 index 000000000..f63908431 --- /dev/null +++ b/deployment/modules/mysql/tests/mysql_user.pp @@ -0,0 +1,23 @@ +$mysql_root_pw = 'password' + +class { 'mysql::server': + config_hash => { + root_password => 'password', + } +} + +database_user{ 'redmine@localhost': + ensure => present, + password_hash => mysql_password('redmine'), + require => Class['mysql::server'], +} + +database_user{ 'dan@localhost': + ensure => present, + password_hash => mysql_password('blah') +} + +database_user{ 'dan@%': + ensure => present, + password_hash => mysql_password('blah'), +} diff --git a/deployment/modules/mysql/tests/perl.pp b/deployment/modules/mysql/tests/perl.pp new file mode 100644 index 000000000..87e941751 --- /dev/null +++ b/deployment/modules/mysql/tests/perl.pp @@ -0,0 +1 @@ +include mysql::perl diff --git a/deployment/modules/mysql/tests/python.pp b/deployment/modules/mysql/tests/python.pp new file mode 100644 index 000000000..04f7ffa1a --- /dev/null +++ b/deployment/modules/mysql/tests/python.pp @@ -0,0 +1 @@ +class { 'mysql::python':} diff --git a/deployment/modules/mysql/tests/ruby.pp b/deployment/modules/mysql/tests/ruby.pp new file mode 100644 index 000000000..e84c046a3 --- /dev/null +++ b/deployment/modules/mysql/tests/ruby.pp @@ -0,0 +1 @@ +include mysql::ruby diff --git a/deployment/modules/mysql/tests/server.pp b/deployment/modules/mysql/tests/server.pp new file mode 100644 index 000000000..8afdd00d2 --- /dev/null +++ b/deployment/modules/mysql/tests/server.pp @@ -0,0 +1,3 @@ +class { 'mysql::server': + root_password => 'password', +} diff --git a/deployment/modules/mysql/tests/server/account_security.pp b/deployment/modules/mysql/tests/server/account_security.pp new file mode 100644 index 000000000..de393cce4 --- /dev/null +++ b/deployment/modules/mysql/tests/server/account_security.pp @@ -0,0 +1,4 @@ +class { 'mysql::server': + config_hash => { 'root_password' => 'password', }, +} +class { 'mysql::server::account_security': } diff --git a/deployment/modules/mysql/tests/server/config.pp b/deployment/modules/mysql/tests/server/config.pp new file mode 100644 index 000000000..fe8d86e90 --- /dev/null +++ b/deployment/modules/mysql/tests/server/config.pp @@ -0,0 +1,11 @@ +mysql::server::config { 'testfile': + settings => { + 'mysqld' => { + 'bind-address' => '0.0.0.0', + 'read-only' => true, + }, + 'client' => { + 'port' => '3306' + } + } +} diff --git a/deployment/modules/sshd/files/sshd_config b/deployment/modules/sshd/files/sshd_config new file mode 100755 index 000000000..5a4725e6d --- /dev/null +++ b/deployment/modules/sshd/files/sshd_config @@ -0,0 +1,135 @@ +# $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $ + +# This is the sshd server system-wide configuration file. See +# sshd_config(5) for more information. + +# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin + +# The strategy used for options in the default sshd_config shipped with +# OpenSSH is to specify options with their default value where +# possible, but leave them commented. Uncommented options change a +# default value. + +#Port 22 +#AddressFamily any +#ListenAddress 0.0.0.0 +#ListenAddress :: + +# Disable legacy (protocol version 1) support in the server for new +# installations. In future the default will change to require explicit +# activation of protocol 1 +Protocol 2 + +# HostKey for protocol version 1 +#HostKey /etc/ssh/ssh_host_key +# HostKeys for protocol version 2 +#HostKey /etc/ssh/ssh_host_rsa_key +#HostKey /etc/ssh/ssh_host_dsa_key + +# Lifetime and size of ephemeral version 1 server key +#KeyRegenerationInterval 1h +#ServerKeyBits 1024 + +# Logging +# obsoletes QuietMode and FascistLogging +#SyslogFacility AUTH +SyslogFacility AUTHPRIV +#LogLevel INFO + +# Authentication: + +#LoginGraceTime 2m +PermitRootLogin yes +#StrictModes yes +#MaxAuthTries 6 +#MaxSessions 10 + +#RSAAuthentication yes +PubkeyAuthentication yes +AuthorizedKeysFile .ssh/authorized_keys +#AuthorizedKeysCommand none +#AuthorizedKeysCommandRunAs nobody + +# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts +#RhostsRSAAuthentication no +# similar for protocol version 2 +#HostbasedAuthentication no +# Change to yes if you don't trust ~/.ssh/known_hosts for +# RhostsRSAAuthentication and HostbasedAuthentication +#IgnoreUserKnownHosts no +# Don't read the user's ~/.rhosts and ~/.shosts files +#IgnoreRhosts yes + +# To disable tunneled clear text passwords, change to no here! +#PasswordAuthentication yes +#PermitEmptyPasswords no +PasswordAuthentication yes + +# Change to no to disable s/key passwords +#ChallengeResponseAuthentication yes +ChallengeResponseAuthentication no + +# Kerberos options +#KerberosAuthentication no +#KerberosOrLocalPasswd yes +#KerberosTicketCleanup yes +#KerberosGetAFSToken no +#KerberosUseKuserok yes + +# GSSAPI options +GSSAPIAuthentication no +#GSSAPICleanupCredentials yes +#GSSAPIStrictAcceptorCheck yes +#GSSAPIKeyExchange no + +# Set this to 'yes' to enable PAM authentication, account processing, +# and session processing. If this is enabled, PAM authentication will +# be allowed through the ChallengeResponseAuthentication and +# PasswordAuthentication. Depending on your PAM configuration, +# PAM authentication via ChallengeResponseAuthentication may bypass +# the setting of "PermitRootLogin without-password". +# If you just want the PAM account and session checks to run without +# PAM authentication, then enable this but set PasswordAuthentication +# and ChallengeResponseAuthentication to 'no'. +#UsePAM no +UsePAM yes + +# Accept locale-related environment variables +AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES +AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT +AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE +AcceptEnv XMODIFIERS + +#AllowAgentForwarding yes +#AllowTcpForwarding yes +#GatewayPorts no +X11Forwarding no +#X11DisplayOffset 10 +#X11UseLocalhost yes +#PrintMotd yes +#PrintLastLog yes +#TCPKeepAlive yes +#UseLogin no +#UsePrivilegeSeparation yes +#PermitUserEnvironment no +#Compression delayed +#ClientAliveInterval 0 +#ClientAliveCountMax 3 +#ShowPatchLevel no +UseDNS no +#PidFile /var/run/sshd.pid +#MaxStartups 10 +#PermitTunnel no +#ChrootDirectory none + +# no default banner path +#Banner none + +# override default of no subsystems +Subsystem sftp /usr/libexec/openssh/sftp-server + +# Example of overriding settings on a per-user basis +#Match User anoncvs +# X11Forwarding no +# AllowTcpForwarding no +# ForceCommand cvs server diff --git a/deployment/modules/sshd/manifests/init.pp b/deployment/modules/sshd/manifests/init.pp new file mode 100755 index 000000000..43fc452d5 --- /dev/null +++ b/deployment/modules/sshd/manifests/init.pp @@ -0,0 +1,16 @@ +class sshd { + + package { 'openssh-server': + ensure => latest + } -> file { 'sshdconfig': + notify => Service['ssh'], + name => '/etc/ssh/sshd_config', + owner => 'root', + group => 'root', + mode => '0644', + source => 'puppet:///modules/sshd/sshd_config' + } ~> service { 'ssh': + ensure => 'running', + enable => true + } +} diff --git a/deployment/modules/stdlib/CHANGELOG b/deployment/modules/stdlib/CHANGELOG new file mode 100644 index 000000000..e1a095f63 --- /dev/null +++ b/deployment/modules/stdlib/CHANGELOG @@ -0,0 +1,278 @@ +2013-05-06 - Jeff McCune - 4.1.0 + * (#20582) Restore facter_dot_d to stdlib for PE users (3b887c8) + * (maint) Update Gemfile with GEM_FACTER_VERSION (f44d535) + +2013-05-06 - Alex Cline - 4.1.0 + * Terser method of string to array conversion courtesy of ethooz. (d38bce0) + +2013-05-06 - Alex Cline 4.1.0 + * Refactor ensure_resource expectations (b33cc24) + +2013-05-06 - Alex Cline 4.1.0 + * Changed str-to-array conversion and removed abbreviation. (de253db) + +2013-05-03 - Alex Cline 4.1.0 + * (#20548) Allow an array of resource titles to be passed into the ensure_resource function (e08734a) + +2013-05-02 - Raphaël Pinson - 4.1.0 + * Add a dirname function (2ba9e47) + +2013-04-29 - Mark Smith-Guerrero - 4.1.0 + * (maint) Fix a small typo in hash() description (928036a) + +2013-04-12 - Jeff McCune - 4.0.2 + * Update user information in gemspec to make the intent of the Gem clear. + +2013-04-11 - Jeff McCune - 4.0.1 + * Fix README function documentation (ab3e30c) + +2013-04-11 - Jeff McCune - 4.0.0 + * stdlib 4.0 drops support with Puppet 2.7 + * stdlib 4.0 preserves support with Puppet 3 + +2013-04-11 - Jeff McCune - 4.0.0 + * Add ability to use puppet from git via bundler (9c5805f) + +2013-04-10 - Jeff McCune - 4.0.0 + * (maint) Make stdlib usable as a Ruby GEM (e81a45e) + +2013-04-10 - Erik Dalén - 4.0.0 + * Add a count function (f28550e) + +2013-03-31 - Amos Shapira - 4.0.0 + * (#19998) Implement any2array (7a2fb80) + +2013-03-29 - Steve Huff - 4.0.0 + * (19864) num2bool match fix (8d217f0) + +2013-03-20 - Erik Dalén - 4.0.0 + * Allow comparisons of Numeric and number as String (ff5dd5d) + +2013-03-26 - Richard Soderberg - 4.0.0 + * add suffix function to accompany the prefix function (88a93ac) + +2013-03-19 - Kristof Willaert - 4.0.0 + * Add floor function implementation and unit tests (0527341) + +2012-04-03 - Eric Shamow - 4.0.0 + * (#13610) Add is_function_available to stdlib (961dcab) + +2012-12-17 - Justin Lambert - 4.0.0 + * str2bool should return a boolean if called with a boolean (5d5a4d4) + +2012-10-23 - Uwe Stuehler - 4.0.0 + * Fix number of arguments check in flatten() (e80207b) + +2013-03-11 - Jeff McCune - 4.0.0 + * Add contributing document (96e19d0) + +2013-03-04 - Raphaël Pinson - 4.0.0 + * Add missing documentation for validate_augeas and validate_cmd to README.markdown (a1510a1) + +2013-02-14 - Joshua Hoblitt - 4.0.0 + * (#19272) Add has_element() function (95cf3fe) + +2013-02-07 - Raphaël Pinson - 4.0.0 + * validate_cmd(): Use Puppet::Util::Execution.execute when available (69248df) + +2012-12-06 - Raphaël Pinson - 4.0.0 + * Add validate_augeas function (3a97c23) + +2012-12-06 - Raphaël Pinson - 4.0.0 + * Add validate_cmd function (6902cc5) + +2013-01-14 - David Schmitt - 4.0.0 + * Add geppetto project definition (b3fc0a3) + +2013-01-02 - Jaka Hudoklin - 4.0.0 + * Add getparam function to get defined resource parameters (20e0e07) + +2013-01-05 - Jeff McCune - 4.0.0 + * (maint) Add Travis CI Support (d082046) + +2012-12-04 - Jeff McCune - 4.0.0 + * Clarify that stdlib 3 supports Puppet 3 (3a6085f) + +2012-11-30 - Erik Dalén - 4.0.0 + * maint: style guideline fixes (7742e5f) + +2012-11-09 - James Fryman - 4.0.0 + * puppet-lint cleanup (88acc52) + +2012-11-06 - Joe Julian - 4.0.0 + * Add function, uriescape, to URI.escape strings. Redmine #17459 (fd52b8d) + +2012-09-18 - Chad Metcalf - 3.2.0 + * Add an ensure_packages function. (8a8c09e) + +2012-11-23 - Erik Dalén - 3.2.0 + * (#17797) min() and max() functions (9954133) + +2012-05-23 - Peter Meier - 3.2.0 + * (#14670) autorequire a file_line resource's path (dfcee63) + +2012-11-19 - Joshua Harlan Lifton - 3.2.0 + * Add join_keys_to_values function (ee0f2b3) + +2012-11-17 - Joshua Harlan Lifton - 3.2.0 + * Extend delete function for strings and hashes (7322e4d) + +2012-08-03 - Gary Larizza - 3.2.0 + * Add the pick() function (ba6dd13) + +2012-03-20 - Wil Cooley - 3.2.0 + * (#13974) Add predicate functions for interface facts (f819417) + +2012-11-06 - Joe Julian - 3.2.0 + * Add function, uriescape, to URI.escape strings. Redmine #17459 (70f4a0e) + +2012-10-25 - Jeff McCune - 3.1.1 + * (maint) Fix spec failures resulting from Facter API changes (97f836f) + +2012-10-23 - Matthaus Owens - 3.1.0 + * Add PE facts to stdlib (cdf3b05) + +2012-08-16 - Jeff McCune - 3.0.1 + * Fix accidental removal of facts_dot_d.rb in 3.0.0 release + +2012-08-16 - Jeff McCune - 3.0.0 + * stdlib 3.0 drops support with Puppet 2.6 + * stdlib 3.0 preserves support with Puppet 2.7 + +2012-08-07 - Dan Bode - 3.0.0 + * Add function ensure_resource and defined_with_params (ba789de) + +2012-07-10 - Hailee Kenney - 3.0.0 + * (#2157) Remove facter_dot_d for compatibility with external facts (f92574f) + +2012-04-10 - Chris Price - 3.0.0 + * (#13693) moving logic from local spec_helper to puppetlabs_spec_helper (85f96df) + +2012-10-25 - Jeff McCune - 2.5.1 + * (maint) Fix spec failures resulting from Facter API changes (97f836f) + +2012-10-23 - Matthaus Owens - 2.5.0 + * Add PE facts to stdlib (cdf3b05) + +2012-08-15 - Dan Bode - 2.5.0 + * Explicitly load functions used by ensure_resource (9fc3063) + +2012-08-13 - Dan Bode - 2.5.0 + * Add better docs about duplicate resource failures (97d327a) + +2012-08-13 - Dan Bode - 2.5.0 + * Handle undef for parameter argument (4f8b133) + +2012-08-07 - Dan Bode - 2.5.0 + * Add function ensure_resource and defined_with_params (a0cb8cd) + +2012-08-20 - Jeff McCune - 2.5.0 + * Disable tests that fail on 2.6.x due to #15912 (c81496e) + +2012-08-20 - Jeff McCune - 2.5.0 + * (Maint) Fix mis-use of rvalue functions as statements (4492913) + +2012-08-20 - Jeff McCune - 2.5.0 + * Add .rspec file to repo root (88789e8) + +2012-06-07 - Chris Price - 2.4.0 + * Add support for a 'match' parameter to file_line (a06c0d8) + +2012-08-07 - Erik Dalén - 2.4.0 + * (#15872) Add to_bytes function (247b69c) + +2012-07-19 - Jeff McCune - 2.4.0 + * (Maint) use PuppetlabsSpec::PuppetInternals.scope (master) (deafe88) + +2012-07-10 - Hailee Kenney - 2.4.0 + * (#2157) Make facts_dot_d compatible with external facts (5fb0ddc) + +2012-03-16 - Steve Traylen - 2.4.0 + * (#13205) Rotate array/string randomley based on fqdn, fqdn_rotate() (fef247b) + +2012-05-22 - Peter Meier - 2.3.3 + * fix regression in #11017 properly (f0a62c7) + +2012-05-10 - Jeff McCune - 2.3.3 + * Fix spec tests using the new spec_helper (7d34333) + +2012-05-10 - Puppet Labs - 2.3.2 + * Make file_line default to ensure => present (1373e70) + * Memoize file_line spec instance variables (20aacc5) + * Fix spec tests using the new spec_helper (1ebfa5d) + * (#13595) initialize_everything_for_tests couples modules Puppet ver (3222f35) + * (#13439) Fix MRI 1.9 issue with spec_helper (15c5fd1) + * (#13439) Fix test failures with Puppet 2.6.x (665610b) + * (#13439) refactor spec helper for compatibility with both puppet 2.7 and master (82194ca) + * (#13494) Specify the behavior of zero padded strings (61891bb) + +2012-03-29 Puppet Labs - 2.1.3 +* (#11607) Add Rakefile to enable spec testing +* (#12377) Avoid infinite loop when retrying require json + +2012-03-13 Puppet Labs - 2.3.1 +* (#13091) Fix LoadError bug with puppet apply and puppet_vardir fact + +2012-03-12 Puppet Labs - 2.3.0 +* Add a large number of new Puppet functions +* Backwards compatibility preserved with 2.2.x + +2011-12-30 Puppet Labs - 2.2.1 +* Documentation only release for the Forge + +2011-12-30 Puppet Labs - 2.1.2 +* Documentation only release for PE 2.0.x + +2011-11-08 Puppet Labs - 2.2.0 +* #10285 - Refactor json to use pson instead. +* Maint - Add watchr autotest script +* Maint - Make rspec tests work with Puppet 2.6.4 +* #9859 - Add root_home fact and tests + +2011-08-18 Puppet Labs - 2.1.1 +* Change facts.d paths to match Facter 2.0 paths. +* /etc/facter/facts.d +* /etc/puppetlabs/facter/facts.d + +2011-08-17 Puppet Labs - 2.1.0 +* Add R.I. Pienaar's facts.d custom facter fact +* facts defined in /etc/facts.d and /etc/puppetlabs/facts.d are + automatically loaded now. + +2011-08-04 Puppet Labs - 2.0.0 +* Rename whole_line to file_line +* This is an API change and as such motivating a 2.0.0 release according to semver.org. + +2011-08-04 Puppet Labs - 1.1.0 +* Rename append_line to whole_line +* This is an API change and as such motivating a 1.1.0 release. + +2011-08-04 Puppet Labs - 1.0.0 +* Initial stable release +* Add validate_array and validate_string functions +* Make merge() function work with Ruby 1.8.5 +* Add hash merging function +* Add has_key function +* Add loadyaml() function +* Add append_line native + +2011-06-21 Jeff McCune - 0.1.7 +* Add validate_hash() and getvar() functions + +2011-06-15 Jeff McCune - 0.1.6 +* Add anchor resource type to provide containment for composite classes + +2011-06-03 Jeff McCune - 0.1.5 +* Add validate_bool() function to stdlib + +0.1.4 2011-05-26 Jeff McCune +* Move most stages after main + +0.1.3 2011-05-25 Jeff McCune +* Add validate_re() function + +0.1.2 2011-05-24 Jeff McCune +* Update to add annotated tag + +0.1.1 2011-05-24 Jeff McCune +* Add stdlib::stages class with a standard set of stages diff --git a/deployment/modules/stdlib/CONTRIBUTING.md b/deployment/modules/stdlib/CONTRIBUTING.md new file mode 100644 index 000000000..bd11f636e --- /dev/null +++ b/deployment/modules/stdlib/CONTRIBUTING.md @@ -0,0 +1,65 @@ +# How to contribute + +Third-party patches are essential for keeping stdlib great. We simply can't +access the huge number of platforms and myriad configurations for running +stdlib. We want to keep it as easy as possible to contribute changes that +get things working in your environment. There are a few guidelines that we +need contributors to follow so that we can have a chance of keeping on +top of things. + +## Getting Started + +* Make sure you have a [Redmine account](http://projects.puppetlabs.com) +* Make sure you have a [GitHub account](https://github.com/signup/free) +* Submit a ticket for your issue, assuming one does not already exist. + * Clearly describe the issue including steps to reproduce when it is a bug. + * Make sure you fill in the earliest version that you know has the issue. +* Fork the repository on GitHub + +## Making Changes + +* Create a topic branch from where you want to base your work. + * This is usually the master branch. + * Only target release branches if you are certain your fix must be on that + branch. + * To quickly create a topic branch based on master; `git branch + fix/master/my_contribution master` then checkout the new branch with `git + checkout fix/master/my_contribution`. Please avoid working directly on the + `master` branch. +* Make commits of logical units. +* Check for unnecessary whitespace with `git diff --check` before committing. +* Make sure your commit messages are in the proper format. + +```` + (#99999) Make the example in CONTRIBUTING imperative and concrete + + Without this patch applied the example commit message in the CONTRIBUTING + document is not a concrete example. This is a problem because the + contributor is left to imagine what the commit message should look like + based on a description rather than an example. This patch fixes the + problem by making the example concrete and imperative. + + The first line is a real life imperative statement with a ticket number + from our issue tracker. The body describes the behavior without the patch, + why this is a problem, and how the patch fixes the problem when applied. +```` + +* Make sure you have added the necessary tests for your changes. +* Run _all_ the tests to assure nothing else was accidentally broken. + +## Submitting Changes + +* Sign the [Contributor License Agreement](http://links.puppetlabs.com/cla). +* Push your changes to a topic branch in your fork of the repository. +* Submit a pull request to the repository in the puppetlabs organization. +* Update your Redmine ticket to mark that you have submitted code and are ready for it to be reviewed. + * Include a link to the pull request in the ticket + +# Additional Resources + +* [More information on contributing](http://links.puppetlabs.com/contribute-to-puppet) +* [Bug tracker (Redmine)](http://projects.puppetlabs.com) +* [Contributor License Agreement](http://links.puppetlabs.com/cla) +* [General GitHub documentation](http://help.github.com/) +* [GitHub pull request documentation](http://help.github.com/send-pull-requests/) +* #puppet-dev IRC channel on freenode.org diff --git a/deployment/modules/stdlib/Gemfile b/deployment/modules/stdlib/Gemfile new file mode 100644 index 000000000..197cc6b01 --- /dev/null +++ b/deployment/modules/stdlib/Gemfile @@ -0,0 +1,42 @@ +source "https://rubygems.org" + +def location_for(place, fake_version = nil) + mdata = /^(git:[^#]*)#(.*)/.match(place) + if mdata + [fake_version, { :git => mdata[1], :branch => mdata[2], :require => false }].compact + elsif place =~ /^file:\/\/(.*)/ + ['>= 0', { :path => File.expand_path(mdata[1]), :require => false }] + else + [place, { :require => false }] + end +end + +group :development do + gem 'watchr' +end + +group :development, :test do + gem 'rake' + gem 'puppetmodule-stdlib', ">= 1.0.0", :path => File.expand_path("..", __FILE__) + gem 'rspec', "~> 2.11.0", :require => false + gem 'mocha', "~> 0.10.5", :require => false + gem 'puppetlabs_spec_helper', :require => false + gem 'rspec-puppet', :require => false +end + +facterversion = ENV['GEM_FACTER_VERSION'] +if facterversion + gem 'facter', *location_for(facterversion) +else + gem 'facter', :require => false +end + +ENV['GEM_PUPPET_VERSION'] ||= ENV['PUPPET_GEM_VERSION'] +puppetversion = ENV['GEM_PUPPET_VERSION'] +if puppetversion + gem 'puppet', *location_for(puppetversion) +else + gem 'puppet', :require => false +end + +# vim:ft=ruby diff --git a/deployment/modules/stdlib/LICENSE b/deployment/modules/stdlib/LICENSE new file mode 100644 index 000000000..ec0587c0d --- /dev/null +++ b/deployment/modules/stdlib/LICENSE @@ -0,0 +1,19 @@ +Copyright (C) 2011 Puppet Labs Inc + +and some parts: + +Copyright (C) 2011 Krzysztof Wilczynski + +Puppet Labs can be contacted at: info@puppetlabs.com + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. diff --git a/deployment/modules/stdlib/Modulefile b/deployment/modules/stdlib/Modulefile new file mode 100644 index 000000000..9d2e8c220 --- /dev/null +++ b/deployment/modules/stdlib/Modulefile @@ -0,0 +1,11 @@ +name 'puppetlabs-stdlib' +version '4.1.0' +source 'git://github.com/puppetlabs/puppetlabs-stdlib.git' +author 'puppetlabs' +license 'Apache 2.0' +summary 'Puppet Module Standard Library' +description 'Standard Library for Puppet Modules' +project_page 'https://github.com/puppetlabs/puppetlabs-stdlib' + +## Add dependencies, if any: +# dependency 'username/name', '>= 1.2.0' diff --git a/deployment/modules/stdlib/README.markdown b/deployment/modules/stdlib/README.markdown new file mode 100644 index 000000000..7b45b1700 --- /dev/null +++ b/deployment/modules/stdlib/README.markdown @@ -0,0 +1,1194 @@ +# Puppet Labs Standard Library # + +[![Build Status](https://travis-ci.org/puppetlabs/puppetlabs-stdlib.png?branch=master)](https://travis-ci.org/puppetlabs/puppetlabs-stdlib) + +This module provides a "standard library" of resources for developing Puppet +Modules. This modules will include the following additions to Puppet + + * Stages + * Facts + * Functions + * Defined resource types + * Types + * Providers + +This module is officially curated and provided by Puppet Labs. The modules +Puppet Labs writes and distributes will make heavy use of this standard +library. + +To report or research a bug with any part of this module, please go to +[http://projects.puppetlabs.com/projects/stdlib](http://projects.puppetlabs.com/projects/stdlib) + +# Versions # + +This module follows semver.org (v1.0.0) versioning guidelines. The standard +library module is released as part of [Puppet +Enterprise](http://puppetlabs.com/puppet/puppet-enterprise/) and as a result +older versions of Puppet Enterprise that Puppet Labs still supports will have +bugfix maintenance branches periodically "merged up" into master. The current +list of integration branches are: + + * v2.1.x (v2.1.1 released in PE 1) + * v2.2.x (Never released as part of PE, only to the Forge) + * v2.3.x (Released in PE 2) + * v3.0.x (Never released as part of PE, only to the Forge) + * v4.0.x (Drops support for Puppet 2.7) + * master (mainline development branch) + +The first Puppet Enterprise version including the stdlib module is Puppet +Enterprise 1.2. + +# Compatibility # + +Puppet Versions | < 2.6 | 2.6 | 2.7 | 3.x | +:---------------|:-----:|:---:|:---:|:----: +**stdlib 2.x** | no | **yes** | **yes** | no +**stdlib 3.x** | no | no | **yes** | **yes** +**stdlib 4.x** | no | no | no | **yes** + +The stdlib module does not work with Puppet versions released prior to Puppet +2.6.0. + +## stdlib 2.x ## + +All stdlib releases in the 2.0 major version support Puppet 2.6 and Puppet 2.7. + +## stdlib 3.x ## + +The 3.0 major release of stdlib drops support for Puppet 2.6. Stdlib 3.x +supports Puppet 2 and Puppet 3. + +## stdlib 4.x ## + +The 4.0 major release of stdlib drops support for Puppet 2.7. Stdlib 4.x +supports Puppet 3. Notably, ruby 1.8.5 is no longer supported though ruby +1.8.7, 1.9.3, and 2.0.0 are fully supported. + +# Functions # + +abs +--- +Returns the absolute value of a number, for example -34.56 becomes +34.56. Takes a single integer and float value as an argument. + + +- *Type*: rvalue + +any2array +--------- +This converts any object to an array containing that object. Empty argument +lists are converted to an empty array. Arrays are left untouched. Hashes are +converted to arrays of alternating keys and values. + + +- *Type*: rvalue + +bool2num +-------- +Converts a boolean to a number. Converts the values: +false, f, 0, n, and no to 0 +true, t, 1, y, and yes to 1 + Requires a single boolean or string as an input. + + +- *Type*: rvalue + +capitalize +---------- +Capitalizes the first letter of a string or array of strings. +Requires either a single string or an array as an input. + + +- *Type*: rvalue + +chomp +----- +Removes the record separator from the end of a string or an array of +strings, for example `hello\n` becomes `hello`. +Requires a single string or array as an input. + + +- *Type*: rvalue + +chop +---- +Returns a new string with the last character removed. If the string ends +with `\r\n`, both characters are removed. Applying chop to an empty +string returns an empty string. If you wish to merely remove record +separators then you should use the `chomp` function. +Requires a string or array of strings as input. + + +- *Type*: rvalue + +concat +------ +Appends the contents of array 2 onto array 1. + +*Example:* + + concat(['1','2','3'],['4','5','6']) + +Would result in: + + ['1','2','3','4','5','6'] + + +- *Type*: rvalue + +count +----- +Takes an array as first argument and an optional second argument. +Count the number of elements in array that matches second argument. +If called with only an array it counts the number of elements that are not nil/undef. + + +- *Type*: rvalue + +defined_with_params +------------------- +Takes a resource reference and an optional hash of attributes. + +Returns true if a resource with the specified attributes has already been added +to the catalog, and false otherwise. + + user { 'dan': + ensure => present, + } + + if ! defined_with_params(User[dan], {'ensure' => 'present' }) { + user { 'dan': ensure => present, } + } + + +- *Type*: rvalue + +delete +------ +Deletes all instances of a given element from an array, substring from a +string, or key from a hash. + +*Examples:* + + delete(['a','b','c','b'], 'b') + Would return: ['a','c'] + + delete({'a'=>1,'b'=>2,'c'=>3}, 'b') + Would return: {'a'=>1,'c'=>3} + + delete('abracadabra', 'bra') + Would return: 'acada' + + +- *Type*: rvalue + +delete_at +--------- +Deletes a determined indexed value from an array. + +*Examples:* + + delete_at(['a','b','c'], 1) + +Would return: ['a','c'] + + +- *Type*: rvalue + +dirname +------- +Returns the `dirname` of a path. + +*Examples:* + + dirname('/path/to/a/file.ext') + +Would return: '/path/to/a' + +downcase +-------- +Converts the case of a string or all strings in an array to lower case. + + +- *Type*: rvalue + +empty +----- +Returns true if the variable is empty. + + +- *Type*: rvalue + +ensure_packages +--------------- +Takes a list of packages and only installs them if they don't already exist. + + +- *Type*: statement + +ensure_resource +--------------- +Takes a resource type, title, and a list of attributes that describe a +resource. + + user { 'dan': + ensure => present, + } + +This example only creates the resource if it does not already exist: + + ensure_resource('user, 'dan', {'ensure' => 'present' }) + +If the resource already exists but does not match the specified parameters, +this function will attempt to recreate the resource leading to a duplicate +resource definition error. + +An array of resources can also be passed in and each will be created with +the type and parameters specified if it doesn't already exist. + + ensure_resource('user', ['dan','alex'], {'ensure' => 'present'}) + + + +- *Type*: statement + +flatten +------- +This function flattens any deeply nested arrays and returns a single flat array +as a result. + +*Examples:* + + flatten(['a', ['b', ['c']]]) + +Would return: ['a','b','c'] + + +- *Type*: rvalue + +floor +----- +Returns the largest integer less or equal to the argument. +Takes a single numeric value as an argument. + + +- *Type*: rvalue + +fqdn_rotate +----------- +Rotates an array a random number of times based on a nodes fqdn. + + +- *Type*: rvalue + +get_module_path +--------------- +Returns the absolute path of the specified module for the current +environment. + +Example: + $module_path = get_module_path('stdlib') + + +- *Type*: rvalue + +getparam +-------- +Takes a resource reference and name of the parameter and +returns value of resource's parameter. + +*Examples:* + + define example_resource($param) { + } + + example_resource { "example_resource_instance": + param => "param_value" + } + + getparam(Example_resource["example_resource_instance"], "param") + +Would return: param_value + + +- *Type*: rvalue + +getvar +------ +Lookup a variable in a remote namespace. + +For example: + + $foo = getvar('site::data::foo') + # Equivalent to $foo = $site::data::foo + +This is useful if the namespace itself is stored in a string: + + $datalocation = 'site::data' + $bar = getvar("${datalocation}::bar") + # Equivalent to $bar = $site::data::bar + + +- *Type*: rvalue + +grep +---- +This function searches through an array and returns any elements that match +the provided regular expression. + +*Examples:* + + grep(['aaa','bbb','ccc','aaaddd'], 'aaa') + +Would return: + + ['aaa','aaaddd'] + + +- *Type*: rvalue + +has_interface_with +------------------ +Returns boolean based on kind and value: +* macaddress +* netmask +* ipaddress +* network + +has_interface_with("macaddress", "x:x:x:x:x:x") +has_interface_with("ipaddress", "127.0.0.1") => true +etc. + +If no "kind" is given, then the presence of the interface is checked: +has_interface_with("lo") => true + + +- *Type*: rvalue + +has_ip_address +-------------- +Returns true if the client has the requested IP address on some interface. + +This function iterates through the 'interfaces' fact and checks the +'ipaddress_IFACE' facts, performing a simple string comparison. + + +- *Type*: rvalue + +has_ip_network +-------------- +Returns true if the client has an IP address within the requested network. + +This function iterates through the 'interfaces' fact and checks the +'network_IFACE' facts, performing a simple string comparision. + + +- *Type*: rvalue + +has_key +------- +Determine if a hash has a certain key value. + +Example: + + $my_hash = {'key_one' => 'value_one'} + if has_key($my_hash, 'key_two') { + notice('we will not reach here') + } + if has_key($my_hash, 'key_one') { + notice('this will be printed') + } + + + +- *Type*: rvalue + +hash +---- +This function converts an array into a hash. + +*Examples:* + + hash(['a',1,'b',2,'c',3]) + +Would return: {'a'=>1,'b'=>2,'c'=>3} + + +- *Type*: rvalue + +is_array +-------- +Returns true if the variable passed to this function is an array. + +- *Type*: rvalue + +is_domain_name +-------------- +Returns true if the string passed to this function is a syntactically correct domain name. + +- *Type*: rvalue + +is_float +-------- +Returns true if the variable passed to this function is a float. + +- *Type*: rvalue + +is_function_available +--------------------- +This function accepts a string as an argument, determines whether the +Puppet runtime has access to a function by that name. It returns a +true if the function exists, false if not. + +- *Type*: rvalue + +is_hash +------- +Returns true if the variable passed to this function is a hash. + +- *Type*: rvalue + +is_integer +---------- +Returns true if the variable returned to this string is an integer. + +- *Type*: rvalue + +is_ip_address +------------- +Returns true if the string passed to this function is a valid IP address. + +- *Type*: rvalue + +is_mac_address +-------------- +Returns true if the string passed to this function is a valid mac address. + +- *Type*: rvalue + +is_numeric +---------- +Returns true if the variable passed to this function is a number. + +- *Type*: rvalue + +is_string +--------- +Returns true if the variable passed to this function is a string. + +- *Type*: rvalue + +join +---- +This function joins an array into a string using a seperator. + +*Examples:* + + join(['a','b','c'], ",") + +Would result in: "a,b,c" + +- *Type*: rvalue + +join_keys_to_values +------------------- +This function joins each key of a hash to that key's corresponding value with a +separator. Keys and values are cast to strings. The return value is an array in +which each element is one joined key/value pair. + +*Examples:* + + join_keys_to_values({'a'=>1,'b'=>2}, " is ") + +Would result in: ["a is 1","b is 2"] + +- *Type*: rvalue + +keys +---- +Returns the keys of a hash as an array. + +- *Type*: rvalue + +loadyaml +-------- +Load a YAML file containing an array, string, or hash, and return the data +in the corresponding native data type. + +For example: + + $myhash = loadyaml('/etc/puppet/data/myhash.yaml') + + +- *Type*: rvalue + +lstrip +------ +Strips leading spaces to the left of a string. + +- *Type*: rvalue + +max +--- +Returns the highest value of all arguments. +Requires at least one argument. + +- *Type*: rvalue + +member +------ +This function determines if a variable is a member of an array. + +*Examples:* + + member(['a','b'], 'b') + +Would return: true + + member(['a','b'], 'c') + +Would return: false + +- *Type*: rvalue + +merge +----- +Merges two or more hashes together and returns the resulting hash. + +For example: + + $hash1 = {'one' => 1, 'two', => 2} + $hash2 = {'two' => 'dos', 'three', => 'tres'} + $merged_hash = merge($hash1, $hash2) + # The resulting hash is equivalent to: + # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'} + +When there is a duplicate key, the key in the rightmost hash will "win." + +- *Type*: rvalue + +min +--- +Returns the lowest value of all arguments. +Requires at least one argument. + +- *Type*: rvalue + +num2bool +-------- +This function converts a number or a string representation of a number into a +true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0 +become true. + +- *Type*: rvalue + +parsejson +--------- +This function accepts JSON as a string and converts into the correct Puppet +structure. + +- *Type*: rvalue + +parseyaml +--------- +This function accepts YAML as a string and converts it into the correct +Puppet structure. + +- *Type*: rvalue + +pick +---- +This function is similar to a coalesce function in SQL in that it will return +the first value in a list of values that is not undefined or an empty string +(two things in Puppet that will return a boolean false value). Typically, +this function is used to check for a value in the Puppet Dashboard/Enterprise +Console, and failover to a default value like the following: + + $real_jenkins_version = pick($::jenkins_version, '1.449') + +The value of $real_jenkins_version will first look for a top-scope variable +called 'jenkins_version' (note that parameters set in the Puppet Dashboard/ +Enterprise Console are brought into Puppet as top-scope variables), and, +failing that, will use a default value of 1.449. + +- *Type*: rvalue + +prefix +------ +This function applies a prefix to all elements in an array. + +*Examples:* + + prefix(['a','b','c'], 'p') + +Will return: ['pa','pb','pc'] + +- *Type*: rvalue + +range +----- +When given range in the form of (start, stop) it will extrapolate a range as +an array. + +*Examples:* + + range("0", "9") + +Will return: [0,1,2,3,4,5,6,7,8,9] + + range("00", "09") + +Will return: [0,1,2,3,4,5,6,7,8,9] (Zero padded strings are converted to +integers automatically) + + range("a", "c") + +Will return: ["a","b","c"] + + range("host01", "host10") + +Will return: ["host01", "host02", ..., "host09", "host10"] + +- *Type*: rvalue + +reject +------ +This function searches through an array and rejects all elements that match +the provided regular expression. + +*Examples:* + + reject(['aaa','bbb','ccc','aaaddd'], 'aaa') + +Would return: + + ['bbb','ccc'] + + +- *Type*: rvalue + +reverse +------- +Reverses the order of a string or array. + +- *Type*: rvalue + +rstrip +------ +Strips leading spaces to the right of the string. + +- *Type*: rvalue + +shuffle +------- +Randomizes the order of a string or array elements. + +- *Type*: rvalue + +size +---- +Returns the number of elements in a string or array. + +- *Type*: rvalue + +sort +---- +Sorts strings and arrays lexically. + +- *Type*: rvalue + +squeeze +------- +Returns a new string where runs of the same character that occur in this set +are replaced by a single character. + +- *Type*: rvalue + +str2bool +-------- +This converts a string to a boolean. This attempt to convert strings that +contain things like: y, 1, t, true to 'true' and strings that contain things +like: 0, f, n, false, no to 'false'. + + +- *Type*: rvalue + +str2saltedsha512 +---------------- +This converts a string to a salted-SHA512 password hash (which is used for +OS X versions >= 10.7). Given any simple string, you will get a hex version +of a salted-SHA512 password hash that can be inserted into your Puppet +manifests as a valid password attribute. + + +- *Type*: rvalue + +strftime +-------- +This function returns formatted time. + +*Examples:* + +To return the time since epoch: + + strftime("%s") + +To return the date: + + strftime("%Y-%m-%d") + +*Format meaning:* + + %a - The abbreviated weekday name (``Sun'') + %A - The full weekday name (``Sunday'') + %b - The abbreviated month name (``Jan'') + %B - The full month name (``January'') + %c - The preferred local date and time representation + %C - Century (20 in 2009) + %d - Day of the month (01..31) + %D - Date (%m/%d/%y) + %e - Day of the month, blank-padded ( 1..31) + %F - Equivalent to %Y-%m-%d (the ISO 8601 date format) + %h - Equivalent to %b + %H - Hour of the day, 24-hour clock (00..23) + %I - Hour of the day, 12-hour clock (01..12) + %j - Day of the year (001..366) + %k - hour, 24-hour clock, blank-padded ( 0..23) + %l - hour, 12-hour clock, blank-padded ( 0..12) + %L - Millisecond of the second (000..999) + %m - Month of the year (01..12) + %M - Minute of the hour (00..59) + %n - Newline ( +) + %N - Fractional seconds digits, default is 9 digits (nanosecond) + %3N millisecond (3 digits) + %6N microsecond (6 digits) + %9N nanosecond (9 digits) + %p - Meridian indicator (``AM'' or ``PM'') + %P - Meridian indicator (``am'' or ``pm'') + %r - time, 12-hour (same as %I:%M:%S %p) + %R - time, 24-hour (%H:%M) + %s - Number of seconds since 1970-01-01 00:00:00 UTC. + %S - Second of the minute (00..60) + %t - Tab character ( ) + %T - time, 24-hour (%H:%M:%S) + %u - Day of the week as a decimal, Monday being 1. (1..7) + %U - Week number of the current year, + starting with the first Sunday as the first + day of the first week (00..53) + %v - VMS date (%e-%b-%Y) + %V - Week number of year according to ISO 8601 (01..53) + %W - Week number of the current year, + starting with the first Monday as the first + day of the first week (00..53) + %w - Day of the week (Sunday is 0, 0..6) + %x - Preferred representation for the date alone, no time + %X - Preferred representation for the time alone, no date + %y - Year without a century (00..99) + %Y - Year with century + %z - Time zone as hour offset from UTC (e.g. +0900) + %Z - Time zone name + %% - Literal ``%'' character + + +- *Type*: rvalue + +strip +----- +This function removes leading and trailing whitespace from a string or from +every string inside an array. + +*Examples:* + + strip(" aaa ") + +Would result in: "aaa" + + +- *Type*: rvalue + +suffix +------ +This function applies a suffix to all elements in an array. + +*Examples:* + + suffix(['a','b','c'], 'p') + +Will return: ['ap','bp','cp'] + + +- *Type*: rvalue + +swapcase +-------- +This function will swap the existing case of a string. + +*Examples:* + + swapcase("aBcD") + +Would result in: "AbCd" + + +- *Type*: rvalue + +time +---- +This function will return the current time since epoch as an integer. + +*Examples:* + + time() + +Will return something like: 1311972653 + + +- *Type*: rvalue + +to_bytes +-------- +Converts the argument into bytes, for example 4 kB becomes 4096. +Takes a single string value as an argument. + + +- *Type*: rvalue + +type +---- +Returns the type when passed a variable. Type can be one of: + +* string +* array +* hash +* float +* integer +* boolean + + +- *Type*: rvalue + +unique +------ +This function will remove duplicates from strings and arrays. + +*Examples:* + + unique("aabbcc") + +Will return: + + abc + +You can also use this with arrays: + + unique(["a","a","b","b","c","c"]) + +This returns: + + ["a","b","c"] + + +- *Type*: rvalue + +upcase +------ +Converts a string or an array of strings to uppercase. + +*Examples:* + + upcase("abcd") + +Will return: + + ASDF + + +- *Type*: rvalue + +uriescape +--------- +Urlencodes a string or array of strings. +Requires either a single string or an array as an input. + + +- *Type*: rvalue + +validate_absolute_path +---------------------- +Validate the string represents an absolute path in the filesystem. This function works +for windows and unix style paths. + +The following values will pass: + + $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet" + validate_absolute_path($my_path) + $my_path2 = "/var/lib/puppet" + validate_absolute_path($my_path2) + + +The following values will fail, causing compilation to abort: + + validate_absolute_path(true) + validate_absolute_path([ 'var/lib/puppet', '/var/foo' ]) + validate_absolute_path([ '/var/lib/puppet', 'var/foo' ]) + $undefined = undef + validate_absolute_path($undefined) + + + +- *Type*: statement + +validate_array +-------------- +Validate that all passed values are array data structures. Abort catalog +compilation if any value fails this check. + +The following values will pass: + + $my_array = [ 'one', 'two' ] + validate_array($my_array) + +The following values will fail, causing compilation to abort: + + validate_array(true) + validate_array('some_string') + $undefined = undef + validate_array($undefined) + + + +- *Type*: statement + +validate_augeas +--------------- +Perform validation of a string using an Augeas lens +The first argument of this function should be a string to +test, and the second argument should be the name of the Augeas lens to use. +If Augeas fails to parse the string with the lens, the compilation will +abort with a parse error. + +A third argument can be specified, listing paths which should +not be found in the file. The `$file` variable points to the location +of the temporary file being tested in the Augeas tree. + +For example, if you want to make sure your passwd content never contains +a user `foo`, you could write: + + validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo']) + +Or if you wanted to ensure that no users used the '/bin/barsh' shell, +you could use: + + validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]'] + +If a fourth argument is specified, this will be the error message raised and +seen by the user. + +A helpful error message can be returned like this: + + validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas') + + + +- *Type*: statement + +validate_bool +------------- +Validate that all passed values are either true or false. Abort catalog +compilation if any value fails this check. + +The following values will pass: + + $iamtrue = true + validate_bool(true) + validate_bool(true, true, false, $iamtrue) + +The following values will fail, causing compilation to abort: + + $some_array = [ true ] + validate_bool("false") + validate_bool("true") + validate_bool($some_array) + + + +- *Type*: statement + +validate_cmd +------------ +Perform validation of a string with an external command. +The first argument of this function should be a string to +test, and the second argument should be a path to a test command +taking a file as last argument. If the command, launched against +a tempfile containing the passed string, returns a non-null value, +compilation will abort with a parse error. + +If a third argument is specified, this will be the error message raised and +seen by the user. + +A helpful error message can be returned like this: + +Example: + + validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content') + + + +- *Type*: statement + +validate_hash +------------- +Validate that all passed values are hash data structures. Abort catalog +compilation if any value fails this check. + +The following values will pass: + + $my_hash = { 'one' => 'two' } + validate_hash($my_hash) + +The following values will fail, causing compilation to abort: + + validate_hash(true) + validate_hash('some_string') + $undefined = undef + validate_hash($undefined) + + + +- *Type*: statement + +validate_re +----------- +Perform simple validation of a string against one or more regular +expressions. The first argument of this function should be a string to +test, and the second argument should be a stringified regular expression +(without the // delimiters) or an array of regular expressions. If none +of the regular expressions match the string passed in, compilation will +abort with a parse error. + +If a third argument is specified, this will be the error message raised and +seen by the user. + +The following strings will validate against the regular expressions: + + validate_re('one', '^one$') + validate_re('one', [ '^one', '^two' ]) + +The following strings will fail to validate, causing compilation to abort: + + validate_re('one', [ '^two', '^three' ]) + +A helpful error message can be returned like this: + + validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7') + + + +- *Type*: statement + +validate_slength +---------------- +Validate that the first argument is a string (or an array of strings), and +less/equal to than the length of the second argument. It fails if the first +argument is not a string or array of strings, and if arg 2 is not convertable +to a number. + +The following values will pass: + + validate_slength("discombobulate",17) + validate_slength(["discombobulate","moo"],17) + +The following valueis will not: + + validate_slength("discombobulate",1) + validate_slength(["discombobulate","thermometer"],5) + + + +- *Type*: statement + +validate_string +--------------- +Validate that all passed values are string data structures. Abort catalog +compilation if any value fails this check. + +The following values will pass: + + $my_string = "one two" + validate_string($my_string, 'three') + +The following values will fail, causing compilation to abort: + + validate_string(true) + validate_string([ 'some', 'array' ]) + $undefined = undef + validate_string($undefined) + + +- *Type*: statement + +values +------ +When given a hash this function will return the values of that hash. + +*Examples:* + + $hash = { + 'a' => 1, + 'b' => 2, + 'c' => 3, + } + values($hash) + +This example would return: + + [1,2,3] + + +- *Type*: rvalue + +values_at +--------- +Finds value inside an array based on location. + +The first argument is the array you want to analyze, and the second element can +be a combination of: + +* A single numeric index +* A range in the form of 'start-stop' (eg. 4-9) +* An array combining the above + +*Examples*: + + values_at(['a','b','c'], 2) + +Would return ['c']. + + values_at(['a','b','c'], ["0-1"]) + +Would return ['a','b']. + + values_at(['a','b','c','d','e'], [0, "2-3"]) + +Would return ['a','c','d']. + + +- *Type*: rvalue + +zip +--- +Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments. + +*Example:* + + zip(['1','2','3'],['4','5','6']) + +Would result in: + + ["1", "4"], ["2", "5"], ["3", "6"] + + +- *Type*: rvalue + +*This page autogenerated on 2013-04-11 13:54:25 -0700* diff --git a/deployment/modules/stdlib/README_DEVELOPER.markdown b/deployment/modules/stdlib/README_DEVELOPER.markdown new file mode 100644 index 000000000..04349ed79 --- /dev/null +++ b/deployment/modules/stdlib/README_DEVELOPER.markdown @@ -0,0 +1,35 @@ +Puppet Specific Facts +===================== + +Facter is meant to stand alone and apart from Puppet. However, Facter often +runs inside Puppet and all custom facts included in the stdlib module will +almost always be evaluated in the context of Puppet and Facter working +together. + +Still, we don't want to write custom facts that blow up in the users face if +Puppet is not loaded in memory. This is often the case if the user runs +`facter` without also supplying the `--puppet` flag. + +Ah! But Jeff, the custom fact won't be in the `$LOAD_PATH` unless the user +supplies `--facter`! You might say... + +Not (always) true I say! If the user happens to have a CWD of +`/stdlib/lib` then the facts will automatically be evaluated and +blow up. + +In any event, it's pretty easy to write a fact that has no value if Puppet is +not loaded. Simply do it like this: + + Facter.add(:node_vardir) do + setcode do + # This will be nil if Puppet is not available. + Facter::Util::PuppetSettings.with_puppet do + Puppet[:vardir] + end + end + end + +The `Facter::Util::PuppetSettings.with_puppet` method accepts a block and +yields to it only if the Puppet library is loaded. If the Puppet library is +not loaded, then the method silently returns `nil` which Facter interprets as +an undefined fact value. The net effect is that the fact won't be set. diff --git a/deployment/modules/stdlib/README_SPECS.markdown b/deployment/modules/stdlib/README_SPECS.markdown new file mode 100644 index 000000000..917b6310d --- /dev/null +++ b/deployment/modules/stdlib/README_SPECS.markdown @@ -0,0 +1,7 @@ +NOTE +==== + +This project's specs depend on puppet core, and thus they require the +`puppetlabs_spec_helper` project. For more information please see the README +in that project, which can be found here: [puppetlabs spec +helper](https://github.com/puppetlabs/puppetlabs_spec_helper) diff --git a/deployment/modules/stdlib/RELEASE_PROCESS.markdown b/deployment/modules/stdlib/RELEASE_PROCESS.markdown new file mode 100644 index 000000000..0f9328ed0 --- /dev/null +++ b/deployment/modules/stdlib/RELEASE_PROCESS.markdown @@ -0,0 +1,24 @@ +# Contributing to this module # + + * Work in a topic branch + * Submit a github pull request + * Address any comments / feeback + * Merge into master using --no-ff + +# Releasing this module # + + * This module adheres to http://semver.org/ + * Look for API breaking changes using git diff vX.Y.Z..master + * If no API breaking changes, the minor version may be bumped. + * If there are API breaking changes, the major version must be bumped. + * If there are only small minor changes, the patch version may be bumped. + * Update the CHANGELOG + * Update the Modulefile + * Commit these changes with a message along the lines of "Update CHANGELOG and + Modulefile for release" + * Create an annotated tag with git tag -a vX.Y.Z -m 'version X.Y.Z' (NOTE the + leading v as per semver.org) + * Push the tag with git push origin --tags + * Build a new package with puppet-module or the rake build task if it exists + * Publish the new package to the forge + * Bonus points for an announcement to puppet-users. diff --git a/deployment/modules/stdlib/Rakefile b/deployment/modules/stdlib/Rakefile new file mode 100644 index 000000000..14f1c2462 --- /dev/null +++ b/deployment/modules/stdlib/Rakefile @@ -0,0 +1,2 @@ +require 'rubygems' +require 'puppetlabs_spec_helper/rake_tasks' diff --git a/deployment/modules/stdlib/lib/facter/facter_dot_d.rb b/deployment/modules/stdlib/lib/facter/facter_dot_d.rb new file mode 100644 index 000000000..e414b2077 --- /dev/null +++ b/deployment/modules/stdlib/lib/facter/facter_dot_d.rb @@ -0,0 +1,202 @@ +# A Facter plugin that loads facts from /etc/facter/facts.d +# and /etc/puppetlabs/facter/facts.d. +# +# Facts can be in the form of JSON, YAML or Text files +# and any executable that returns key=value pairs. +# +# In the case of scripts you can also create a file that +# contains a cache TTL. For foo.sh store the ttl as just +# a number in foo.sh.ttl +# +# The cache is stored in /tmp/facts_cache.yaml as a mode +# 600 file and will have the end result of not calling your +# fact scripts more often than is needed + +class Facter::Util::DotD + require 'yaml' + + def initialize(dir="/etc/facts.d", cache_file="/tmp/facts_cache.yml") + @dir = dir + @cache_file = cache_file + @cache = nil + @types = {".txt" => :txt, ".json" => :json, ".yaml" => :yaml} + end + + def entries + Dir.entries(@dir).reject{|f| f =~ /^\.|\.ttl$/}.sort.map {|f| File.join(@dir, f) } + rescue + [] + end + + def fact_type(file) + extension = File.extname(file) + + type = @types[extension] || :unknown + + type = :script if type == :unknown && File.executable?(file) + + return type + end + + def txt_parser(file) + File.readlines(file).each do |line| + if line =~ /^(.+)=(.+)$/ + var = $1; val = $2 + + Facter.add(var) do + setcode { val } + end + end + end + rescue Exception => e + Facter.warn("Failed to handle #{file} as text facts: #{e.class}: #{e}") + end + + def json_parser(file) + begin + require 'json' + rescue LoadError + retry if require 'rubygems' + raise + end + + JSON.load(File.read(file)).each_pair do |f, v| + Facter.add(f) do + setcode { v } + end + end + rescue Exception => e + Facter.warn("Failed to handle #{file} as json facts: #{e.class}: #{e}") + end + + def yaml_parser(file) + require 'yaml' + + YAML.load_file(file).each_pair do |f, v| + Facter.add(f) do + setcode { v } + end + end + rescue Exception => e + Facter.warn("Failed to handle #{file} as yaml facts: #{e.class}: #{e}") + end + + def script_parser(file) + result = cache_lookup(file) + ttl = cache_time(file) + + unless result + result = Facter::Util::Resolution.exec(file) + + if ttl > 0 + Facter.debug("Updating cache for #{file}") + cache_store(file, result) + cache_save! + end + else + Facter.debug("Using cached data for #{file}") + end + + result.split("\n").each do |line| + if line =~ /^(.+)=(.+)$/ + var = $1; val = $2 + + Facter.add(var) do + setcode { val } + end + end + end + rescue Exception => e + Facter.warn("Failed to handle #{file} as script facts: #{e.class}: #{e}") + Facter.debug(e.backtrace.join("\n\t")) + end + + def cache_save! + cache = load_cache + File.open(@cache_file, "w", 0600) {|f| f.write(YAML.dump(cache)) } + rescue + end + + def cache_store(file, data) + load_cache + + @cache[file] = {:data => data, :stored => Time.now.to_i} + rescue + end + + def cache_lookup(file) + cache = load_cache + + return nil if cache.empty? + + ttl = cache_time(file) + + if cache[file] + now = Time.now.to_i + + return cache[file][:data] if ttl == -1 + return cache[file][:data] if (now - cache[file][:stored]) <= ttl + return nil + else + return nil + end + rescue + return nil + end + + def cache_time(file) + meta = file + ".ttl" + + return File.read(meta).chomp.to_i + rescue + return 0 + end + + def load_cache + unless @cache + if File.exist?(@cache_file) + @cache = YAML.load_file(@cache_file) + else + @cache = {} + end + end + + return @cache + rescue + @cache = {} + return @cache + end + + def create + entries.each do |fact| + type = fact_type(fact) + parser = "#{type}_parser" + + if respond_to?("#{type}_parser") + Facter.debug("Parsing #{fact} using #{parser}") + + send(parser, fact) + end + end + end +end + + +mdata = Facter.version.match(/(\d+)\.(\d+)\.(\d+)/) +if mdata + (major, minor, patch) = mdata.captures.map { |v| v.to_i } + if major < 2 + # Facter 1.7 introduced external facts support directly + unless major == 1 and minor > 6 + Facter::Util::DotD.new("/etc/facter/facts.d").create + Facter::Util::DotD.new("/etc/puppetlabs/facter/facts.d").create + + # Windows has a different configuration directory that defaults to a vendor + # specific sub directory of the %COMMON_APPDATA% directory. + if Dir.const_defined? 'COMMON_APPDATA' then + windows_facts_dot_d = File.join(Dir::COMMON_APPDATA, 'PuppetLabs', 'facter', 'facts.d') + Facter::Util::DotD.new(windows_facts_dot_d).create + end + end + end +end diff --git a/deployment/modules/stdlib/lib/facter/pe_version.rb b/deployment/modules/stdlib/lib/facter/pe_version.rb new file mode 100644 index 000000000..0cc0f64e9 --- /dev/null +++ b/deployment/modules/stdlib/lib/facter/pe_version.rb @@ -0,0 +1,53 @@ +# Fact: is_pe, pe_version, pe_major_version, pe_minor_version, pe_patch_version +# +# Purpose: Return various facts about the PE state of the system +# +# Resolution: Uses a regex match against puppetversion to determine whether the +# machine has Puppet Enterprise installed, and what version (overall, major, +# minor, patch) is installed. +# +# Caveats: +# +Facter.add("pe_version") do + setcode do + pe_ver = Facter.value("puppetversion").match(/Puppet Enterprise (\d+\.\d+\.\d+)/) + pe_ver[1] if pe_ver + end +end + +Facter.add("is_pe") do + setcode do + if Facter.value(:pe_version).to_s.empty? then + false + else + true + end + end +end + +Facter.add("pe_major_version") do + confine :is_pe => true + setcode do + if pe_version = Facter.value(:pe_version) + pe_version.to_s.split('.')[0] + end + end +end + +Facter.add("pe_minor_version") do + confine :is_pe => true + setcode do + if pe_version = Facter.value(:pe_version) + pe_version.to_s.split('.')[1] + end + end +end + +Facter.add("pe_patch_version") do + confine :is_pe => true + setcode do + if pe_version = Facter.value(:pe_version) + pe_version.to_s.split('.')[2] + end + end +end diff --git a/deployment/modules/stdlib/lib/facter/puppet_vardir.rb b/deployment/modules/stdlib/lib/facter/puppet_vardir.rb new file mode 100644 index 000000000..0e6af40e4 --- /dev/null +++ b/deployment/modules/stdlib/lib/facter/puppet_vardir.rb @@ -0,0 +1,26 @@ +# This facter fact returns the value of the Puppet vardir setting for the node +# running puppet or puppet agent. The intent is to enable Puppet modules to +# automatically have insight into a place where they can place variable data, +# regardless of the node's platform. +# +# The value should be directly usable in a File resource path attribute. + + +begin + require 'facter/util/puppet_settings' +rescue LoadError => e + # puppet apply does not add module lib directories to the $LOAD_PATH (See + # #4248). It should (in the future) but for the time being we need to be + # defensive which is what this rescue block is doing. + rb_file = File.join(File.dirname(__FILE__), 'util', 'puppet_settings.rb') + load rb_file if File.exists?(rb_file) or raise e +end + +Facter.add(:puppet_vardir) do + setcode do + # This will be nil if Puppet is not available. + Facter::Util::PuppetSettings.with_puppet do + Puppet[:vardir] + end + end +end diff --git a/deployment/modules/stdlib/lib/facter/root_home.rb b/deployment/modules/stdlib/lib/facter/root_home.rb new file mode 100644 index 000000000..8249f7d02 --- /dev/null +++ b/deployment/modules/stdlib/lib/facter/root_home.rb @@ -0,0 +1,19 @@ +# A facter fact to determine the root home directory. +# This varies on PE supported platforms and may be +# reconfigured by the end user. + +module Facter::Util::RootHome + class << self + def get_root_home + root_ent = Facter::Util::Resolution.exec("getent passwd root") + # The home directory is the sixth element in the passwd entry + # If the platform doesn't have getent, root_ent will be nil and we should + # return it straight away. + root_ent && root_ent.split(":")[5] + end + end +end + +Facter.add(:root_home) do + setcode { Facter::Util::RootHome.get_root_home } +end diff --git a/deployment/modules/stdlib/lib/facter/util/puppet_settings.rb b/deployment/modules/stdlib/lib/facter/util/puppet_settings.rb new file mode 100644 index 000000000..1ad945218 --- /dev/null +++ b/deployment/modules/stdlib/lib/facter/util/puppet_settings.rb @@ -0,0 +1,21 @@ +module Facter + module Util + module PuppetSettings + # This method is intended to provide a convenient way to evaluate a + # Facter code block only if Puppet is loaded. This is to account for the + # situation where the fact happens to be in the load path, but Puppet is + # not loaded for whatever reason. Perhaps the user is simply running + # facter without the --puppet flag and they happen to be working in a lib + # directory of a module. + def self.with_puppet + begin + Module.const_get("Puppet") + rescue NameError + nil + else + yield + end + end + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/abs.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/abs.rb new file mode 100644 index 000000000..11d2d7fea --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/abs.rb @@ -0,0 +1,36 @@ +# +# abs.rb +# + +module Puppet::Parser::Functions + newfunction(:abs, :type => :rvalue, :doc => <<-EOS + Returns the absolute value of a number, for example -34.56 becomes + 34.56. Takes a single integer and float value as an argument. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "abs(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + + # Numbers in Puppet are often string-encoded which is troublesome ... + if value.is_a?(String) + if value.match(/^-?(?:\d+)(?:\.\d+){1}$/) + value = value.to_f + elsif value.match(/^-?\d+$/) + value = value.to_i + else + raise(Puppet::ParseError, 'abs(): Requires float or ' + + 'integer to work with') + end + end + + # We have numeric value to handle ... + result = value.abs + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/any2array.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/any2array.rb new file mode 100644 index 000000000..e71407e89 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/any2array.rb @@ -0,0 +1,33 @@ +# +# any2array.rb +# + +module Puppet::Parser::Functions + newfunction(:any2array, :type => :rvalue, :doc => <<-EOS +This converts any object to an array containing that object. Empty argument +lists are converted to an empty array. Arrays are left untouched. Hashes are +converted to arrays of alternating keys and values. + EOS + ) do |arguments| + + if arguments.empty? + return [] + end + + if arguments.length == 1 + if arguments[0].kind_of?(Array) + return arguments[0] + elsif arguments[0].kind_of?(Hash) + result = [] + arguments[0].each do |key, value| + result << key << value + end + return result + end + end + + return arguments + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/bool2num.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/bool2num.rb new file mode 100644 index 000000000..9a07a8a11 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/bool2num.rb @@ -0,0 +1,49 @@ +# +# bool2num.rb +# + +module Puppet::Parser::Functions + newfunction(:bool2num, :type => :rvalue, :doc => <<-EOS + Converts a boolean to a number. Converts the values: + false, f, 0, n, and no to 0 + true, t, 1, y, and yes to 1 + Requires a single boolean or string as an input. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "bool2num(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + # We can have either true or false, or string which resembles boolean ... + unless [FalseClass, TrueClass, String].include?(klass) + raise(Puppet::ParseError, 'bool2num(): Requires either ' + + 'boolean or string to work with') + end + + if value.is_a?(String) + # We consider all the yes, no, y, n and so on too ... + value = case value + # + # This is how undef looks like in Puppet ... + # We yield 0 (or false if you wish) in this case. + # + when /^$/, '' then false # Empty string will be false ... + when /^(1|t|y|true|yes)$/ then true + when /^(0|f|n|false|no)$/ then false + when /^(undef|undefined)$/ then false # This is not likely to happen ... + else + raise(Puppet::ParseError, 'bool2num(): Unknown type of boolean given') + end + end + + # We have real boolean values as well ... + result = value ? 1 : 0 + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/capitalize.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/capitalize.rb new file mode 100644 index 000000000..640d00b82 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/capitalize.rb @@ -0,0 +1,34 @@ +# +# capitalize.rb +# + +module Puppet::Parser::Functions + newfunction(:capitalize, :type => :rvalue, :doc => <<-EOS + Capitalizes the first letter of a string or array of strings. + Requires either a single string or an array as an input. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "capitalize(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'capitalize(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.capitalize : i } + else + result = value.capitalize + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/chomp.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/chomp.rb new file mode 100644 index 000000000..4564a000a --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/chomp.rb @@ -0,0 +1,35 @@ +# +# chomp.rb +# + +module Puppet::Parser::Functions + newfunction(:chomp, :type => :rvalue, :doc => <<-'EOS' + Removes the record separator from the end of a string or an array of + strings, for example `hello\n` becomes `hello`. + Requires a single string or array as an input. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "chomp(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'chomp(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.chomp : i } + else + result = value.chomp + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/chop.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/chop.rb new file mode 100644 index 000000000..f242af39c --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/chop.rb @@ -0,0 +1,37 @@ +# +# chop.rb +# + +module Puppet::Parser::Functions + newfunction(:chop, :type => :rvalue, :doc => <<-'EOS' + Returns a new string with the last character removed. If the string ends + with `\r\n`, both characters are removed. Applying chop to an empty + string returns an empty string. If you wish to merely remove record + separators then you should use the `chomp` function. + Requires a string or array of strings as input. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "chop(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'chop(): Requires either an ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.chop : i } + else + result = value.chop + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/concat.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/concat.rb new file mode 100644 index 000000000..c86aa0057 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/concat.rb @@ -0,0 +1,37 @@ +# +# concat.rb +# + +module Puppet::Parser::Functions + newfunction(:concat, :type => :rvalue, :doc => <<-EOS +Appends the contents of array 2 onto array 1. + +*Example:* + + concat(['1','2','3'],['4','5','6']) + +Would result in: + + ['1','2','3','4','5','6'] + EOS + ) do |arguments| + + # Check that 2 arguments have been given ... + raise(Puppet::ParseError, "concat(): Wrong number of arguments " + + "given (#{arguments.size} for 2)") if arguments.size != 2 + + a = arguments[0] + b = arguments[1] + + # Check that both args are arrays. + unless a.is_a?(Array) and b.is_a?(Array) + raise(Puppet::ParseError, 'concat(): Requires array to work with') + end + + result = a.concat(b) + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/count.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/count.rb new file mode 100644 index 000000000..52de1b8a5 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/count.rb @@ -0,0 +1,22 @@ +module Puppet::Parser::Functions + newfunction(:count, :type => :rvalue, :arity => -2, :doc => <<-EOS +Takes an array as first argument and an optional second argument. +Count the number of elements in array that matches second argument. +If called with only an array it counts the number of elements that are not nil/undef. + EOS + ) do |args| + + if (args.size > 2) then + raise(ArgumentError, "count(): Wrong number of arguments "+ + "given #{args.size} for 1 or 2.") + end + + collection, item = args + + if item then + collection.count item + else + collection.count { |obj| obj != nil && obj != :undef && obj != '' } + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb new file mode 100644 index 000000000..d7df306c7 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/defined_with_params.rb @@ -0,0 +1,35 @@ +# Test whether a given class or definition is defined +require 'puppet/parser/functions' + +Puppet::Parser::Functions.newfunction(:defined_with_params, + :type => :rvalue, + :doc => <<-'ENDOFDOC' +Takes a resource reference and an optional hash of attributes. + +Returns true if a resource with the specified attributes has already been added +to the catalog, and false otherwise. + + user { 'dan': + ensure => present, + } + + if ! defined_with_params(User[dan], {'ensure' => 'present' }) { + user { 'dan': ensure => present, } + } +ENDOFDOC +) do |vals| + reference, params = vals + raise(ArgumentError, 'Must specify a reference') unless reference + if (! params) || params == '' + params = {} + end + ret = false + if resource = findresource(reference.to_s) + matches = params.collect do |key, value| + resource[key] == value + end + ret = params.empty? || !matches.include?(false) + end + Puppet.debug("Resource #{reference} was not determined to be defined") + ret +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/delete.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/delete.rb new file mode 100644 index 000000000..f81434409 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/delete.rb @@ -0,0 +1,46 @@ +# +# delete.rb +# + +# TODO(Krzysztof Wilczynski): We need to add support for regular expression ... + +module Puppet::Parser::Functions + newfunction(:delete, :type => :rvalue, :doc => <<-EOS +Deletes all instances of a given element from an array, substring from a +string, or key from a hash. + +*Examples:* + + delete(['a','b','c','b'], 'b') + Would return: ['a','c'] + + delete({'a'=>1,'b'=>2,'c'=>3}, 'b') + Would return: {'a'=>1,'c'=>3} + + delete('abracadabra', 'bra') + Would return: 'acada' + EOS + ) do |arguments| + + if (arguments.size != 2) then + raise(Puppet::ParseError, "delete(): Wrong number of arguments "+ + "given #{arguments.size} for 2.") + end + + collection = arguments[0] + item = arguments[1] + + case collection + when Array, Hash + collection.delete item + when String + collection.gsub! item, '' + else + raise(TypeError, "delete(): First argument must be an Array, " + + "String, or Hash. Given an argument of class #{collection.class}.") + end + collection + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/delete_at.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/delete_at.rb new file mode 100644 index 000000000..3eb4b5375 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/delete_at.rb @@ -0,0 +1,49 @@ +# +# delete_at.rb +# + +module Puppet::Parser::Functions + newfunction(:delete_at, :type => :rvalue, :doc => <<-EOS +Deletes a determined indexed value from an array. + +*Examples:* + + delete_at(['a','b','c'], 1) + +Would return: ['a','c'] + EOS + ) do |arguments| + + raise(Puppet::ParseError, "delete_at(): Wrong number of arguments " + + "given (#{arguments.size} for 2)") if arguments.size < 2 + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'delete_at(): Requires array to work with') + end + + index = arguments[1] + + if index.is_a?(String) and not index.match(/^\d+$/) + raise(Puppet::ParseError, 'delete_at(): You must provide ' + + 'non-negative numeric index') + end + + result = array.clone + + # Numbers in Puppet are often string-encoded which is troublesome ... + index = index.to_i + + if index > result.size - 1 # First element is at index 0 is it not? + raise(Puppet::ParseError, 'delete_at(): Given index ' + + 'exceeds size of array given') + end + + result.delete_at(index) # We ignore the element that got deleted ... + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/dirname.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/dirname.rb new file mode 100644 index 000000000..ea8cc1e08 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/dirname.rb @@ -0,0 +1,15 @@ +module Puppet::Parser::Functions + newfunction(:dirname, :type => :rvalue, :doc => <<-EOS + Returns the dirname of a path. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "dirname(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + path = arguments[0] + return File.dirname(path) + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/downcase.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/downcase.rb new file mode 100644 index 000000000..4066d210f --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/downcase.rb @@ -0,0 +1,33 @@ +# +# downcase.rb +# + +module Puppet::Parser::Functions + newfunction(:downcase, :type => :rvalue, :doc => <<-EOS +Converts the case of a string or all strings in an array to lower case. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "downcase(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'downcase(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.downcase : i } + else + result = value.downcase + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/empty.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/empty.rb new file mode 100644 index 000000000..80ebb86b8 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/empty.rb @@ -0,0 +1,28 @@ +# +# empty.rb +# + +module Puppet::Parser::Functions + newfunction(:empty, :type => :rvalue, :doc => <<-EOS +Returns true if the variable is empty. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "empty(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, Hash, String].include?(klass) + raise(Puppet::ParseError, 'empty(): Requires either ' + + 'array, hash or string to work with') + end + + result = value.empty? + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb new file mode 100644 index 000000000..450ea026d --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/ensure_packages.rb @@ -0,0 +1,24 @@ +# +# ensure_packages.rb +# +require 'puppet/parser/functions' + +module Puppet::Parser::Functions + newfunction(:ensure_packages, :type => :statement, :doc => <<-EOS +Takes a list of packages and only installs them if they don't already exist. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "ensure_packages(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size != 1 + raise(Puppet::ParseError, "ensure_packages(): Requires array " + + "given (#{arguments[0].class})") if !arguments[0].kind_of?(Array) + + Puppet::Parser::Functions.function(:ensure_resource) + arguments[0].each { |package_name| + function_ensure_resource(['package', package_name, {'ensure' => 'present' } ]) + } + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb new file mode 100644 index 000000000..a9a17338e --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/ensure_resource.rb @@ -0,0 +1,45 @@ +# Test whether a given class or definition is defined +require 'puppet/parser/functions' + +Puppet::Parser::Functions.newfunction(:ensure_resource, + :type => :statement, + :doc => <<-'ENDOFDOC' +Takes a resource type, title, and a list of attributes that describe a +resource. + + user { 'dan': + ensure => present, + } + +This example only creates the resource if it does not already exist: + + ensure_resource('user, 'dan', {'ensure' => 'present' }) + +If the resource already exists but does not match the specified parameters, +this function will attempt to recreate the resource leading to a duplicate +resource definition error. + +An array of resources can also be passed in and each will be created with +the type and parameters specified if it doesn't already exist. + + ensure_resource('user', ['dan','alex'], {'ensure' => 'present'}) + +ENDOFDOC +) do |vals| + type, title, params = vals + raise(ArgumentError, 'Must specify a type') unless type + raise(ArgumentError, 'Must specify a title') unless title + params ||= {} + + items = [title].flatten + + items.each do |item| + Puppet::Parser::Functions.function(:defined_with_params) + if function_defined_with_params(["#{type}[#{item}]", params]) + Puppet.debug("Resource #{type}[#{item}] not created because it already exists") + else + Puppet::Parser::Functions.function(:create_resources) + function_create_resources([type.capitalize, { item => params }]) + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/flatten.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/flatten.rb new file mode 100644 index 000000000..a1ed18329 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/flatten.rb @@ -0,0 +1,33 @@ +# +# flatten.rb +# + +module Puppet::Parser::Functions + newfunction(:flatten, :type => :rvalue, :doc => <<-EOS +This function flattens any deeply nested arrays and returns a single flat array +as a result. + +*Examples:* + + flatten(['a', ['b', ['c']]]) + +Would return: ['a','b','c'] + EOS + ) do |arguments| + + raise(Puppet::ParseError, "flatten(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size != 1 + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'flatten(): Requires array to work with') + end + + result = array.flatten + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/floor.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/floor.rb new file mode 100644 index 000000000..a40192349 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/floor.rb @@ -0,0 +1,20 @@ +module Puppet::Parser::Functions + newfunction(:floor, :type => :rvalue, :doc => <<-EOS + Returns the largest integer less or equal to the argument. + Takes a single numeric value as an argument. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "floor(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size != 1 + + arg = arguments[0] + + raise(Puppet::ParseError, "floor(): Wrong argument type " + + "given (#{arg.class} for Numeric)") if arg.is_a?(Numeric) == false + + arg.floor + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb new file mode 100644 index 000000000..655820605 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/fqdn_rotate.rb @@ -0,0 +1,46 @@ +# +# fqdn_rotate.rb +# + +module Puppet::Parser::Functions + newfunction(:fqdn_rotate, :type => :rvalue, :doc => <<-EOS +Rotates an array a random number of times based on a nodes fqdn. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "fqdn_rotate(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + require 'digest/md5' + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'fqdn_rotate(): Requires either ' + + 'array or string to work with') + end + + result = value.clone + + string = value.is_a?(String) ? true : false + + # Check whether it makes sense to rotate ... + return result if result.size <= 1 + + # We turn any string value into an array to be able to rotate ... + result = string ? result.split('') : result + + elements = result.size + + srand(Digest::MD5.hexdigest([lookupvar('::fqdn'),arguments].join(':')).hex) + rand(elements).times { + result.push result.shift + } + + result = string ? result.join : result + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb new file mode 100644 index 000000000..1421b91f5 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/get_module_path.rb @@ -0,0 +1,17 @@ +module Puppet::Parser::Functions + newfunction(:get_module_path, :type =>:rvalue, :doc => <<-EOT + Returns the absolute path of the specified module for the current + environment. + + Example: + $module_path = get_module_path('stdlib') + EOT + ) do |args| + raise(Puppet::ParseError, "get_module_path(): Wrong number of arguments, expects one") unless args.size == 1 + if module_path = Puppet::Module.find(args[0], compiler.environment.to_s) + module_path.path + else + raise(Puppet::ParseError, "Could not find module #{args[0]} in environment #{compiler.environment}") + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/getparam.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/getparam.rb new file mode 100644 index 000000000..6d510069f --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/getparam.rb @@ -0,0 +1,35 @@ +# Test whether a given class or definition is defined +require 'puppet/parser/functions' + +Puppet::Parser::Functions.newfunction(:getparam, + :type => :rvalue, + :doc => <<-'ENDOFDOC' +Takes a resource reference and name of the parameter and +returns value of resource's parameter. + +*Examples:* + + define example_resource($param) { + } + + example_resource { "example_resource_instance": + param => "param_value" + } + + getparam(Example_resource["example_resource_instance"], "param") + +Would return: param_value +ENDOFDOC +) do |vals| + reference, param = vals + raise(ArgumentError, 'Must specify a reference') unless reference + raise(ArgumentError, 'Must specify name of a parameter') unless param and param.instance_of? String + + return '' if param.empty? + + if resource = findresource(reference.to_s) + return resource[param] if resource[param] + end + + return '' +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/getvar.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/getvar.rb new file mode 100644 index 000000000..162114995 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/getvar.rb @@ -0,0 +1,26 @@ +module Puppet::Parser::Functions + + newfunction(:getvar, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| + Lookup a variable in a remote namespace. + + For example: + + $foo = getvar('site::data::foo') + # Equivalent to $foo = $site::data::foo + + This is useful if the namespace itself is stored in a string: + + $datalocation = 'site::data' + $bar = getvar("${datalocation}::bar") + # Equivalent to $bar = $site::data::bar + ENDHEREDOC + + unless args.length == 1 + raise Puppet::ParseError, ("getvar(): wrong number of arguments (#{args.length}; must be 1)") + end + + self.lookupvar("#{args[0]}") + + end + +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/grep.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/grep.rb new file mode 100644 index 000000000..ceba9ecc8 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/grep.rb @@ -0,0 +1,33 @@ +# +# grep.rb +# + +module Puppet::Parser::Functions + newfunction(:grep, :type => :rvalue, :doc => <<-EOS +This function searches through an array and returns any elements that match +the provided regular expression. + +*Examples:* + + grep(['aaa','bbb','ccc','aaaddd'], 'aaa') + +Would return: + + ['aaa','aaaddd'] + EOS + ) do |arguments| + + if (arguments.size != 2) then + raise(Puppet::ParseError, "grep(): Wrong number of arguments "+ + "given #{arguments.size} for 2") + end + + a = arguments[0] + pattern = Regexp.new(arguments[1]) + + a.grep(pattern) + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb new file mode 100644 index 000000000..7f150a717 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/has_interface_with.rb @@ -0,0 +1,52 @@ +# +# has_interface_with +# + +module Puppet::Parser::Functions + newfunction(:has_interface_with, :type => :rvalue, :doc => <<-EOS +Returns boolean based on kind and value: + * macaddress + * netmask + * ipaddress + * network + +has_interface_with("macaddress", "x:x:x:x:x:x") +has_interface_with("ipaddress", "127.0.0.1") => true +etc. + +If no "kind" is given, then the presence of the interface is checked: +has_interface_with("lo") => true + EOS + ) do |args| + + raise(Puppet::ParseError, "has_interface_with(): Wrong number of arguments " + + "given (#{args.size} for 1 or 2)") if args.size < 1 or args.size > 2 + + interfaces = lookupvar('interfaces') + + # If we do not have any interfaces, then there are no requested attributes + return false if (interfaces == :undefined) + + interfaces = interfaces.split(',') + + if args.size == 1 + return interfaces.member?(args[0]) + end + + kind, value = args + + if lookupvar(kind) == value + return true + end + + result = false + interfaces.each do |iface| + if value == lookupvar("#{kind}_#{iface}") + result = true + break + end + end + + result + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb new file mode 100644 index 000000000..842c8ec67 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/has_ip_address.rb @@ -0,0 +1,25 @@ +# +# has_ip_address +# + +module Puppet::Parser::Functions + newfunction(:has_ip_address, :type => :rvalue, :doc => <<-EOS +Returns true if the client has the requested IP address on some interface. + +This function iterates through the 'interfaces' fact and checks the +'ipaddress_IFACE' facts, performing a simple string comparison. + EOS + ) do |args| + + raise(Puppet::ParseError, "has_ip_address(): Wrong number of arguments " + + "given (#{args.size} for 1)") if args.size != 1 + + Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ + unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with) + + function_has_interface_with(['ipaddress', args[0]]) + + end +end + +# vim:sts=2 sw=2 diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb new file mode 100644 index 000000000..9ccf9024f --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/has_ip_network.rb @@ -0,0 +1,25 @@ +# +# has_ip_network +# + +module Puppet::Parser::Functions + newfunction(:has_ip_network, :type => :rvalue, :doc => <<-EOS +Returns true if the client has an IP address within the requested network. + +This function iterates through the 'interfaces' fact and checks the +'network_IFACE' facts, performing a simple string comparision. + EOS + ) do |args| + + raise(Puppet::ParseError, "has_ip_network(): Wrong number of arguments " + + "given (#{args.size} for 1)") if args.size != 1 + + Puppet::Parser::Functions.autoloader.load(:has_interface_with) \ + unless Puppet::Parser::Functions.autoloader.loaded?(:has_interface_with) + + function_has_interface_with(['network', args[0]]) + + end +end + +# vim:sts=2 sw=2 diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/has_key.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/has_key.rb new file mode 100644 index 000000000..4657cc29c --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/has_key.rb @@ -0,0 +1,28 @@ +module Puppet::Parser::Functions + + newfunction(:has_key, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| + Determine if a hash has a certain key value. + + Example: + + $my_hash = {'key_one' => 'value_one'} + if has_key($my_hash, 'key_two') { + notice('we will not reach here') + } + if has_key($my_hash, 'key_one') { + notice('this will be printed') + } + + ENDHEREDOC + + unless args.length == 2 + raise Puppet::ParseError, ("has_key(): wrong number of arguments (#{args.length}; must be 2)") + end + unless args[0].is_a?(Hash) + raise Puppet::ParseError, "has_key(): expects the first argument to be a hash, got #{args[0].inspect} which is of type #{args[0].class}" + end + args[0].has_key?(args[1]) + + end + +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/hash.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/hash.rb new file mode 100644 index 000000000..8cc4823be --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/hash.rb @@ -0,0 +1,41 @@ +# +# hash.rb +# + +module Puppet::Parser::Functions + newfunction(:hash, :type => :rvalue, :doc => <<-EOS +This function converts an array into a hash. + +*Examples:* + + hash(['a',1,'b',2,'c',3]) + +Would return: {'a'=>1,'b'=>2,'c'=>3} + EOS + ) do |arguments| + + raise(Puppet::ParseError, "hash(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'hash(): Requires array to work with') + end + + result = {} + + begin + # This is to make it compatible with older version of Ruby ... + array = array.flatten + result = Hash[*array] + rescue Exception + raise(Puppet::ParseError, 'hash(): Unable to compute ' + + 'hash from array given') + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/is_array.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/is_array.rb new file mode 100644 index 000000000..b39e184ae --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/is_array.rb @@ -0,0 +1,22 @@ +# +# is_array.rb +# + +module Puppet::Parser::Functions + newfunction(:is_array, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is an array. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "is_array(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + type = arguments[0] + + result = type.is_a?(Array) + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb new file mode 100644 index 000000000..5826dc0d9 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/is_domain_name.rb @@ -0,0 +1,47 @@ +# +# is_domain_name.rb +# + +module Puppet::Parser::Functions + newfunction(:is_domain_name, :type => :rvalue, :doc => <<-EOS +Returns true if the string passed to this function is a syntactically correct domain name. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "is_domain_name(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + domain = arguments[0] + + # Limits (rfc1035, 3.1) + domain_max_length=255 + label_min_length=1 + label_max_length=63 + + # Allow ".", it is the top level domain + return true if domain == '.' + + # Remove the final dot, if present. + domain.chomp!('.') + + # Check the whole domain + return false if domain.empty? + return false if domain.length > domain_max_length + + # Check each label in the domain + labels = domain.split('.') + vlabels = labels.each do |label| + break if label.length < label_min_length + break if label.length > label_max_length + break if label[-1..-1] == '-' + break if label[0..0] == '-' + break unless /^[a-z\d-]+$/i.match(label) + end + return vlabels == labels + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/is_float.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/is_float.rb new file mode 100644 index 000000000..911f3c2dc --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/is_float.rb @@ -0,0 +1,27 @@ +# +# is_float.rb +# + +module Puppet::Parser::Functions + newfunction(:is_float, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a float. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "is_float(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + value = arguments[0] + + if value != value.to_f.to_s and !value.is_a? Float then + return false + else + return true + end + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/is_function_available.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/is_function_available.rb new file mode 100644 index 000000000..6cbd35c3d --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/is_function_available.rb @@ -0,0 +1,23 @@ +# +# is_function_available.rb +# + +module Puppet::Parser::Functions + newfunction(:is_function_available, :type => :rvalue, :doc => <<-EOS +This function accepts a string as an argument, determines whether the +Puppet runtime has access to a function by that name. It returns a +true if the function exists, false if not. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "is_function_available?(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + function = Puppet::Parser::Functions.function(arguments[0].to_sym) + function.is_a?(String) and not function.empty? + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/is_hash.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/is_hash.rb new file mode 100644 index 000000000..ad907f086 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/is_hash.rb @@ -0,0 +1,22 @@ +# +# is_hash.rb +# + +module Puppet::Parser::Functions + newfunction(:is_hash, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a hash. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "is_hash(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size != 1 + + type = arguments[0] + + result = type.is_a?(Hash) + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/is_integer.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/is_integer.rb new file mode 100644 index 000000000..6b29e988e --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/is_integer.rb @@ -0,0 +1,27 @@ +# +# is_integer.rb +# + +module Puppet::Parser::Functions + newfunction(:is_integer, :type => :rvalue, :doc => <<-EOS +Returns true if the variable returned to this string is an integer. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "is_integer(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + value = arguments[0] + + if value != value.to_i.to_s and !value.is_a? Fixnum then + return false + else + return true + end + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb new file mode 100644 index 000000000..a90adabe1 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/is_ip_address.rb @@ -0,0 +1,32 @@ +# +# is_ip_address.rb +# + +module Puppet::Parser::Functions + newfunction(:is_ip_address, :type => :rvalue, :doc => <<-EOS +Returns true if the string passed to this function is a valid IP address. + EOS + ) do |arguments| + + require 'ipaddr' + + if (arguments.size != 1) then + raise(Puppet::ParseError, "is_ip_address(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + begin + ip = IPAddr.new(arguments[0]) + rescue ArgumentError + return false + end + + if ip.ipv4? or ip.ipv6? then + return true + else + return false + end + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb new file mode 100644 index 000000000..1b3088a26 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/is_mac_address.rb @@ -0,0 +1,27 @@ +# +# is_mac_address.rb +# + +module Puppet::Parser::Functions + newfunction(:is_mac_address, :type => :rvalue, :doc => <<-EOS +Returns true if the string passed to this function is a valid mac address. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "is_mac_address(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + mac = arguments[0] + + if /^[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}:[a-fA-F0-9]{1,2}$/.match(mac) then + return true + else + return false + end + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb new file mode 100644 index 000000000..abf03213c --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/is_numeric.rb @@ -0,0 +1,27 @@ +# +# is_numeric.rb +# + +module Puppet::Parser::Functions + newfunction(:is_numeric, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a number. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "is_numeric(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + value = arguments[0] + + if value == value.to_f.to_s or value == value.to_i.to_s or value.is_a? Numeric then + return true + else + return false + end + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/is_string.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/is_string.rb new file mode 100644 index 000000000..f5bef0457 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/is_string.rb @@ -0,0 +1,26 @@ +# +# is_string.rb +# + +module Puppet::Parser::Functions + newfunction(:is_string, :type => :rvalue, :doc => <<-EOS +Returns true if the variable passed to this function is a string. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "is_string(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + type = arguments[0] + + result = type.is_a?(String) + + if result and (type == type.to_f.to_s or type == type.to_i.to_s) then + return false + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/join.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/join.rb new file mode 100644 index 000000000..005a46ea5 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/join.rb @@ -0,0 +1,41 @@ +# +# join.rb +# + +module Puppet::Parser::Functions + newfunction(:join, :type => :rvalue, :doc => <<-EOS +This function joins an array into a string using a seperator. + +*Examples:* + + join(['a','b','c'], ",") + +Would result in: "a,b,c" + EOS + ) do |arguments| + + # Technically we support two arguments but only first is mandatory ... + raise(Puppet::ParseError, "join(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'join(): Requires array to work with') + end + + suffix = arguments[1] if arguments[1] + + if suffix + unless suffix.is_a?(String) + raise(Puppet::ParseError, 'join(): Requires string to work with') + end + end + + result = suffix ? array.join(suffix) : array.join + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb new file mode 100644 index 000000000..e9924fe2e --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/join_keys_to_values.rb @@ -0,0 +1,47 @@ +# +# join.rb +# + +module Puppet::Parser::Functions + newfunction(:join_keys_to_values, :type => :rvalue, :doc => <<-EOS +This function joins each key of a hash to that key's corresponding value with a +separator. Keys and values are cast to strings. The return value is an array in +which each element is one joined key/value pair. + +*Examples:* + + join_keys_to_values({'a'=>1,'b'=>2}, " is ") + +Would result in: ["a is 1","b is 2"] + EOS + ) do |arguments| + + # Validate the number of arguments. + if arguments.size != 2 + raise(Puppet::ParseError, "join_keys_to_values(): Takes exactly two " + + "arguments, but #{arguments.size} given.") + end + + # Validate the first argument. + hash = arguments[0] + if not hash.is_a?(Hash) + raise(TypeError, "join_keys_to_values(): The first argument must be a " + + "hash, but a #{hash.class} was given.") + end + + # Validate the second argument. + separator = arguments[1] + if not separator.is_a?(String) + raise(TypeError, "join_keys_to_values(): The second argument must be a " + + "string, but a #{separator.class} was given.") + end + + # Join the keys to their values. + hash.map do |k,v| + String(k) + separator + String(v) + end + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/keys.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/keys.rb new file mode 100644 index 000000000..f0d13b647 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/keys.rb @@ -0,0 +1,26 @@ +# +# keys.rb +# + +module Puppet::Parser::Functions + newfunction(:keys, :type => :rvalue, :doc => <<-EOS +Returns the keys of a hash as an array. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "keys(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + hash = arguments[0] + + unless hash.is_a?(Hash) + raise(Puppet::ParseError, 'keys(): Requires hash to work with') + end + + result = hash.keys + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb new file mode 100644 index 000000000..10c400501 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/loadyaml.rb @@ -0,0 +1,20 @@ +module Puppet::Parser::Functions + + newfunction(:loadyaml, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| + Load a YAML file containing an array, string, or hash, and return the data + in the corresponding native data type. + + For example: + + $myhash = loadyaml('/etc/puppet/data/myhash.yaml') + ENDHEREDOC + + unless args.length == 1 + raise Puppet::ParseError, ("loadyaml(): wrong number of arguments (#{args.length}; must be 1)") + end + + YAML.load_file(args[0]) + + end + +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/lstrip.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/lstrip.rb new file mode 100644 index 000000000..3a64de337 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/lstrip.rb @@ -0,0 +1,33 @@ +# +# lstrip.rb +# + +module Puppet::Parser::Functions + newfunction(:lstrip, :type => :rvalue, :doc => <<-EOS +Strips leading spaces to the left of a string. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "lstrip(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'lstrip(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.lstrip : i } + else + result = value.lstrip + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/max.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/max.rb new file mode 100644 index 000000000..60fb94ac0 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/max.rb @@ -0,0 +1,21 @@ +module Puppet::Parser::Functions + newfunction(:max, :type => :rvalue, :doc => <<-EOS + Returns the highest value of all arguments. + Requires at least one argument. + EOS + ) do |args| + + raise(Puppet::ParseError, "max(): Wrong number of arguments " + + "need at least one") if args.size == 0 + + # Sometimes we get numbers as numerics and sometimes as strings. + # We try to compare them as numbers when possible + return args.max do |a,b| + if a.to_s =~ /\A-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then + a.to_f <=> b.to_f + else + a.to_s <=> b.to_s + end + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/member.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/member.rb new file mode 100644 index 000000000..43d76affd --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/member.rb @@ -0,0 +1,44 @@ +# +# member.rb +# + +# TODO(Krzysztof Wilczynski): We need to add support for regular expression ... +# TODO(Krzysztof Wilczynski): Support for strings and hashes too ... + +module Puppet::Parser::Functions + newfunction(:member, :type => :rvalue, :doc => <<-EOS +This function determines if a variable is a member of an array. + +*Examples:* + + member(['a','b'], 'b') + +Would return: true + + member(['a','b'], 'c') + +Would return: false + EOS + ) do |arguments| + + raise(Puppet::ParseError, "member(): Wrong number of arguments " + + "given (#{arguments.size} for 2)") if arguments.size < 2 + + array = arguments[0] + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'member(): Requires array to work with') + end + + item = arguments[1] + + raise(Puppet::ParseError, 'member(): You must provide item ' + + 'to search for within array given') if item.empty? + + result = array.include?(item) + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/merge.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/merge.rb new file mode 100644 index 000000000..6ec085eb1 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/merge.rb @@ -0,0 +1,33 @@ +module Puppet::Parser::Functions + newfunction(:merge, :type => :rvalue, :doc => <<-'ENDHEREDOC') do |args| + Merges two or more hashes together and returns the resulting hash. + + For example: + + $hash1 = {'one' => 1, 'two', => 2} + $hash2 = {'two' => 'dos', 'three', => 'tres'} + $merged_hash = merge($hash1, $hash2) + # The resulting hash is equivalent to: + # $merged_hash = {'one' => 1, 'two' => 'dos', 'three' => 'tres'} + + When there is a duplicate key, the key in the rightmost hash will "win." + + ENDHEREDOC + + if args.length < 2 + raise Puppet::ParseError, ("merge(): wrong number of arguments (#{args.length}; must be at least 2)") + end + + # The hash we accumulate into + accumulator = Hash.new + # Merge into the accumulator hash + args.each do |arg| + unless arg.is_a?(Hash) + raise Puppet::ParseError, "merge: unexpected argument type #{arg.class}, only expects hash arguments" + end + accumulator.merge!(arg) + end + # Return the fully merged hash + accumulator + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/min.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/min.rb new file mode 100644 index 000000000..6bd6ebf20 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/min.rb @@ -0,0 +1,21 @@ +module Puppet::Parser::Functions + newfunction(:min, :type => :rvalue, :doc => <<-EOS + Returns the lowest value of all arguments. + Requires at least one argument. + EOS + ) do |args| + + raise(Puppet::ParseError, "min(): Wrong number of arguments " + + "need at least one") if args.size == 0 + + # Sometimes we get numbers as numerics and sometimes as strings. + # We try to compare them as numbers when possible + return args.min do |a,b| + if a.to_s =~ /\A^-?\d+(.\d+)?\z/ and b.to_s =~ /\A-?\d+(.\d+)?\z/ then + a.to_f <=> b.to_f + else + a.to_s <=> b.to_s + end + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/num2bool.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/num2bool.rb new file mode 100644 index 000000000..af0e6ed78 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/num2bool.rb @@ -0,0 +1,43 @@ +# +# num2bool.rb +# + +module Puppet::Parser::Functions + newfunction(:num2bool, :type => :rvalue, :doc => <<-EOS +This function converts a number or a string representation of a number into a +true boolean. Zero or anything non-numeric becomes false. Numbers higher then 0 +become true. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "num2bool(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size != 1 + + number = arguments[0] + + case number + when Numeric + # Yay, it's a number + when String + begin + number = Float(number) + rescue ArgumentError => ex + raise(Puppet::ParseError, "num2bool(): '#{number}' does not look like a number: #{ex.message}") + end + else + begin + number = number.to_s + rescue NoMethodError => ex + raise(Puppet::ParseError, "num2bool(): Unable to parse argument: #{ex.message}") + end + end + + # Truncate Floats + number = number.to_i + + # Return true for any positive number and false otherwise + return number > 0 + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/parsejson.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/parsejson.rb new file mode 100644 index 000000000..a9a16a452 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/parsejson.rb @@ -0,0 +1,24 @@ +# +# parsejson.rb +# + +module Puppet::Parser::Functions + newfunction(:parsejson, :type => :rvalue, :doc => <<-EOS +This function accepts JSON as a string and converts into the correct Puppet +structure. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "parsejson(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + json = arguments[0] + + # PSON is natively available in puppet + PSON.load(json) + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb new file mode 100644 index 000000000..53d54faff --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/parseyaml.rb @@ -0,0 +1,24 @@ +# +# parseyaml.rb +# + +module Puppet::Parser::Functions + newfunction(:parseyaml, :type => :rvalue, :doc => <<-EOS +This function accepts YAML as a string and converts it into the correct +Puppet structure. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "parseyaml(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + require 'yaml' + + YAML::load(arguments[0]) + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/pick.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/pick.rb new file mode 100644 index 000000000..cbc030021 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/pick.rb @@ -0,0 +1,29 @@ +module Puppet::Parser::Functions + newfunction(:pick, :type => :rvalue, :doc => <<-EOS + +This function is similar to a coalesce function in SQL in that it will return +the first value in a list of values that is not undefined or an empty string +(two things in Puppet that will return a boolean false value). Typically, +this function is used to check for a value in the Puppet Dashboard/Enterprise +Console, and failover to a default value like the following: + + $real_jenkins_version = pick($::jenkins_version, '1.449') + +The value of $real_jenkins_version will first look for a top-scope variable +called 'jenkins_version' (note that parameters set in the Puppet Dashboard/ +Enterprise Console are brought into Puppet as top-scope variables), and, +failing that, will use a default value of 1.449. + +EOS +) do |args| + args = args.compact + args.delete(:undef) + args.delete(:undefined) + args.delete("") + if args[0].to_s.empty? then + fail "Must provide non empty value." + else + return args[0] + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/prefix.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/prefix.rb new file mode 100644 index 000000000..62211ae68 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/prefix.rb @@ -0,0 +1,45 @@ +# +# prefix.rb +# + +module Puppet::Parser::Functions + newfunction(:prefix, :type => :rvalue, :doc => <<-EOS +This function applies a prefix to all elements in an array. + +*Examples:* + + prefix(['a','b','c'], 'p') + +Will return: ['pa','pb','pc'] + EOS + ) do |arguments| + + # Technically we support two arguments but only first is mandatory ... + raise(Puppet::ParseError, "prefix(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + array = arguments[0] + + unless array.is_a?(Array) + raise Puppet::ParseError, "prefix(): expected first argument to be an Array, got #{array.inspect}" + end + + prefix = arguments[1] if arguments[1] + + if prefix + unless prefix.is_a?(String) + raise Puppet::ParseError, "prefix(): expected second argument to be a String, got #{suffix.inspect}" + end + end + + # Turn everything into string same as join would do ... + result = array.collect do |i| + i = i.to_s + prefix ? prefix + i : i + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/range.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/range.rb new file mode 100644 index 000000000..825617b38 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/range.rb @@ -0,0 +1,80 @@ +# +# range.rb +# + +# TODO(Krzysztof Wilczynski): We probably need to approach numeric values differently ... + +module Puppet::Parser::Functions + newfunction(:range, :type => :rvalue, :doc => <<-EOS +When given range in the form of (start, stop) it will extrapolate a range as +an array. + +*Examples:* + + range("0", "9") + +Will return: [0,1,2,3,4,5,6,7,8,9] + + range("00", "09") + +Will return: [0,1,2,3,4,5,6,7,8,9] (Zero padded strings are converted to +integers automatically) + + range("a", "c") + +Will return: ["a","b","c"] + + range("host01", "host10") + +Will return: ["host01", "host02", ..., "host09", "host10"] + EOS + ) do |arguments| + + # We support more than one argument but at least one is mandatory ... + raise(Puppet::ParseError, "range(): Wrong number of " + + "arguments given (#{arguments.size} for 1)") if arguments.size < 1 + + if arguments.size > 1 + start = arguments[0] + stop = arguments[1] + + type = '..' # We select simplest type for Range available in Ruby ... + + elsif arguments.size > 0 + value = arguments[0] + + if m = value.match(/^(\w+)(\.\.\.?|\-)(\w+)$/) + start = m[1] + stop = m[3] + + type = m[2] + + elsif value.match(/^.+$/) + raise(Puppet::ParseError, 'range(): Unable to compute range ' + + 'from the value given') + else + raise(Puppet::ParseError, 'range(): Unknown format of range given') + end + end + + # Check whether we have integer value if so then make it so ... + if start.match(/^\d+$/) + start = start.to_i + stop = stop.to_i + else + start = start.to_s + stop = stop.to_s + end + + range = case type + when /^(\.\.|\-)$/ then (start .. stop) + when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ... + end + + result = range.collect { |i| i } # Get them all ... Pokemon ... + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/reject.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/reject.rb new file mode 100644 index 000000000..1953ffcf1 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/reject.rb @@ -0,0 +1,31 @@ +# +# reject.rb +# + +module Puppet::Parser::Functions + newfunction(:reject, :type => :rvalue, :doc => <<-EOS) do |args| +This function searches through an array and rejects all elements that match +the provided regular expression. + +*Examples:* + + reject(['aaa','bbb','ccc','aaaddd'], 'aaa') + +Would return: + + ['bbb','ccc'] +EOS + + if (args.size != 2) + raise Puppet::ParseError, + "reject(): Wrong number of arguments given #{args.size} for 2" + end + + ary = args[0] + pattern = Regexp.new(args[1]) + + ary.reject { |e| e =~ pattern } + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/reverse.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/reverse.rb new file mode 100644 index 000000000..fe048690c --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/reverse.rb @@ -0,0 +1,28 @@ +# +# reverse.rb +# + +module Puppet::Parser::Functions + newfunction(:reverse, :type => :rvalue, :doc => <<-EOS +Reverses the order of a string or array. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "reverse(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'reverse(): Requires either ' + + 'array or string to work with') + end + + result = value.reverse + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/rstrip.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/rstrip.rb new file mode 100644 index 000000000..29b099820 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/rstrip.rb @@ -0,0 +1,32 @@ +# +# rstrip.rb +# + +module Puppet::Parser::Functions + newfunction(:rstrip, :type => :rvalue, :doc => <<-EOS +Strips leading spaces to the right of the string. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "rstrip(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'rstrip(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + result = value.collect { |i| i.is_a?(String) ? i.rstrip : i } + else + result = value.rstrip + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/shuffle.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/shuffle.rb new file mode 100644 index 000000000..18134ab63 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/shuffle.rb @@ -0,0 +1,46 @@ +# +# shuffle.rb +# + +module Puppet::Parser::Functions + newfunction(:shuffle, :type => :rvalue, :doc => <<-EOS +Randomizes the order of a string or array elements. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "shuffle(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'shuffle(): Requires either ' + + 'array or string to work with') + end + + result = value.clone + + string = value.is_a?(String) ? true : false + + # Check whether it makes sense to shuffle ... + return result if result.size <= 1 + + # We turn any string value into an array to be able to shuffle ... + result = string ? result.split('') : result + + elements = result.size + + # Simple implementation of Fisher–Yates in-place shuffle ... + elements.times do |i| + j = rand(elements - i) + i + result[j], result[i] = result[i], result[j] + end + + result = string ? result.join : result + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/size.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/size.rb new file mode 100644 index 000000000..cc207e3fa --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/size.rb @@ -0,0 +1,48 @@ +# +# size.rb +# + +# TODO(Krzysztof Wilczynski): Support for hashes would be nice too ... + +module Puppet::Parser::Functions + newfunction(:size, :type => :rvalue, :doc => <<-EOS +Returns the number of elements in a string or array. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "size(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + item = arguments[0] + + if item.is_a?(String) + + begin + # + # Check whether your item is a numeric value or not ... + # This will take care about positive and/or negative numbers + # for both integer and floating-point values ... + # + # Please note that Puppet has no notion of hexadecimal + # nor octal numbers for its DSL at this point in time ... + # + Float(item) + + raise(Puppet::ParseError, 'size(): Requires either ' + + 'string or array to work with') + + rescue ArgumentError + result = item.size + end + + elsif item.is_a?(Array) + result = item.size + else + raise(Puppet::ParseError, 'size(): Unknown type given') + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/sort.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/sort.rb new file mode 100644 index 000000000..cefbe5463 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/sort.rb @@ -0,0 +1,27 @@ +# +# sort.rb +# + +module Puppet::Parser::Functions + newfunction(:sort, :type => :rvalue, :doc => <<-EOS +Sorts strings and arrays lexically. + EOS + ) do |arguments| + + if (arguments.size != 1) then + raise(Puppet::ParseError, "sort(): Wrong number of arguments "+ + "given #{arguments.size} for 1") + end + + value = arguments[0] + + if value.is_a?(Array) then + value.sort + elsif value.is_a?(String) then + value.split("").sort.join("") + end + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/squeeze.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/squeeze.rb new file mode 100644 index 000000000..81fadfdb2 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/squeeze.rb @@ -0,0 +1,36 @@ +# +# squeeze.rb +# + +module Puppet::Parser::Functions + newfunction(:squeeze, :type => :rvalue, :doc => <<-EOS +Returns a new string where runs of the same character that occur in this set are replaced by a single character. + EOS + ) do |arguments| + + if ((arguments.size != 2) and (arguments.size != 1)) then + raise(Puppet::ParseError, "squeeze(): Wrong number of arguments "+ + "given #{arguments.size} for 2 or 1") + end + + item = arguments[0] + squeezeval = arguments[1] + + if item.is_a?(Array) then + if squeezeval then + item.collect { |i| i.squeeze(squeezeval) } + else + item.collect { |i| i.squeeze } + end + else + if squeezeval then + item.squeeze(squeezeval) + else + item.squeeze + end + end + + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/str2bool.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/str2bool.rb new file mode 100644 index 000000000..fece7a6f2 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/str2bool.rb @@ -0,0 +1,46 @@ +# +# str2bool.rb +# + +module Puppet::Parser::Functions + newfunction(:str2bool, :type => :rvalue, :doc => <<-EOS +This converts a string to a boolean. This attempt to convert strings that +contain things like: y, 1, t, true to 'true' and strings that contain things +like: 0, f, n, false, no to 'false'. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "str2bool(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + string = arguments[0] + + # If string is already Boolean, return it + if !!string == string + return string + end + + unless string.is_a?(String) + raise(Puppet::ParseError, 'str2bool(): Requires either ' + + 'string to work with') + end + + # We consider all the yes, no, y, n and so on too ... + result = case string + # + # This is how undef looks like in Puppet ... + # We yield false in this case. + # + when /^$/, '' then false # Empty string will be false ... + when /^(1|t|y|true|yes)$/ then true + when /^(0|f|n|false|no)$/ then false + when /^(undef|undefined)$/ then false # This is not likely to happen ... + else + raise(Puppet::ParseError, 'str2bool(): Unknown type of boolean given') + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb new file mode 100644 index 000000000..7fe7b0128 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/str2saltedsha512.rb @@ -0,0 +1,32 @@ +# +# str2saltedsha512.rb +# + +module Puppet::Parser::Functions + newfunction(:str2saltedsha512, :type => :rvalue, :doc => <<-EOS +This converts a string to a salted-SHA512 password hash (which is used for +OS X versions >= 10.7). Given any simple string, you will get a hex version +of a salted-SHA512 password hash that can be inserted into your Puppet +manifests as a valid password attribute. + EOS + ) do |arguments| + require 'digest/sha2' + + raise(Puppet::ParseError, "str2saltedsha512(): Wrong number of arguments " + + "passed (#{arguments.size} but we require 1)") if arguments.size != 1 + + password = arguments[0] + + unless password.is_a?(String) + raise(Puppet::ParseError, 'str2saltedsha512(): Requires a ' + + "String argument, you passed: #{password.class}") + end + + seedint = rand(2**31 - 1) + seedstring = Array(seedint).pack("L") + saltedpass = Digest::SHA512.digest(seedstring + password) + (seedstring + saltedpass).unpack('H*')[0] + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/strftime.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/strftime.rb new file mode 100644 index 000000000..0b52adecd --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/strftime.rb @@ -0,0 +1,107 @@ +# +# strftime.rb +# + +module Puppet::Parser::Functions + newfunction(:strftime, :type => :rvalue, :doc => <<-EOS +This function returns formatted time. + +*Examples:* + +To return the time since epoch: + + strftime("%s") + +To return the date: + + strftime("%Y-%m-%d") + +*Format meaning:* + + %a - The abbreviated weekday name (``Sun'') + %A - The full weekday name (``Sunday'') + %b - The abbreviated month name (``Jan'') + %B - The full month name (``January'') + %c - The preferred local date and time representation + %C - Century (20 in 2009) + %d - Day of the month (01..31) + %D - Date (%m/%d/%y) + %e - Day of the month, blank-padded ( 1..31) + %F - Equivalent to %Y-%m-%d (the ISO 8601 date format) + %h - Equivalent to %b + %H - Hour of the day, 24-hour clock (00..23) + %I - Hour of the day, 12-hour clock (01..12) + %j - Day of the year (001..366) + %k - hour, 24-hour clock, blank-padded ( 0..23) + %l - hour, 12-hour clock, blank-padded ( 0..12) + %L - Millisecond of the second (000..999) + %m - Month of the year (01..12) + %M - Minute of the hour (00..59) + %n - Newline (\n) + %N - Fractional seconds digits, default is 9 digits (nanosecond) + %3N millisecond (3 digits) + %6N microsecond (6 digits) + %9N nanosecond (9 digits) + %p - Meridian indicator (``AM'' or ``PM'') + %P - Meridian indicator (``am'' or ``pm'') + %r - time, 12-hour (same as %I:%M:%S %p) + %R - time, 24-hour (%H:%M) + %s - Number of seconds since 1970-01-01 00:00:00 UTC. + %S - Second of the minute (00..60) + %t - Tab character (\t) + %T - time, 24-hour (%H:%M:%S) + %u - Day of the week as a decimal, Monday being 1. (1..7) + %U - Week number of the current year, + starting with the first Sunday as the first + day of the first week (00..53) + %v - VMS date (%e-%b-%Y) + %V - Week number of year according to ISO 8601 (01..53) + %W - Week number of the current year, + starting with the first Monday as the first + day of the first week (00..53) + %w - Day of the week (Sunday is 0, 0..6) + %x - Preferred representation for the date alone, no time + %X - Preferred representation for the time alone, no date + %y - Year without a century (00..99) + %Y - Year with century + %z - Time zone as hour offset from UTC (e.g. +0900) + %Z - Time zone name + %% - Literal ``%'' character + EOS + ) do |arguments| + + # Technically we support two arguments but only first is mandatory ... + raise(Puppet::ParseError, "strftime(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + format = arguments[0] + + raise(Puppet::ParseError, 'strftime(): You must provide ' + + 'format for evaluation') if format.empty? + + # The Time Zone argument is optional ... + time_zone = arguments[1] if arguments[1] + + time = Time.new + + # There is probably a better way to handle Time Zone ... + if time_zone and not time_zone.empty? + original_zone = ENV['TZ'] + + local_time = time.clone + local_time = local_time.utc + + ENV['TZ'] = time_zone + + time = local_time.localtime + + ENV['TZ'] = original_zone + end + + result = time.strftime(format) + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/strip.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/strip.rb new file mode 100644 index 000000000..5f4630d7d --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/strip.rb @@ -0,0 +1,39 @@ +# +# strip.rb +# + +module Puppet::Parser::Functions + newfunction(:strip, :type => :rvalue, :doc => <<-EOS +This function removes leading and trailing whitespace from a string or from +every string inside an array. + +*Examples:* + + strip(" aaa ") + +Would result in: "aaa" + EOS + ) do |arguments| + + raise(Puppet::ParseError, "strip(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'strip(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + result = value.collect { |i| i.is_a?(String) ? i.strip : i } + else + result = value.strip + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/suffix.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/suffix.rb new file mode 100644 index 000000000..f7792d6f7 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/suffix.rb @@ -0,0 +1,45 @@ +# +# suffix.rb +# + +module Puppet::Parser::Functions + newfunction(:suffix, :type => :rvalue, :doc => <<-EOS +This function applies a suffix to all elements in an array. + +*Examples:* + + suffix(['a','b','c'], 'p') + +Will return: ['ap','bp','cp'] + EOS + ) do |arguments| + + # Technically we support two arguments but only first is mandatory ... + raise(Puppet::ParseError, "suffix(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + array = arguments[0] + + unless array.is_a?(Array) + raise Puppet::ParseError, "suffix(): expected first argument to be an Array, got #{array.inspect}" + end + + suffix = arguments[1] if arguments[1] + + if suffix + unless suffix.is_a? String + raise Puppet::ParseError, "suffix(): expected second argument to be a String, got #{suffix.inspect}" + end + end + + # Turn everything into string same as join would do ... + result = array.collect do |i| + i = i.to_s + suffix ? i + suffix : i + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/swapcase.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/swapcase.rb new file mode 100644 index 000000000..b9e663253 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/swapcase.rb @@ -0,0 +1,39 @@ +# +# swapcase.rb +# + +module Puppet::Parser::Functions + newfunction(:swapcase, :type => :rvalue, :doc => <<-EOS +This function will swap the existing case of a string. + +*Examples:* + + swapcase("aBcD") + +Would result in: "AbCd" + EOS + ) do |arguments| + + raise(Puppet::ParseError, "swapcase(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'swapcase(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.swapcase : i } + else + result = value.swapcase + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/time.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/time.rb new file mode 100644 index 000000000..0cddaf86b --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/time.rb @@ -0,0 +1,49 @@ +# +# time.rb +# + +module Puppet::Parser::Functions + newfunction(:time, :type => :rvalue, :doc => <<-EOS +This function will return the current time since epoch as an integer. + +*Examples:* + + time() + +Will return something like: 1311972653 + EOS + ) do |arguments| + + # The Time Zone argument is optional ... + time_zone = arguments[0] if arguments[0] + + if (arguments.size != 0) and (arguments.size != 1) then + raise(Puppet::ParseError, "time(): Wrong number of arguments "+ + "given #{arguments.size} for 0 or 1") + end + + time = Time.new + + # There is probably a better way to handle Time Zone ... + if time_zone and not time_zone.empty? + original_zone = ENV['TZ'] + + local_time = time.clone + local_time = local_time.utc + + ENV['TZ'] = time_zone + + time = local_time.localtime + + ENV['TZ'] = original_zone + end + + # Calling Time#to_i on a receiver changes it. Trust me I am the Doctor. + result = time.strftime('%s') + result = result.to_i + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb new file mode 100644 index 000000000..8ff73d10b --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/to_bytes.rb @@ -0,0 +1,28 @@ +module Puppet::Parser::Functions + newfunction(:to_bytes, :type => :rvalue, :doc => <<-EOS + Converts the argument into bytes, for example 4 kB becomes 4096. + Takes a single string value as an argument. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "to_bytes(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size != 1 + + arg = arguments[0] + + return arg if arg.is_a? Numeric + + value,prefix = */([0-9.e+-]*)\s*([^bB]?)/.match(arg)[1,2] + + value = value.to_f + case prefix + when '' then return value.to_i + when 'k' then return (value*(1<<10)).to_i + when 'M' then return (value*(1<<20)).to_i + when 'G' then return (value*(1<<30)).to_i + when 'T' then return (value*(1<<40)).to_i + when 'E' then return (value*(1<<50)).to_i + else raise Puppet::ParseError, "to_bytes(): Unknown prefix #{prefix}" + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/type.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/type.rb new file mode 100644 index 000000000..8d85f1158 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/type.rb @@ -0,0 +1,50 @@ +# +# type.rb +# + +module Puppet::Parser::Functions + newfunction(:type, :type => :rvalue, :doc => <<-EOS +Returns the type when passed a variable. Type can be one of: + +* string +* array +* hash +* float +* integer +* boolean + EOS + ) do |arguments| + + raise(Puppet::ParseError, "type(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + + klass = value.class + + if not [TrueClass, FalseClass, Array, Bignum, Fixnum, Float, Hash, String].include?(klass) + raise(Puppet::ParseError, 'type(): Unknown type') + end + + klass = klass.to_s # Ugly ... + + # We note that Integer is the parent to Bignum and Fixnum ... + result = case klass + when /^(?:Big|Fix)num$/ then 'integer' + when /^(?:True|False)Class$/ then 'boolean' + else klass + end + + if result == "String" then + if value == value.to_i.to_s then + result = "Integer" + elsif value == value.to_f.to_s then + result = "Float" + end + end + + return result.downcase + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/unique.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/unique.rb new file mode 100644 index 000000000..8844a7418 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/unique.rb @@ -0,0 +1,51 @@ +# +# unique.rb +# + +module Puppet::Parser::Functions + newfunction(:unique, :type => :rvalue, :doc => <<-EOS +This function will remove duplicates from strings and arrays. + +*Examples:* + + unique("aabbcc") + +Will return: + + abc + +You can also use this with arrays: + + unique(["a","a","b","b","c","c"]) + +This returns: + + ["a","b","c"] + EOS + ) do |arguments| + + raise(Puppet::ParseError, "unique(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'unique(): Requires either ' + + 'array or string to work with') + end + + result = value.clone + + string = value.is_a?(String) ? true : false + + # We turn any string value into an array to be able to shuffle ... + result = string ? result.split('') : result + result = result.uniq # Remove duplicates ... + result = string ? result.join : result + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/upcase.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/upcase.rb new file mode 100644 index 000000000..fe6cadc3c --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/upcase.rb @@ -0,0 +1,41 @@ +# +# upcase.rb +# + +module Puppet::Parser::Functions + newfunction(:upcase, :type => :rvalue, :doc => <<-EOS +Converts a string or an array of strings to uppercase. + +*Examples:* + + upcase("abcd") + +Will return: + + ASDF + EOS + ) do |arguments| + + raise(Puppet::ParseError, "upcase(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'upcase(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? i.upcase : i } + else + result = value.upcase + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/uriescape.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/uriescape.rb new file mode 100644 index 000000000..67b93a64d --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/uriescape.rb @@ -0,0 +1,36 @@ +# +# uriescape.rb +# +require 'uri' + +module Puppet::Parser::Functions + newfunction(:uriescape, :type => :rvalue, :doc => <<-EOS + Urlencodes a string or array of strings. + Requires either a single string or an array as an input. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "uriescape(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + value = arguments[0] + klass = value.class + unsafe = ":/?#[]@!$&'()*+,;= " + + unless [Array, String].include?(klass) + raise(Puppet::ParseError, 'uriescape(): Requires either ' + + 'array or string to work with') + end + + if value.is_a?(Array) + # Numbers in Puppet are often string-encoded which is troublesome ... + result = value.collect { |i| i.is_a?(String) ? URI.escape(i,unsafe) : i } + else + result = URI.escape(value,unsafe) + end + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb new file mode 100644 index 000000000..fe279744e --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_absolute_path.rb @@ -0,0 +1,56 @@ +module Puppet::Parser::Functions + newfunction(:validate_absolute_path, :doc => <<-'ENDHEREDOC') do |args| + Validate the string represents an absolute path in the filesystem. This function works + for windows and unix style paths. + + The following values will pass: + + $my_path = "C:/Program Files (x86)/Puppet Labs/Puppet" + validate_absolute_path($my_path) + $my_path2 = "/var/lib/puppet" + validate_absolute_path($my_path2) + + + The following values will fail, causing compilation to abort: + + validate_absolute_path(true) + validate_absolute_path([ 'var/lib/puppet', '/var/foo' ]) + validate_absolute_path([ '/var/lib/puppet', 'var/foo' ]) + $undefined = undef + validate_absolute_path($undefined) + + ENDHEREDOC + + require 'puppet/util' + + unless args.length > 0 then + raise Puppet::ParseError, ("validate_absolute_path(): wrong number of arguments (#{args.length}; must be > 0)") + end + + args.each do |arg| + # This logic was borrowed from + # [lib/puppet/file_serving/base.rb](https://github.com/puppetlabs/puppet/blob/master/lib/puppet/file_serving/base.rb) + + # Puppet 2.7 and beyond will have Puppet::Util.absolute_path? Fall back to a back-ported implementation otherwise. + if Puppet::Util.respond_to?(:absolute_path?) then + unless Puppet::Util.absolute_path?(arg, :posix) or Puppet::Util.absolute_path?(arg, :windows) + raise Puppet::ParseError, ("#{arg.inspect} is not an absolute path.") + end + else + # This code back-ported from 2.7.x's lib/puppet/util.rb Puppet::Util.absolute_path? + # Determine in a platform-specific way whether a path is absolute. This + # defaults to the local platform if none is specified. + # Escape once for the string literal, and once for the regex. + slash = '[\\\\/]' + name = '[^\\\\/]+' + regexes = { + :windows => %r!^(([A-Z]:#{slash})|(#{slash}#{slash}#{name}#{slash}#{name})|(#{slash}#{slash}\?#{slash}#{name}))!i, + :posix => %r!^/!, + } + + rval = (!!(arg =~ regexes[:posix])) || (!!(arg =~ regexes[:windows])) + rval or raise Puppet::ParseError, ("#{arg.inspect} is not an absolute path.") + end + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/validate_array.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_array.rb new file mode 100644 index 000000000..34b511825 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_array.rb @@ -0,0 +1,33 @@ +module Puppet::Parser::Functions + + newfunction(:validate_array, :doc => <<-'ENDHEREDOC') do |args| + Validate that all passed values are array data structures. Abort catalog + compilation if any value fails this check. + + The following values will pass: + + $my_array = [ 'one', 'two' ] + validate_array($my_array) + + The following values will fail, causing compilation to abort: + + validate_array(true) + validate_array('some_string') + $undefined = undef + validate_array($undefined) + + ENDHEREDOC + + unless args.length > 0 then + raise Puppet::ParseError, ("validate_array(): wrong number of arguments (#{args.length}; must be > 0)") + end + + args.each do |arg| + unless arg.is_a?(Array) + raise Puppet::ParseError, ("#{arg.inspect} is not an Array. It looks to be a #{arg.class}") + end + end + + end + +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb new file mode 100644 index 000000000..154d66091 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_augeas.rb @@ -0,0 +1,81 @@ +module Puppet::Parser::Functions + newfunction(:validate_augeas, :doc => <<-'ENDHEREDOC') do |args| + Perform validation of a string using an Augeas lens + The first argument of this function should be a string to + test, and the second argument should be the name of the Augeas lens to use. + If Augeas fails to parse the string with the lens, the compilation will + abort with a parse error. + + A third argument can be specified, listing paths which should + not be found in the file. The `$file` variable points to the location + of the temporary file being tested in the Augeas tree. + + For example, if you want to make sure your passwd content never contains + a user `foo`, you could write: + + validate_augeas($passwdcontent, 'Passwd.lns', ['$file/foo']) + + Or if you wanted to ensure that no users used the '/bin/barsh' shell, + you could use: + + validate_augeas($passwdcontent, 'Passwd.lns', ['$file/*[shell="/bin/barsh"]'] + + If a fourth argument is specified, this will be the error message raised and + seen by the user. + + A helpful error message can be returned like this: + + validate_augeas($sudoerscontent, 'Sudoers.lns', [], 'Failed to validate sudoers content with Augeas') + + ENDHEREDOC + unless Puppet.features.augeas? + raise Puppet::ParseError, ("validate_augeas(): this function requires the augeas feature. See http://projects.puppetlabs.com/projects/puppet/wiki/Puppet_Augeas#Pre-requisites for how to activate it.") + end + + if (args.length < 2) or (args.length > 4) then + raise Puppet::ParseError, ("validate_augeas(): wrong number of arguments (#{args.length}; must be 2, 3, or 4)") + end + + msg = args[3] || "validate_augeas(): Failed to validate content against #{args[1].inspect}" + + require 'augeas' + aug = Augeas::open(nil, nil, Augeas::NO_MODL_AUTOLOAD) + begin + content = args[0] + + # Test content in a temporary file + tmpfile = Tempfile.new("validate_augeas") + begin + tmpfile.write(content) + ensure + tmpfile.close + end + + # Check for syntax + lens = args[1] + aug.transform( + :lens => lens, + :name => 'Validate_augeas', + :incl => tmpfile.path + ) + aug.load! + + unless aug.match("/augeas/files#{tmpfile.path}//error").empty? + error = aug.get("/augeas/files#{tmpfile.path}//error/message") + msg += " with error: #{error}" + raise Puppet::ParseError, (msg) + end + + # Launch unit tests + tests = args[2] || [] + aug.defvar('file', "/files#{tmpfile.path}") + tests.each do |t| + msg += " testing path #{t}" + raise Puppet::ParseError, (msg) unless aug.match(t).empty? + end + ensure + aug.close + tmpfile.unlink + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb new file mode 100644 index 000000000..62c1d8882 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_bool.rb @@ -0,0 +1,34 @@ +module Puppet::Parser::Functions + + newfunction(:validate_bool, :doc => <<-'ENDHEREDOC') do |args| + Validate that all passed values are either true or false. Abort catalog + compilation if any value fails this check. + + The following values will pass: + + $iamtrue = true + validate_bool(true) + validate_bool(true, true, false, $iamtrue) + + The following values will fail, causing compilation to abort: + + $some_array = [ true ] + validate_bool("false") + validate_bool("true") + validate_bool($some_array) + + ENDHEREDOC + + unless args.length > 0 then + raise Puppet::ParseError, ("validate_bool(): wrong number of arguments (#{args.length}; must be > 0)") + end + + args.each do |arg| + unless (arg.is_a?(TrueClass) || arg.is_a?(FalseClass)) + raise Puppet::ParseError, ("#{arg.inspect} is not a boolean. It looks to be a #{arg.class}") + end + end + + end + +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/validate_cmd.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_cmd.rb new file mode 100644 index 000000000..344a80cd3 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_cmd.rb @@ -0,0 +1,47 @@ +require 'puppet/util/execution' + +module Puppet::Parser::Functions + newfunction(:validate_cmd, :doc => <<-'ENDHEREDOC') do |args| + Perform validation of a string with an external command. + The first argument of this function should be a string to + test, and the second argument should be a path to a test command + taking a file as last argument. If the command, launched against + a tempfile containing the passed string, returns a non-null value, + compilation will abort with a parse error. + + If a third argument is specified, this will be the error message raised and + seen by the user. + + A helpful error message can be returned like this: + + Example: + + validate_cmd($sudoerscontent, '/usr/sbin/visudo -c -f', 'Visudo failed to validate sudoers content') + + ENDHEREDOC + if (args.length < 2) or (args.length > 3) then + raise Puppet::ParseError, ("validate_cmd(): wrong number of arguments (#{args.length}; must be 2 or 3)") + end + + msg = args[2] || "validate_cmd(): failed to validate content with command #{args[1].inspect}" + + content = args[0] + checkscript = args[1] + + # Test content in a temporary file + tmpfile = Tempfile.new("validate_cmd") + begin + tmpfile.write(content) + if Puppet::Util::Execution.respond_to?('execute') + Puppet::Util::Execution.execute("#{checkscript} #{tmpfile.path}") + else + Puppet::Util.execute("#{checkscript} #{tmpfile.path}") + end + rescue Puppet::ExecutionFailure => detail + msg += "\n#{detail}" + raise Puppet::ParseError, msg + ensure + tmpfile.unlink + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb new file mode 100644 index 000000000..9bdd54328 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_hash.rb @@ -0,0 +1,33 @@ +module Puppet::Parser::Functions + + newfunction(:validate_hash, :doc => <<-'ENDHEREDOC') do |args| + Validate that all passed values are hash data structures. Abort catalog + compilation if any value fails this check. + + The following values will pass: + + $my_hash = { 'one' => 'two' } + validate_hash($my_hash) + + The following values will fail, causing compilation to abort: + + validate_hash(true) + validate_hash('some_string') + $undefined = undef + validate_hash($undefined) + + ENDHEREDOC + + unless args.length > 0 then + raise Puppet::ParseError, ("validate_hash(): wrong number of arguments (#{args.length}; must be > 0)") + end + + args.each do |arg| + unless arg.is_a?(Hash) + raise Puppet::ParseError, ("#{arg.inspect} is not a Hash. It looks to be a #{arg.class}") + end + end + + end + +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/validate_re.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_re.rb new file mode 100644 index 000000000..ca25a702c --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_re.rb @@ -0,0 +1,40 @@ +module Puppet::Parser::Functions + newfunction(:validate_re, :doc => <<-'ENDHEREDOC') do |args| + Perform simple validation of a string against one or more regular + expressions. The first argument of this function should be a string to + test, and the second argument should be a stringified regular expression + (without the // delimiters) or an array of regular expressions. If none + of the regular expressions match the string passed in, compilation will + abort with a parse error. + + If a third argument is specified, this will be the error message raised and + seen by the user. + + The following strings will validate against the regular expressions: + + validate_re('one', '^one$') + validate_re('one', [ '^one', '^two' ]) + + The following strings will fail to validate, causing compilation to abort: + + validate_re('one', [ '^two', '^three' ]) + + A helpful error message can be returned like this: + + validate_re($::puppetversion, '^2.7', 'The $puppetversion fact value does not match 2.7') + + ENDHEREDOC + if (args.length < 2) or (args.length > 3) then + raise Puppet::ParseError, ("validate_re(): wrong number of arguments (#{args.length}; must be 2 or 3)") + end + + msg = args[2] || "validate_re(): #{args[0].inspect} does not match #{args[1].inspect}" + + # We're using a flattened array here because we can't call String#any? in + # Ruby 1.9 like we can in Ruby 1.8 + raise Puppet::ParseError, (msg) unless [args[1]].flatten.any? do |re_str| + args[0] =~ Regexp.compile(re_str) + end + + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb new file mode 100644 index 000000000..fdcc0a2d1 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_slength.rb @@ -0,0 +1,52 @@ +module Puppet::Parser::Functions + + newfunction(:validate_slength, :doc => <<-'ENDHEREDOC') do |args| + Validate that the first argument is a string (or an array of strings), and + less/equal to than the length of the second argument. It fails if the first + argument is not a string or array of strings, and if arg 2 is not convertable + to a number. + + The following values will pass: + + validate_slength("discombobulate",17) + validate_slength(["discombobulate","moo"],17) + + The following valueis will not: + + validate_slength("discombobulate",1) + validate_slength(["discombobulate","thermometer"],5) + + ENDHEREDOC + + raise Puppet::ParseError, ("validate_slength(): Wrong number of arguments (#{args.length}; must be = 2)") unless args.length == 2 + + unless (args[0].is_a?(String) or args[0].is_a?(Array)) + raise Puppet::ParseError, ("validate_slength(): please pass a string, or an array of strings - what you passed didn't work for me at all - #{args[0].class}") + end + + begin + max_length = args[1].to_i + rescue NoMethodError => e + raise Puppet::ParseError, ("validate_slength(): Couldn't convert whatever you passed as the length parameter to an integer - sorry: " + e.message ) + end + + raise Puppet::ParseError, ("validate_slength(): please pass a positive number as max_length") unless max_length > 0 + + case args[0] + when String + raise Puppet::ParseError, ("validate_slength(): #{args[0].inspect} is #{args[0].length} characters. It should have been less than or equal to #{max_length} characters") unless args[0].length <= max_length + when Array + args[0].each do |arg| + if arg.is_a?(String) + unless ( arg.is_a?(String) and arg.length <= max_length ) + raise Puppet::ParseError, ("validate_slength(): #{arg.inspect} is #{arg.length} characters. It should have been less than or equal to #{max_length} characters") + end + else + raise Puppet::ParseError, ("validate_slength(): #{arg.inspect} is not a string, it's a #{arg.class}") + end + end + else + raise Puppet::ParseError, ("validate_slength(): please pass a string, or an array of strings - what you passed didn't work for me at all - #{args[0].class}") + end + end +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/validate_string.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_string.rb new file mode 100644 index 000000000..e667794a6 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/validate_string.rb @@ -0,0 +1,33 @@ +module Puppet::Parser::Functions + + newfunction(:validate_string, :doc => <<-'ENDHEREDOC') do |args| + Validate that all passed values are string data structures. Abort catalog + compilation if any value fails this check. + + The following values will pass: + + $my_string = "one two" + validate_string($my_string, 'three') + + The following values will fail, causing compilation to abort: + + validate_string(true) + validate_string([ 'some', 'array' ]) + $undefined = undef + validate_string($undefined) + + ENDHEREDOC + + unless args.length > 0 then + raise Puppet::ParseError, ("validate_string(): wrong number of arguments (#{args.length}; must be > 0)") + end + + args.each do |arg| + unless arg.is_a?(String) + raise Puppet::ParseError, ("#{arg.inspect} is not a string. It looks to be a #{arg.class}") + end + end + + end + +end diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/values.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/values.rb new file mode 100644 index 000000000..16067561b --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/values.rb @@ -0,0 +1,39 @@ +# +# values.rb +# + +module Puppet::Parser::Functions + newfunction(:values, :type => :rvalue, :doc => <<-EOS +When given a hash this function will return the values of that hash. + +*Examples:* + + $hash = { + 'a' => 1, + 'b' => 2, + 'c' => 3, + } + values($hash) + +This example would return: + + [1,2,3] + EOS + ) do |arguments| + + raise(Puppet::ParseError, "values(): Wrong number of arguments " + + "given (#{arguments.size} for 1)") if arguments.size < 1 + + hash = arguments[0] + + unless hash.is_a?(Hash) + raise(Puppet::ParseError, 'values(): Requires hash to work with') + end + + result = hash.values + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/values_at.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/values_at.rb new file mode 100644 index 000000000..d3e69d97f --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/values_at.rb @@ -0,0 +1,98 @@ +# +# values_at.rb +# + +module Puppet::Parser::Functions + newfunction(:values_at, :type => :rvalue, :doc => <<-EOS +Finds value inside an array based on location. + +The first argument is the array you want to analyze, and the second element can +be a combination of: + +* A single numeric index +* A range in the form of 'start-stop' (eg. 4-9) +* An array combining the above + +*Examples*: + + values_at(['a','b','c'], 2) + +Would return ['c']. + + values_at(['a','b','c'], ["0-1"]) + +Would return ['a','b']. + + values_at(['a','b','c','d','e'], [0, "2-3"]) + +Would return ['a','c','d']. + EOS + ) do |arguments| + + raise(Puppet::ParseError, "values_at(): Wrong number of " + + "arguments given (#{arguments.size} for 2)") if arguments.size < 2 + + array = arguments.shift + + unless array.is_a?(Array) + raise(Puppet::ParseError, 'values_at(): Requires array to work with') + end + + indices = [arguments.shift].flatten() # Get them all ... Pokemon ... + + if not indices or indices.empty? + raise(Puppet::ParseError, 'values_at(): You must provide ' + + 'at least one positive index to collect') + end + + result = [] + indices_list = [] + + indices.each do |i| + if m = i.match(/^(\d+)(\.\.\.?|\-)(\d+)$/) + start = m[1].to_i + stop = m[3].to_i + + type = m[2] + + if start > stop + raise(Puppet::ParseError, 'values_at(): Stop index in ' + + 'given indices range is smaller than the start index') + elsif stop > array.size - 1 # First element is at index 0 is it not? + raise(Puppet::ParseError, 'values_at(): Stop index in ' + + 'given indices range exceeds array size') + end + + range = case type + when /^(\.\.|\-)$/ then (start .. stop) + when /^(\.\.\.)$/ then (start ... stop) # Exclusive of last element ... + end + + range.each { |i| indices_list << i.to_i } + else + # Only positive numbers allowed in this case ... + if not i.match(/^\d+$/) + raise(Puppet::ParseError, 'values_at(): Unknown format ' + + 'of given index') + end + + # In Puppet numbers are often string-encoded ... + i = i.to_i + + if i > array.size - 1 # Same story. First element is at index 0 ... + raise(Puppet::ParseError, 'values_at(): Given index ' + + 'exceeds array size') + end + + indices_list << i + end + end + + # We remove nil values as they make no sense in Puppet DSL ... + result = indices_list.collect { |i| array[i] }.compact + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/parser/functions/zip.rb b/deployment/modules/stdlib/lib/puppet/parser/functions/zip.rb new file mode 100644 index 000000000..2b56e9ca0 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/parser/functions/zip.rb @@ -0,0 +1,65 @@ +# +# zip.rb +# + +module Puppet::Parser::Functions + newfunction(:zip, :type => :rvalue, :doc => <<-EOS +Takes one element from first array and merges corresponding elements from second array. This generates a sequence of n-element arrays, where n is one more than the count of arguments. + +*Example:* + + zip(['1','2','3'],['4','5','6']) + +Would result in: + + ["1", "4"], ["2", "5"], ["3", "6"] + EOS + ) do |arguments| + + # Technically we support three arguments but only first is mandatory ... + raise(Puppet::ParseError, "zip(): Wrong number of arguments " + + "given (#{arguments.size} for 2)") if arguments.size < 2 + + a = arguments[0] + b = arguments[1] + + unless a.is_a?(Array) and b.is_a?(Array) + raise(Puppet::ParseError, 'zip(): Requires array to work with') + end + + flatten = arguments[2] if arguments[2] + + if flatten + klass = flatten.class + + # We can have either true or false, or string which resembles boolean ... + unless [FalseClass, TrueClass, String].include?(klass) + raise(Puppet::ParseError, 'zip(): Requires either ' + + 'boolean or string to work with') + end + + if flatten.is_a?(String) + # We consider all the yes, no, y, n and so on too ... + flatten = case flatten + # + # This is how undef looks like in Puppet ... + # We yield false in this case. + # + when /^$/, '' then false # Empty string will be false ... + when /^(1|t|y|true|yes)$/ then true + when /^(0|f|n|false|no)$/ then false + when /^(undef|undefined)$/ then false # This is not likely to happen ... + else + raise(Puppet::ParseError, 'zip(): Unknown type of boolean given') + end + end + end + + result = a.zip(b) + result = flatten ? result.flatten : result + + return result + end +end + +# vim: set ts=2 sw=2 et : diff --git a/deployment/modules/stdlib/lib/puppet/provider/file_line/ruby.rb b/deployment/modules/stdlib/lib/puppet/provider/file_line/ruby.rb new file mode 100644 index 000000000..a3219d3d4 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/provider/file_line/ruby.rb @@ -0,0 +1,59 @@ + +Puppet::Type.type(:file_line).provide(:ruby) do + + def exists? + lines.find do |line| + line.chomp == resource[:line].chomp + end + end + + def create + if resource[:match] + handle_create_with_match() + else + handle_create_without_match() + end + end + + def destroy + local_lines = lines + File.open(resource[:path],'w') do |fh| + fh.write(local_lines.reject{|l| l.chomp == resource[:line] }.join('')) + end + end + + private + def lines + # If this type is ever used with very large files, we should + # write this in a different way, using a temp + # file; for now assuming that this type is only used on + # small-ish config files that can fit into memory without + # too much trouble. + @lines ||= File.readlines(resource[:path]) + end + + def handle_create_with_match() + regex = resource[:match] ? Regexp.new(resource[:match]) : nil + match_count = lines.select { |l| regex.match(l) }.size + if match_count > 1 + raise Puppet::Error, "More than one line in file '#{resource[:path]}' matches pattern '#{resource[:match]}'" + end + File.open(resource[:path], 'w') do |fh| + lines.each do |l| + fh.puts(regex.match(l) ? resource[:line] : l) + end + + if (match_count == 0) + fh.puts(resource[:line]) + end + end + end + + def handle_create_without_match + File.open(resource[:path], 'a') do |fh| + fh.puts resource[:line] + end + end + + +end diff --git a/deployment/modules/stdlib/lib/puppet/type/anchor.rb b/deployment/modules/stdlib/lib/puppet/type/anchor.rb new file mode 100644 index 000000000..fe1e5aa19 --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/type/anchor.rb @@ -0,0 +1,46 @@ +Puppet::Type.newtype(:anchor) do + desc <<-'ENDOFDESC' + A simple resource type intended to be used as an anchor in a composite class. + + In Puppet 2.6, when a class declares another class, the resources in the + interior class are not contained by the exterior class. This interacts badly + with the pattern of composing complex modules from smaller classes, as it + makes it impossible for end users to specify order relationships between the + exterior class and other modules. + + The anchor type lets you work around this. By sandwiching any interior + classes between two no-op resources that _are_ contained by the exterior + class, you can ensure that all resources in the module are contained. + + class ntp { + # These classes will have the correct order relationship with each + # other. However, without anchors, they won't have any order + # relationship to Class['ntp']. + class { 'ntp::package': } + -> class { 'ntp::config': } + -> class { 'ntp::service': } + + # These two resources "anchor" the composed classes within the ntp + # class. + anchor { 'ntp::begin': } -> Class['ntp::package'] + Class['ntp::service'] -> anchor { 'ntp::end': } + } + + This allows the end user of the ntp module to establish require and before + relationships with Class['ntp']: + + class { 'ntp': } -> class { 'mcollective': } + class { 'mcollective': } -> class { 'ntp': } + + ENDOFDESC + + newparam :name do + desc "The name of the anchor resource." + end + + def refresh + # We don't do anything with them, but we need this to + # show that we are "refresh aware" and not break the + # chain of propagation. + end +end diff --git a/deployment/modules/stdlib/lib/puppet/type/file_line.rb b/deployment/modules/stdlib/lib/puppet/type/file_line.rb new file mode 100644 index 000000000..f71a4bc7b --- /dev/null +++ b/deployment/modules/stdlib/lib/puppet/type/file_line.rb @@ -0,0 +1,70 @@ +Puppet::Type.newtype(:file_line) do + + desc <<-EOT + Ensures that a given line is contained within a file. The implementation + matches the full line, including whitespace at the beginning and end. If + the line is not contained in the given file, Puppet will add the line to + ensure the desired state. Multiple resources may be declared to manage + multiple lines in the same file. + + Example: + + file_line { 'sudo_rule': + path => '/etc/sudoers', + line => '%sudo ALL=(ALL) ALL', + } + file_line { 'sudo_rule_nopw': + path => '/etc/sudoers', + line => '%sudonopw ALL=(ALL) NOPASSWD: ALL', + } + + In this example, Puppet will ensure both of the specified lines are + contained in the file /etc/sudoers. + + EOT + + ensurable do + defaultvalues + defaultto :present + end + + newparam(:name, :namevar => true) do + desc 'An arbitrary name used as the identity of the resource.' + end + + newparam(:match) do + desc 'An optional regular expression to run against existing lines in the file;\n' + + 'if a match is found, we replace that line rather than adding a new line.' + end + + newparam(:line) do + desc 'The line to be appended to the file located by the path parameter.' + end + + newparam(:path) do + desc 'The file Puppet will ensure contains the line specified by the line parameter.' + validate do |value| + unless (Puppet.features.posix? and value =~ /^\//) or (Puppet.features.microsoft_windows? and (value =~ /^.:\// or value =~ /^\/\/[^\/]+\/[^\/]+/)) + raise(Puppet::Error, "File paths must be fully qualified, not '#{value}'") + end + end + end + + # Autorequire the file resource if it's being managed + autorequire(:file) do + self[:path] + end + + validate do + unless self[:line] and self[:path] + raise(Puppet::Error, "Both line and path are required attributes") + end + + if (self[:match]) + unless Regexp.new(self[:match]).match(self[:line]) + raise(Puppet::Error, "When providing a 'match' parameter, the value must be a regex that matches against the value of your 'line' parameter") + end + end + + end +end diff --git a/deployment/modules/stdlib/manifests/init.pp b/deployment/modules/stdlib/manifests/init.pp new file mode 100644 index 000000000..500ad770d --- /dev/null +++ b/deployment/modules/stdlib/manifests/init.pp @@ -0,0 +1,20 @@ +# Class: stdlib +# +# This module manages stdlib. Most of stdlib's features are automatically +# loaded by Puppet, but this class should be declared in order to use the +# standardized run stages. +# +# Parameters: none +# +# Actions: +# +# Declares all other classes in the stdlib module. Currently, this consists +# of stdlib::stages. +# +# Requires: nothing +# +class stdlib { + + class { 'stdlib::stages': } + +} diff --git a/deployment/modules/stdlib/manifests/stages.pp b/deployment/modules/stdlib/manifests/stages.pp new file mode 100644 index 000000000..eb15fd650 --- /dev/null +++ b/deployment/modules/stdlib/manifests/stages.pp @@ -0,0 +1,43 @@ +# Class: stdlib::stages +# +# This class manages a standard set of run stages for Puppet. It is managed by +# the stdlib class, and should not be declared independently. +# +# The high level stages are (in order): +# +# * setup +# * main +# * runtime +# * setup_infra +# * deploy_infra +# * setup_app +# * deploy_app +# * deploy +# +# Parameters: none +# +# Actions: +# +# Declares various run-stages for deploying infrastructure, +# language runtimes, and application layers. +# +# Requires: nothing +# +# Sample Usage: +# +# node default { +# include stdlib +# class { java: stage => 'runtime' } +# } +# +class stdlib::stages { + + stage { 'setup': before => Stage['main'] } + stage { 'runtime': require => Stage['main'] } + -> stage { 'setup_infra': } + -> stage { 'deploy_infra': } + -> stage { 'setup_app': } + -> stage { 'deploy_app': } + -> stage { 'deploy': } + +} diff --git a/deployment/modules/stdlib/metadata.json b/deployment/modules/stdlib/metadata.json new file mode 100644 index 000000000..5d3308e21 --- /dev/null +++ b/deployment/modules/stdlib/metadata.json @@ -0,0 +1,270 @@ +{ + "types": [ + { + "doc": " A simple resource type intended to be used as an anchor in a composite class.\n\n In Puppet 2.6, when a class declares another class, the resources in the\n interior class are not contained by the exterior class. This interacts badly\n with the pattern of composing complex modules from smaller classes, as it\n makes it impossible for end users to specify order relationships between the\n exterior class and other modules.\n\n The anchor type lets you work around this. By sandwiching any interior\n classes between two no-op resources that _are_ contained by the exterior\n class, you can ensure that all resources in the module are contained.\n\n class ntp {\n # These classes will have the correct order relationship with each\n # other. However, without anchors, they won't have any order\n # relationship to Class['ntp'].\n class { 'ntp::package': }\n -> class { 'ntp::config': }\n -> class { 'ntp::service': }\n\n # These two resources \"anchor\" the composed classes within the ntp\n # class.\n anchor { 'ntp::begin': } -> Class['ntp::package']\n Class['ntp::service'] -> anchor { 'ntp::end': }\n }\n\n This allows the end user of the ntp module to establish require and before\n relationships with Class['ntp']:\n\n class { 'ntp': } -> class { 'mcollective': }\n class { 'mcollective': } -> class { 'ntp': }\n\n", + "parameters": [ + { + "doc": "The name of the anchor resource.", + "name": "name" + } + ], + "name": "anchor", + "properties": [ + + ] + }, + { + "doc": " Ensures that a given line is contained within a file. The implementation\n matches the full line, including whitespace at the beginning and end. If\n the line is not contained in the given file, Puppet will add the line to\n ensure the desired state. Multiple resources may be declared to manage\n multiple lines in the same file.\n\n Example:\n\n file_line { 'sudo_rule':\n path => '/etc/sudoers',\n line => '%sudo ALL=(ALL) ALL',\n }\n file_line { 'sudo_rule_nopw':\n path => '/etc/sudoers',\n line => '%sudonopw ALL=(ALL) NOPASSWD: ALL',\n }\n\n In this example, Puppet will ensure both of the specified lines are\n contained in the file /etc/sudoers.\n\n", + "providers": [ + { + "doc": "", + "name": "ruby" + } + ], + "parameters": [ + { + "doc": "An arbitrary name used as the identity of the resource.", + "name": "name" + }, + { + "doc": "An optional regular expression to run against existing lines in the file;\\nif a match is found, we replace that line rather than adding a new line.", + "name": "match" + }, + { + "doc": "The line to be appended to the file located by the path parameter.", + "name": "line" + }, + { + "doc": "The file Puppet will ensure contains the line specified by the line parameter.", + "name": "path" + } + ], + "name": "file_line", + "properties": [ + { + "doc": "The basic property that the resource should be in. Valid values are `present`, `absent`.", + "name": "ensure" + } + ] + } + ], + "license": "Apache 2.0", + "checksums": { + "spec/unit/puppet/parser/functions/uriescape_spec.rb": "8d9e15156d93fe29bfe91a2e83352ff4", + "Gemfile": "a7144ac8fdb2255ed7badb6b54f6c342", + "spec/unit/facter/root_home_spec.rb": "4f4c4236ac2368d2e27fd2f3eb606a19", + "spec/unit/puppet/parser/functions/size_spec.rb": "d126b696b21a8cd754d58f78ddba6f06", + "spec/unit/puppet/parser/functions/shuffle_spec.rb": "2141a54d2fb3cf725b88184d639677f4", + "spec/unit/puppet/parser/functions/validate_re_spec.rb": "b21292ad2f30c0d43ab2f0c2df0ba7d5", + "lib/puppet/parser/functions/flatten.rb": "25777b76f9719162a8bab640e5595b7a", + "lib/puppet/parser/functions/ensure_packages.rb": "ca852b2441ca44b91a984094de4e3afc", + "lib/puppet/parser/functions/validate_augeas.rb": "d4acca7b8a9fdada9ae39e5101902cc1", + "spec/unit/puppet/parser/functions/unique_spec.rb": "2df8b3b2edb9503943cb4dcb4a371867", + "tests/has_ip_network.pp": "abc05686797a776ea8c054657e6f7456", + "spec/fixtures/manifests/site.pp": "d41d8cd98f00b204e9800998ecf8427e", + "lib/puppet/parser/functions/defined_with_params.rb": "ffab4433d03f32b551f2ea024a2948fc", + "lib/puppet/parser/functions/size.rb": "8972d48c0f9e487d659bd7326b40b642", + "lib/puppet/parser/functions/has_ip_address.rb": "ee207f47906455a5aa49c4fb219dd325", + "lib/facter/util/puppet_settings.rb": "9f1d2593d0ae56bfca89d4b9266aeee1", + "spec/unit/puppet/parser/functions/any2array_spec.rb": "167e114cfa222de971bf8be141766b6a", + "spec/unit/facter/pe_required_facts_spec.rb": "0ec83db2a004a0d7f6395b34939c53b9", + "spec/unit/puppet/parser/functions/bool2num_spec.rb": "67c3055d5d4e4c9fbcaca82038a09081", + "lib/facter/root_home.rb": "f559294cceafcf70799339627d94871d", + "lib/puppet/parser/functions/loadyaml.rb": "2b912f257aa078e376d3b3f6a86c2a00", + "spec/unit/puppet/parser/functions/is_float_spec.rb": "171fc0e382d9856c2d8db2b70c9ec9cd", + "lib/puppet/type/anchor.rb": "bbd36bb49c3b554f8602d8d3df366c0c", + "lib/puppet/parser/functions/getparam.rb": "4dd7a0e35f4a3780dcfc9b19b4e0006e", + "lib/facter/facter_dot_d.rb": "b35b8b59ec579901444f984127f0b833", + "lib/puppet/parser/functions/strftime.rb": "e02e01a598ca5d7d6eee0ba22440304a", + "lib/puppet/parser/functions/max.rb": "f652fd0b46ef7d2fbdb42b141f8fdd1d", + "spec/spec_helper.rb": "4449b0cafd8f7b2fb440c0cdb0a1f2b3", + "lib/puppet/parser/functions/merge.rb": "52281fe881b762e2adfef20f58dc4180", + "lib/puppet/parser/functions/validate_slength.rb": "0ca530d1d3b45c3fe2d604c69acfc22f", + "spec/unit/puppet/parser/functions/suffix_spec.rb": "c3eed8e40066f2ad56264405c4192f2e", + "spec/unit/puppet/parser/functions/validate_bool_spec.rb": "32a580f280ba62bf17ccd30460d357bd", + "spec/unit/puppet/parser/functions/str2bool_spec.rb": "60e3eaea48b0f6efccc97010df7d912c", + "lib/puppet/parser/functions/reject.rb": "689f6a7c961a55fe9dcd240921f4c7f9", + "lib/puppet/parser/functions/delete.rb": "9b17b9f7f820adf02360147c1a2f4279", + "lib/puppet/parser/functions/strip.rb": "273d547c7b05c0598556464dfd12f5fd", + "lib/puppet/parser/functions/values.rb": "066a6e4170e5034edb9a80463dff2bb5", + "LICENSE": "38a048b9d82e713d4e1b2573e370a756", + "lib/puppet/parser/functions/is_array.rb": "875ca4356cb0d7a10606fb146b4a3d11", + "spec/unit/puppet/parser/functions/strip_spec.rb": "a01796bebbdabd3fad12b0662ea5966e", + "lib/puppet/parser/functions/swapcase.rb": "4902f38f0b9292afec66d40fee4b02ec", + "lib/puppet/parser/functions/has_ip_network.rb": "b4d726c8b2a0afac81ced8a3a28aa731", + "spec/unit/puppet/parser/functions/validate_array_spec.rb": "bcd231229554785c4270ca92ef99cb60", + "lib/puppet/parser/functions/validate_re.rb": "c6664b3943bc820415a43f16372dc2a9", + "lib/puppet/parser/functions/time.rb": "08d88d52abd1e230e3a2f82107545d48", + "lib/puppet/parser/functions/is_numeric.rb": "0a9bcc49e8f57af81bdfbb7e7c3a575c", + "spec/unit/puppet/parser/functions/merge_spec.rb": "a63c0bc2f812e27fbef570d834ef61ce", + "lib/puppet/parser/functions/count.rb": "9eb74eccd93e2b3c87fd5ea14e329eba", + "spec/unit/puppet/parser/functions/values_at_spec.rb": "de45fd8abbc4c037c3c4fac2dcf186f9", + "spec/monkey_patches/publicize_methods.rb": "ce2c98f38b683138c5ac649344a39276", + "spec/unit/puppet/parser/functions/is_hash_spec.rb": "408e121a5e30c4c5c4a0a383beb6e209", + "lib/puppet/parser/functions/chop.rb": "4691a56e6064b792ed4575e4ad3f3d20", + "spec/unit/puppet/parser/functions/validate_cmd_spec.rb": "538db08292a0ecc4cd902a14aaa55d74", + "spec/unit/puppet/parser/functions/is_integer_spec.rb": "a302cf1de5ccb494ca9614d2fc2b53c5", + "spec/functions/ensure_resource_spec.rb": "3423a445e13efc7663a71c6641d49d07", + "spec/unit/puppet/parser/functions/keys_spec.rb": "35cc2ed490dc68da6464f245dfebd617", + "manifests/init.pp": "f2ba5f36e7227ed87bbb69034fc0de8b", + "lib/puppet/parser/functions/dirname.rb": "bef7214eb89db3eb8f7ee5fc9dca0233", + "lib/puppet/parser/functions/validate_hash.rb": "e9cfaca68751524efe16ecf2f958a9a0", + "lib/puppet/parser/functions/join_keys_to_values.rb": "f29da49531228f6ca5b3aa0df00a14c2", + "spec/unit/puppet/parser/functions/delete_spec.rb": "0d84186ea618523b4b2a4ca0b5a09c9e", + "lib/puppet/parser/functions/validate_string.rb": "6afcbc51f83f0714348b8d61e06ea7eb", + "spec/unit/puppet/parser/functions/rstrip_spec.rb": "a408e933753c9c323a05d7079d32cbb3", + "spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb": "c67b71737bee9936f5261d41a37bad46", + "spec/unit/puppet/parser/functions/concat_spec.rb": "c21aaa84609f92290d5ffb2ce8ea4bf5", + "lib/puppet/parser/functions/unique.rb": "217ccce6d23235af92923f50f8556963", + "CHANGELOG": "344383410cb78409f0c59ecf38e8c21a", + "lib/puppet/parser/functions/member.rb": "541e67d06bc4155e79b00843a125e9bc", + "spec/unit/puppet/parser/functions/validate_string_spec.rb": "64a4f681084cba55775a070f7fab5e0c", + "lib/facter/puppet_vardir.rb": "c7ddc97e8a84ded3dd93baa5b9b3283d", + "lib/puppet/parser/functions/pick.rb": "2bede116a0651405c47e650bbf942abe", + "spec/unit/puppet/parser/functions/parseyaml_spec.rb": "65dfed872930ffe0d21954c15daaf498", + "lib/puppet/parser/functions/delete_at.rb": "6bc24b79390d463d8be95396c963381a", + "lib/puppet/parser/functions/zip.rb": "a80782461ed9465f0cd0c010936f1855", + "tests/file_line.pp": "67727539aa7b7dd76f06626fe734f7f7", + "lib/puppet/parser/functions/ensure_resource.rb": "3f68b8e17a16bfd01455cd73f8e324ba", + "lib/puppet/parser/functions/num2bool.rb": "605c12fa518c87ed2c66ae153e0686ce", + "spec/unit/puppet/parser/functions/grep_spec.rb": "78179537496a7150469e591a95e255d8", + "lib/puppet/parser/functions/keys.rb": "eb6ac815ea14fbf423580ed903ef7bad", + "spec/unit/puppet/parser/functions/num2bool_spec.rb": "8cd5b46b7c8e612dfae3362e3a68a5f9", + "lib/puppet/parser/functions/parsejson.rb": "e7f968c34928107b84cd0860daf50ab1", + "lib/puppet/parser/functions/is_mac_address.rb": "288bd4b38d4df42a83681f13e7eaaee0", + "lib/puppet/parser/functions/join.rb": "b28087823456ca5cf943de4a233ac77f", + "spec/unit/puppet/parser/functions/type_spec.rb": "422f2c33458fe9b0cc9614d16f7573ba", + "lib/puppet/parser/functions/downcase.rb": "9204a04c2a168375a38d502db8811bbe", + "spec/unit/puppet/parser/functions/validate_augeas_spec.rb": "1d5bcfbf97dc56b45734248a14358d4f", + "spec/unit/puppet/parser/functions/has_ip_address_spec.rb": "f53c7baeaf024ff577447f6c28c0f3a7", + "lib/puppet/parser/functions/is_function_available.rb": "88c63869cb5df3402bc9756a8d40c16d", + "lib/puppet/parser/functions/prefix.rb": "21fd6a2c1ee8370964346b3bfe829d2b", + "spec/watchr.rb": "b588ddf9ef1c19ab97aa892cc776da73", + "spec/unit/puppet/parser/functions/has_key_spec.rb": "3e4e730d98bbdfb88438b6e08e45868e", + "lib/puppet/parser/functions/values_at.rb": "094ac110ce9f7a5b16d0c80a0cf2243c", + "lib/puppet/parser/functions/fqdn_rotate.rb": "20743a138c56fc806a35cb7b60137dbc", + "lib/puppet/parser/functions/rstrip.rb": "8a0d69876bdbc88a2054ba41c9c38961", + "spec/unit/puppet/parser/functions/validate_slength_spec.rb": "a1b4d805149dc0143e9a57e43e1f84bf", + "spec/functions/ensure_packages_spec.rb": "935b4aec5ab36bdd0458c1a9b2a93ad5", + "lib/puppet/parser/functions/suffix.rb": "109279db4180441e75545dbd5f273298", + "lib/puppet/parser/functions/str2saltedsha512.rb": "49afad7b386be38ce53deaefef326e85", + "spec/unit/puppet/parser/functions/count_spec.rb": "db98ef89752a7112425f0aade10108e0", + "lib/puppet/parser/functions/hash.rb": "9d072527dfc7354b69292e9302906530", + "manifests/stages.pp": "cc6ed1751d334b0ea278c0335c7f0b5a", + "spec/unit/puppet/parser/functions/is_ip_address_spec.rb": "6040a9bae4e5c853966148b634501157", + "spec/unit/facter/pe_version_spec.rb": "ef031cca838f36f99b1dab3259df96a5", + "spec/unit/puppet/parser/functions/get_module_path_spec.rb": "b7ea196f548b1a9a745ab6671295ab27", + "lib/puppet/parser/functions/is_integer.rb": "a50ebc15c30bffd759e4a6f8ec6a0cf3", + "lib/puppet/parser/functions/reverse.rb": "1386371c0f5301055fdf99079e862b3e", + "spec/unit/puppet/parser/functions/has_interface_with_spec.rb": "7c16d731c518b434c81b8cb2227cc916", + "README_SPECS.markdown": "82bb4c6abbb711f40778b162ec0070c1", + "spec/unit/puppet/parser/functions/is_domain_name_spec.rb": "8eed3a9eb9334bf6a473ad4e2cabc2ec", + "spec/unit/puppet/parser/functions/join_spec.rb": "c3b50c39390a86b493511be2c6722235", + "lib/puppet/parser/functions/chomp.rb": "719d46923d75251f7b6b68b6e015cccc", + "lib/puppet/parser/functions/is_string.rb": "2bd9a652bbb2668323eee6c57729ff64", + "spec/unit/puppet/parser/functions/is_array_spec.rb": "8c020af9c360abdbbf1ba887bb26babe", + "Modulefile": "351bba73290cd526ca7bacd4c7d250dc", + "spec/unit/puppet/parser/functions/reject_spec.rb": "8e16c9f064870e958b6278261e480954", + "spec/unit/puppet/type/file_line_spec.rb": "d9f4e08e8b98e565a07f1b995593fa89", + "spec/unit/puppet/parser/functions/lstrip_spec.rb": "1fc2c2d80b5f724a358c3cfeeaae6249", + "lib/puppet/parser/functions/type.rb": "62f914d6c90662aaae40c5539701be60", + "lib/puppet/parser/functions/shuffle.rb": "6445e6b4dc62c37b184a60eeaf34414b", + "lib/puppet/parser/functions/has_key.rb": "7cd9728c38f0b0065f832dabd62b0e7e", + "lib/puppet/parser/functions/concat.rb": "f28a09811ff4d19bb5e7a540e767d65c", + "spec/unit/puppet/parser/functions/capitalize_spec.rb": "82a4209a033fc88c624f708c12e64e2a", + "tests/init.pp": "1d98070412c76824e66db4b7eb74d433", + "lib/puppet/provider/file_line/ruby.rb": "a445a57f9b884037320ea37307dbc92b", + "tests/has_ip_address.pp": "93ce02915f67ddfb43a049b2b84ef391", + "spec/unit/puppet/parser/functions/min_spec.rb": "bf80bf58261117bb24392670b624a611", + "lib/puppet/parser/functions/to_bytes.rb": "83f23c33adbfa42b2a9d9fc2db3daeb4", + "lib/puppet/parser/functions/sort.rb": "504b033b438461ca4f9764feeb017833", + "lib/puppet/parser/functions/capitalize.rb": "14481fc8c7c83fe002066ebcf6722f17", + "lib/puppet/type/file_line.rb": "3e8222cb58f3503b3ea7de3647c602a0", + "lib/puppet/parser/functions/has_interface_with.rb": "8d3ebca805dc6edb88b6b7a13d404787", + "spec/functions/getparam_spec.rb": "122f37cf9ec7489f1dae10db39c871b5", + "Rakefile": "f37e6131fe7de9a49b09d31596f5fbf1", + "spec/unit/puppet/parser/functions/downcase_spec.rb": "b0197829512f2e92a2d2b06ce8e2226f", + "spec/unit/puppet/parser/functions/max_spec.rb": "5562bccc643443af7e4fa7c9d1e52b8b", + "lib/puppet/parser/functions/validate_absolute_path.rb": "385137ac24a2dec6cecc4e6ea75be442", + "spec/unit/puppet/parser/functions/getvar_spec.rb": "842bf88d47077a9ae64097b6e39c3364", + "spec/unit/puppet/parser/functions/sort_spec.rb": "7039cd230a94e95d9d1de2e1094acae2", + "spec/unit/puppet/parser/functions/strftime_spec.rb": "bf140883ecf3254277306fa5b25f0344", + "spec/unit/puppet/parser/functions/is_mac_address_spec.rb": "644cd498b426ff2f9ea9cbc5d8e141d7", + "spec/unit/puppet/parser/functions/empty_spec.rb": "028c30267d648a172d8a81a9262c3abe", + "lib/puppet/parser/functions/is_domain_name.rb": "fba9f855df3bbf90d72dfd5201f65d2b", + "lib/puppet/parser/functions/get_module_path.rb": "d4bf50da25c0b98d26b75354fa1bcc45", + "spec/unit/puppet/provider/file_line/ruby_spec.rb": "e8cd7432739cb212d40a9148523bd4d7", + "spec/unit/puppet/parser/functions/reverse_spec.rb": "48169990e59081ccbd112b6703418ce4", + "spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb": "1de174be8835ba6fef86b590887bb2cc", + "spec/unit/puppet/parser/functions/prefix_spec.rb": "16a95b321d76e773812693c80edfbe36", + "spec/spec.opts": "a600ded995d948e393fbe2320ba8e51c", + "spec/monkey_patches/alias_should_to_must.rb": "7cd4065c63f06f1ab3aaa1c5f92af947", + "lib/puppet/parser/functions/uriescape.rb": "9ebc34f1b2f319626512b8cd7cde604c", + "lib/puppet/parser/functions/floor.rb": "c5a960e9714810ebb99198ff81a11a3b", + "lib/puppet/parser/functions/empty.rb": "ae92905c9d94ddca30bf56b7b1dabedf", + "spec/unit/puppet/parser/functions/range_spec.rb": "91d69115dea43f62a2dca9a10467d836", + "tests/has_interface_with.pp": "59c98b4af0d39fc11d1ef4c7a6dc8f7a", + "spec/unit/puppet/parser/functions/is_function_available.rb": "069ef7490eba66424cab75444f36828a", + "README_DEVELOPER.markdown": "220a8b28521b5c5d2ea87c4ddb511165", + "spec/unit/puppet/parser/functions/flatten_spec.rb": "583c9a70f93e492cfb22ffa1811f6aa0", + "lib/puppet/parser/functions/upcase.rb": "a5744a74577cfa136fca2835e75888d3", + "lib/puppet/parser/functions/str2bool.rb": "c822a8944747f5624b13f2da0df8db21", + "lib/puppet/parser/functions/is_hash.rb": "8c7d9a05084dab0389d1b779c8a05b1a", + "lib/puppet/parser/functions/abs.rb": "32161bd0435fdfc2aec2fc559d2b454b", + "spec/unit/puppet/parser/functions/validate_hash_spec.rb": "8529c74051ceb71e6b1b97c9cecdf625", + "spec/unit/puppet/parser/functions/member_spec.rb": "067c60985efc57022ca1c5508d74d77f", + "README.markdown": "b63097a958f22abf7999d475a6a4d32a", + "spec/unit/puppet/parser/functions/values_spec.rb": "0ac9e141ed1f612d7cc224f747b2d1d9", + "lib/puppet/parser/functions/validate_cmd.rb": "0319a15d24fd077ebabc2f79969f6ab5", + "lib/puppet/parser/functions/is_float.rb": "f1b0d333061d31bf0c25bd4c33dc134b", + "lib/puppet/parser/functions/bool2num.rb": "8e627eee990e811e35e7e838c586bd77", + "lib/puppet/parser/functions/validate_bool.rb": "4ddffdf5954b15863d18f392950b88f4", + "lib/puppet/parser/functions/grep.rb": "5682995af458b05f3b53dd794c4bf896", + "spec/unit/puppet/parser/functions/upcase_spec.rb": "813668919bc62cdd1d349dafc19fbbb3", + "spec/unit/puppet/parser/functions/parsejson_spec.rb": "37ab84381e035c31d6a3dd9bf73a3d53", + "spec/unit/puppet/parser/functions/squeeze_spec.rb": "df5b349c208a9a2a4d4b8e6d9324756f", + "spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb": "07839082d24d5a7628fd5bce6c8b35c3", + "spec/unit/puppet/parser/functions/chop_spec.rb": "4e9534d25b952b261c9f46add677c390", + "lib/puppet/parser/functions/squeeze.rb": "541f85b4203b55c9931d3d6ecd5c75f8", + "lib/puppet/parser/functions/lstrip.rb": "210b103f78622e099f91cc2956b6f741", + "spec/unit/puppet/type/anchor_spec.rb": "a5478a72a7fab2d215f39982a9230c18", + "lib/facter/pe_version.rb": "4a9353952963b011759f3e6652a10da5", + "spec/unit/puppet/parser/functions/hash_spec.rb": "826337a92d8f7a189b7ac19615db0ed7", + "spec/unit/puppet/parser/functions/floor_spec.rb": "d01ef7dfe0245d7a0a73d7df13cb02e3", + "spec/unit/puppet/parser/functions/time_spec.rb": "b6d0279062779efe5153fe5cfafc5bbd", + "spec/unit/puppet/parser/functions/swapcase_spec.rb": "0660ce8807608cc8f98ad1edfa76a402", + "lib/puppet/parser/functions/validate_array.rb": "72b29289b8af1cfc3662ef9be78911b8", + "lib/puppet/parser/functions/is_ip_address.rb": "a714a736c1560e8739aaacd9030cca00", + "lib/puppet/parser/functions/getvar.rb": "10bf744212947bc6a7bfd2c9836dbd23", + "RELEASE_PROCESS.markdown": "94b92bc99ac4106ba1a74d5c04e520f9", + "spec/classes/anchor_spec.rb": "695d65275c3ac310d7fa23b91f8bbb4a", + "lib/puppet/parser/functions/any2array.rb": "a81e71d6b67a551d38770ba9a1948a75", + "spec/functions/defined_with_params_spec.rb": "3bdfac38e3d6f06140ff2e926f4ebed2", + "spec/unit/puppet/parser/functions/pick_spec.rb": "aba6247d3925e373272fca6768fd5403", + "spec/unit/puppet/parser/functions/to_bytes_spec.rb": "80aaf68cf7e938e46b5278c1907af6be", + "spec/unit/puppet/parser/functions/is_string_spec.rb": "5c015d8267de852da3a12b984e077092", + "spec/unit/puppet/parser/functions/abs_spec.rb": "0a5864a29a8e9e99acc483268bd5917c", + "spec/unit/facter/util/puppet_settings_spec.rb": "345bcbef720458e25be0190b7638e4d9", + "spec/unit/puppet/parser/functions/zip_spec.rb": "06a86e4e70d2aea63812582aae1d26c4", + "spec/unit/puppet/parser/functions/dirname_spec.rb": "1d7cf70468c2cfa6dacfc75935322395", + "spec/unit/puppet/parser/functions/delete_at_spec.rb": "5a4287356b5bd36a6e4c100421215b8e", + "spec/unit/puppet/parser/functions/chomp_spec.rb": "3cd8e2fe6b12efeffad94cce5b693b7c", + "spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb": "7c7937411b7fe4bb944c0c022d3a96b0", + "lib/puppet/parser/functions/range.rb": "033048bba333fe429e77e0f2e91db25f", + "lib/puppet/parser/functions/parseyaml.rb": "00f10ec1e2b050e23d80c256061ebdd7", + "spec/unit/puppet/parser/functions/is_numeric_spec.rb": "5f08148803b6088c27b211c446ad3658", + "spec/unit/puppet/parser/functions/has_ip_network_spec.rb": "885ea8a4c987b735d683b742bf846cb1", + "lib/puppet/parser/functions/min.rb": "0d2a1b7e735ab251c5469e735fa3f4c6", + "CONTRIBUTING.md": "fdddc4606dc3b6949e981e6bf50bc8e5" + }, + "version": "4.1.0", + "description": "Standard Library for Puppet Modules", + "source": "git://github.com/puppetlabs/puppetlabs-stdlib.git", + "project_page": "https://github.com/puppetlabs/puppetlabs-stdlib", + "summary": "Puppet Module Standard Library", + "dependencies": [ + + ], + "author": "puppetlabs", + "name": "puppetlabs-stdlib" +} \ No newline at end of file diff --git a/deployment/modules/stdlib/spec/classes/anchor_spec.rb b/deployment/modules/stdlib/spec/classes/anchor_spec.rb new file mode 100644 index 000000000..2dd17de9a --- /dev/null +++ b/deployment/modules/stdlib/spec/classes/anchor_spec.rb @@ -0,0 +1,32 @@ +require 'puppet' +require 'rspec-puppet' + +describe "anchorrefresh" do + let(:node) { 'testhost.example.com' } + let :pre_condition do + <<-ANCHORCLASS +class anchored { + anchor { 'anchored::begin': } + ~> anchor { 'anchored::end': } +} + +class anchorrefresh { + notify { 'first': } + ~> class { 'anchored': } + ~> anchor { 'final': } +} + ANCHORCLASS + end + + def apply_catalog_and_return_exec_rsrc + catalog = subject.to_ral + transaction = catalog.apply + transaction.resource_status("Anchor[final]") + end + + it 'propagates events through the anchored class' do + resource = apply_catalog_and_return_exec_rsrc + + expect(resource.restarted).to eq(true) + end +end diff --git a/deployment/modules/stdlib/spec/fixtures/manifests/site.pp b/deployment/modules/stdlib/spec/fixtures/manifests/site.pp new file mode 100644 index 000000000..e69de29bb diff --git a/deployment/modules/stdlib/spec/functions/defined_with_params_spec.rb b/deployment/modules/stdlib/spec/functions/defined_with_params_spec.rb new file mode 100644 index 000000000..28dbab311 --- /dev/null +++ b/deployment/modules/stdlib/spec/functions/defined_with_params_spec.rb @@ -0,0 +1,37 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +require 'rspec-puppet' +describe 'defined_with_params' do + describe 'when a resource is not specified' do + it { should run.with_params().and_raise_error(ArgumentError) } + end + describe 'when compared against a resource with no attributes' do + let :pre_condition do + 'user { "dan": }' + end + it do + should run.with_params('User[dan]', {}).and_return(true) + should run.with_params('User[bob]', {}).and_return(false) + should run.with_params('User[dan]', {'foo' => 'bar'}).and_return(false) + end + end + + describe 'when compared against a resource with attributes' do + let :pre_condition do + 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}' + end + it do + should run.with_params('User[dan]', {}).and_return(true) + should run.with_params('User[dan]', '').and_return(true) + should run.with_params('User[dan]', {'ensure' => 'present'} + ).and_return(true) + should run.with_params('User[dan]', + {'ensure' => 'present', 'managehome' => false} + ).and_return(true) + should run.with_params('User[dan]', + {'ensure' => 'absent', 'managehome' => false} + ).and_return(false) + end + end +end diff --git a/deployment/modules/stdlib/spec/functions/ensure_packages_spec.rb b/deployment/modules/stdlib/spec/functions/ensure_packages_spec.rb new file mode 100644 index 000000000..1c2a328e4 --- /dev/null +++ b/deployment/modules/stdlib/spec/functions/ensure_packages_spec.rb @@ -0,0 +1,42 @@ +#! /usr/bin/env ruby + +require 'spec_helper' +require 'rspec-puppet' + +describe 'ensure_packages' do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + describe 'argument handling' do + it 'fails with no arguments' do + should run.with_params().and_raise_error(Puppet::ParseError) + end + it 'requires an array' do + lambda { scope.function_ensure_packages([['foo']]) }.should_not raise_error + end + it 'fails when given a string' do + should run.with_params('foo').and_raise_error(Puppet::ParseError) + end + end + + context 'given a catalog containing Package[puppet]{ensure => absent}' do + let :pre_condition do + 'package { puppet: ensure => absent }' + end + + # NOTE: should run.with_params has the side effect of making the compiler + # available to the test harness. + it 'has no effect on Package[puppet]' do + should run.with_params(['puppet']) + rsrc = compiler.catalog.resource('Package[puppet]') + rsrc.to_hash.should == {:ensure => "absent"} + end + end + + context 'given a clean catalog' do + it 'declares package resources with ensure => present' do + should run.with_params(['facter']) + rsrc = compiler.catalog.resource('Package[facter]') + rsrc.to_hash.should == {:name => "facter", :ensure => "present"} + end + end +end diff --git a/deployment/modules/stdlib/spec/functions/ensure_resource_spec.rb b/deployment/modules/stdlib/spec/functions/ensure_resource_spec.rb new file mode 100644 index 000000000..2e8aefc52 --- /dev/null +++ b/deployment/modules/stdlib/spec/functions/ensure_resource_spec.rb @@ -0,0 +1,64 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +require 'rspec-puppet' +describe 'ensure_resource' do + describe 'when a type or title is not specified' do + it { should run.with_params().and_raise_error(ArgumentError) } + it { should run.with_params(['type']).and_raise_error(ArgumentError) } + end + + describe 'when compared against a resource with no attributes' do + let :pre_condition do + 'user { "dan": }' + end + it "should contain the the ensured resources" do + subject.should run.with_params('user', 'dan', {}) + compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' + end + end + + describe 'when compared against a resource with attributes' do + let :pre_condition do + 'user { "dan": ensure => present, shell => "/bin/csh", managehome => false}' + end + # these first three should not fail + it { should run.with_params('User', 'dan', {}) } + it { should run.with_params('User', 'dan', '') } + it { should run.with_params('User', 'dan', {'ensure' => 'present'}) } + it { should run.with_params('User', 'dan', {'ensure' => 'present', 'managehome' => false}) } + # test that this fails + it { should run.with_params('User', 'dan', {'ensure' => 'absent', 'managehome' => false}).and_raise_error(Puppet::Error) } + end + + describe 'when an array of new resources are passed in' do + it "should contain the ensured resources" do + subject.should run.with_params('User', ['dan', 'alex'], {}) + compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' + compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]' + end + end + + describe 'when an array of existing resources is compared against existing resources' do + let :pre_condition do + 'user { "dan": ensure => present; "alex": ensure => present }' + end + it "should return the existing resources" do + subject.should run.with_params('User', ['dan', 'alex'], {}) + compiler.catalog.resource('User[dan]').to_s.should == 'User[dan]' + compiler.catalog.resource('User[alex]').to_s.should == 'User[alex]' + end + end + + describe 'when compared against existing resources with attributes' do + let :pre_condition do + 'user { "dan": ensure => present; "alex": ensure => present }' + end + # These should not fail + it { should run.with_params('User', ['dan', 'alex'], {}) } + it { should run.with_params('User', ['dan', 'alex'], '') } + it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'present'}) } + # This should fail + it { should run.with_params('User', ['dan', 'alex'], {'ensure' => 'absent'}).and_raise_error(Puppet::Error) } + end +end diff --git a/deployment/modules/stdlib/spec/functions/getparam_spec.rb b/deployment/modules/stdlib/spec/functions/getparam_spec.rb new file mode 100644 index 000000000..d9c50a6c2 --- /dev/null +++ b/deployment/modules/stdlib/spec/functions/getparam_spec.rb @@ -0,0 +1,34 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +require 'rspec-puppet' +describe 'getparam' do + describe 'when a resource is not specified' do + it do + should run.with_params().and_raise_error(ArgumentError) + should run.with_params('User[dan]').and_raise_error(ArgumentError) + should run.with_params('User[dan]', {}).and_raise_error(ArgumentError) + should run.with_params('User[dan]', '').and_return('') + end + end + describe 'when compared against a resource with no params' do + let :pre_condition do + 'user { "dan": }' + end + it do + should run.with_params('User[dan]', 'shell').and_return('') + end + end + + describe 'when compared against a resource with params' do + let :pre_condition do + 'user { "dan": ensure => present, shell => "/bin/sh", managehome => false}' + end + it do + should run.with_params('User[dan]', 'shell').and_return('/bin/sh') + should run.with_params('User[dan]', '').and_return('') + should run.with_params('User[dan]', 'ensure').and_return('present') + should run.with_params('User[dan]', 'managehome').and_return(false) + end + end +end diff --git a/deployment/modules/stdlib/spec/monkey_patches/alias_should_to_must.rb b/deployment/modules/stdlib/spec/monkey_patches/alias_should_to_must.rb new file mode 100755 index 000000000..1a1111799 --- /dev/null +++ b/deployment/modules/stdlib/spec/monkey_patches/alias_should_to_must.rb @@ -0,0 +1,8 @@ +require 'rspec' + +class Object + # This is necessary because the RAL has a 'should' + # method. + alias :must :should + alias :must_not :should_not +end diff --git a/deployment/modules/stdlib/spec/monkey_patches/publicize_methods.rb b/deployment/modules/stdlib/spec/monkey_patches/publicize_methods.rb new file mode 100755 index 000000000..f3a1abf40 --- /dev/null +++ b/deployment/modules/stdlib/spec/monkey_patches/publicize_methods.rb @@ -0,0 +1,10 @@ +# Some monkey-patching to allow us to test private methods. +class Class + def publicize_methods(*methods) + saved_private_instance_methods = methods.empty? ? self.private_instance_methods : methods + + self.class_eval { public(*saved_private_instance_methods) } + yield + self.class_eval { private(*saved_private_instance_methods) } + end +end diff --git a/deployment/modules/stdlib/spec/spec.opts b/deployment/modules/stdlib/spec/spec.opts new file mode 100644 index 000000000..91cd6427e --- /dev/null +++ b/deployment/modules/stdlib/spec/spec.opts @@ -0,0 +1,6 @@ +--format +s +--colour +--loadby +mtime +--backtrace diff --git a/deployment/modules/stdlib/spec/spec_helper.rb b/deployment/modules/stdlib/spec/spec_helper.rb new file mode 100644 index 000000000..931d35c84 --- /dev/null +++ b/deployment/modules/stdlib/spec/spec_helper.rb @@ -0,0 +1,28 @@ +dir = File.expand_path(File.dirname(__FILE__)) +$LOAD_PATH.unshift File.join(dir, 'lib') + +# Don't want puppet getting the command line arguments for rake or autotest +ARGV.clear + +require 'puppet' +require 'facter' +require 'mocha' +gem 'rspec', '>=2.0.0' +require 'rspec/expectations' + +require 'puppetlabs_spec_helper/module_spec_helper' + +RSpec.configure do |config| + # FIXME REVISIT - We may want to delegate to Facter like we do in + # Puppet::PuppetSpecInitializer.initialize_via_testhelper(config) because + # this behavior is a duplication of the spec_helper in Facter. + config.before :each do + # Ensure that we don't accidentally cache facts and environment between + # test cases. This requires each example group to explicitly load the + # facts being exercised with something like + # Facter.collection.loader.load(:ipaddress) + Facter::Util::Loader.any_instance.stubs(:load_all) + Facter.clear + Facter.clear_messages + end +end diff --git a/deployment/modules/stdlib/spec/unit/facter/pe_required_facts_spec.rb b/deployment/modules/stdlib/spec/unit/facter/pe_required_facts_spec.rb new file mode 100644 index 000000000..f219b371f --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/facter/pe_required_facts_spec.rb @@ -0,0 +1,69 @@ +# Puppet Enterprise requires the following facts to be set in order to operate. +# These facts are set using the file ???? and the two facts are +# `fact_stomp_port`, and `fact_stomp_server`. +# + +require 'spec_helper' + +describe "External facts in /etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt" do + context "With Facter 1.6.17 which does not have external facts support" do + before :each do + Facter.stubs(:version).returns("1.6.17") + # Stub out the filesystem for stdlib + Dir.stubs(:entries).with("/etc/puppetlabs/facter/facts.d"). + returns(['puppet_enterprise_installer.txt']) + Dir.stubs(:entries).with("/etc/facter/facts.d").returns([]) + File.stubs(:readlines).with('/etc/puppetlabs/facter/facts.d/puppet_enterprise_installer.txt'). + returns([ + "fact_stomp_port=61613\n", + "fact_stomp_server=puppetmaster.acme.com\n", + "fact_is_puppetagent=true\n", + "fact_is_puppetmaster=false\n", + "fact_is_puppetca=false\n", + "fact_is_puppetconsole=false\n", + ]) + if Facter.collection.respond_to? :load + Facter.collection.load(:facter_dot_d) + else + Facter.collection.loader.load(:facter_dot_d) + end + end + + it 'defines fact_stomp_port' do + Facter.fact(:fact_stomp_port).value.should == '61613' + end + it 'defines fact_stomp_server' do + Facter.fact(:fact_stomp_server).value.should == 'puppetmaster.acme.com' + end + it 'defines fact_is_puppetagent' do + Facter.fact(:fact_is_puppetagent).value.should == 'true' + end + it 'defines fact_is_puppetmaster' do + Facter.fact(:fact_is_puppetmaster).value.should == 'false' + end + it 'defines fact_is_puppetca' do + Facter.fact(:fact_is_puppetca).value.should == 'false' + end + it 'defines fact_is_puppetconsole' do + Facter.fact(:fact_is_puppetconsole).value.should == 'false' + end + end + + [ '1.7.1', '2.0.1' ].each do |v| + context "With Facter #{v} which has external facts support" do + before :each do + Facter.stubs(:version).returns(v) + end + + it 'does not call Facter::Util::DotD.new' do + Facter::Util::DotD.expects(:new).never + + if Facter.collection.respond_to? :load + Facter.collection.load(:facter_dot_d) + else + Facter.collection.loader.load(:facter_dot_d) + end + end + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/facter/pe_version_spec.rb b/deployment/modules/stdlib/spec/unit/facter/pe_version_spec.rb new file mode 100644 index 000000000..931c6d4b0 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/facter/pe_version_spec.rb @@ -0,0 +1,76 @@ +#!/usr/bin/env rspec + +require 'spec_helper' + +describe "PE Version specs" do + before :each do + # Explicitly load the pe_version.rb file which contains generated facts + # that cannot be automatically loaded. Puppet 2.x implements + # Facter.collection.load while Facter 1.x markes Facter.collection.load as + # a private method. + if Facter.collection.respond_to? :load + Facter.collection.load(:pe_version) + else + Facter.collection.loader.load(:pe_version) + end + end + + context "If PE is installed" do + %w{ 2.6.1 2.10.300 }.each do |version| + puppetversion = "2.7.19 (Puppet Enterprise #{version})" + context "puppetversion => #{puppetversion}" do + before :each do + Facter.fact(:puppetversion).stubs(:value).returns(puppetversion) + end + + (major,minor,patch) = version.split(".") + + it "Should return true" do + Facter.fact(:is_pe).value.should == true + end + + it "Should have a version of #{version}" do + Facter.fact(:pe_version).value.should == version + end + + it "Should have a major version of #{major}" do + Facter.fact(:pe_major_version).value.should == major + end + + it "Should have a minor version of #{minor}" do + Facter.fact(:pe_minor_version).value.should == minor + end + + it "Should have a patch version of #{patch}" do + Facter.fact(:pe_patch_version).value.should == patch + end + end + end + end + + context "When PE is not installed" do + before :each do + Facter.fact(:puppetversion).stubs(:value).returns("2.7.19") + end + + it "is_pe is false" do + Facter.fact(:is_pe).value.should == false + end + + it "pe_version is nil" do + Facter.fact(:pe_version).value.should be_nil + end + + it "pe_major_version is nil" do + Facter.fact(:pe_major_version).value.should be_nil + end + + it "pe_minor_version is nil" do + Facter.fact(:pe_minor_version).value.should be_nil + end + + it "Should have a patch version" do + Facter.fact(:pe_patch_version).value.should be_nil + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/facter/root_home_spec.rb b/deployment/modules/stdlib/spec/unit/facter/root_home_spec.rb new file mode 100644 index 000000000..ce80684ca --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/facter/root_home_spec.rb @@ -0,0 +1,40 @@ +require 'spec_helper' +require 'facter/root_home' + +describe Facter::Util::RootHome do + context "solaris" do + let(:root_ent) { "root:x:0:0:Super-User:/:/sbin/sh" } + let(:expected_root_home) { "/" } + + it "should return /" do + Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent) + Facter::Util::RootHome.get_root_home.should == expected_root_home + end + end + context "linux" do + let(:root_ent) { "root:x:0:0:root:/root:/bin/bash" } + let(:expected_root_home) { "/root" } + + it "should return /root" do + Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent) + Facter::Util::RootHome.get_root_home.should == expected_root_home + end + end + context "macosx" do + let(:root_ent) { "root:*:0:0:System Administrator:/var/root:/bin/sh" } + let(:expected_root_home) { "/var/root" } + + it "should return /var/root" do + Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(root_ent) + Facter::Util::RootHome.get_root_home.should == expected_root_home + end + end + context "windows" do + before :each do + Facter::Util::Resolution.expects(:exec).with("getent passwd root").returns(nil) + end + it "should be nil on windows" do + Facter::Util::RootHome.get_root_home.should be_nil + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb b/deployment/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb new file mode 100644 index 000000000..c3ce6ea07 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/facter/util/puppet_settings_spec.rb @@ -0,0 +1,35 @@ +require 'spec_helper' +require 'facter/util/puppet_settings' + +describe Facter::Util::PuppetSettings do + + describe "#with_puppet" do + context "Without Puppet loaded" do + before(:each) do + Module.expects(:const_get).with("Puppet").raises(NameError) + end + + it 'should be nil' do + subject.with_puppet { Puppet[:vardir] }.should be_nil + end + it 'should not yield to the block' do + Puppet.expects(:[]).never + subject.with_puppet { Puppet[:vardir] }.should be_nil + end + end + context "With Puppet loaded" do + module Puppet; end + let(:vardir) { "/var/lib/puppet" } + + before :each do + Puppet.expects(:[]).with(:vardir).returns vardir + end + it 'should yield to the block' do + subject.with_puppet { Puppet[:vardir] } + end + it 'should return the nodes vardir' do + subject.with_puppet { Puppet[:vardir] }.should eq vardir + end + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb new file mode 100755 index 000000000..c0b42970c --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/abs_spec.rb @@ -0,0 +1,25 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the abs function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("abs").should == "function_abs" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_abs([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert a negative number into a positive" do + result = scope.function_abs(["-34"]) + result.should(eq(34)) + end + + it "should do nothing with a positive number" do + result = scope.function_abs(["5678"]) + result.should(eq(5678)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb new file mode 100644 index 000000000..b266e84f4 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/any2array_spec.rb @@ -0,0 +1,55 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the any2array function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("any2array").should == "function_any2array" + end + + it "should return an empty array if there is less than 1 argument" do + result = scope.function_any2array([]) + result.should(eq([])) + end + + it "should convert boolean true to [ true ] " do + result = scope.function_any2array([true]) + result.should(eq([true])) + end + + it "should convert one object to [object]" do + result = scope.function_any2array(['one']) + result.should(eq(['one'])) + end + + it "should convert multiple objects to [objects]" do + result = scope.function_any2array(['one', 'two']) + result.should(eq(['one', 'two'])) + end + + it "should return empty array it was called with" do + result = scope.function_any2array([[]]) + result.should(eq([])) + end + + it "should return one-member array it was called with" do + result = scope.function_any2array([['string']]) + result.should(eq(['string'])) + end + + it "should return multi-member array it was called with" do + result = scope.function_any2array([['one', 'two']]) + result.should(eq(['one', 'two'])) + end + + it "should return members of a hash it was called with" do + result = scope.function_any2array([{ 'key' => 'value' }]) + result.should(eq(['key', 'value'])) + end + + it "should return an empty array if it was called with an empty hash" do + result = scope.function_any2array([{ }]) + result.should(eq([])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb new file mode 100755 index 000000000..518ac85ec --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/bool2num_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the bool2num function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("bool2num").should == "function_bool2num" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_bool2num([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert true to 1" do + result = scope.function_bool2num([true]) + result.should(eq(1)) + end + + it "should convert false to 0" do + result = scope.function_bool2num([false]) + result.should(eq(0)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb new file mode 100755 index 000000000..69c9758f2 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/capitalize_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the capitalize function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("capitalize").should == "function_capitalize" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_capitalize([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should capitalize the beginning of a string" do + result = scope.function_capitalize(["abc"]) + result.should(eq("Abc")) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb new file mode 100755 index 000000000..e425365fc --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/chomp_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the chomp function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("chomp").should == "function_chomp" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_chomp([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should chomp the end of a string" do + result = scope.function_chomp(["abc\n"]) + result.should(eq("abc")) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb new file mode 100755 index 000000000..9e466de4b --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/chop_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the chop function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("chop").should == "function_chop" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_chop([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should chop the end of a string" do + result = scope.function_chop(["asdf\n"]) + result.should(eq("asdf")) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb new file mode 100644 index 000000000..123188bd4 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/concat_spec.rb @@ -0,0 +1,15 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the concat function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_concat([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should be able to concat an array" do + result = scope.function_concat([['1','2','3'],['4','5','6']]) + result.should(eq(['1','2','3','4','5','6'])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/count_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/count_spec.rb new file mode 100644 index 000000000..2453815c2 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/count_spec.rb @@ -0,0 +1,31 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the count function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("count").should == "function_count" + end + + it "should raise a ArgumentError if there is more than 2 arguments" do + lambda { scope.function_count(['foo', 'bar', 'baz']) }.should( raise_error(ArgumentError)) + end + + it "should be able to count arrays" do + scope.function_count([["1","2","3"]]).should(eq(3)) + end + + it "should be able to count matching elements in arrays" do + scope.function_count([["1", "2", "2"], "2"]).should(eq(2)) + end + + it "should not count nil or empty strings" do + scope.function_count([["foo","bar",nil,""]]).should(eq(2)) + end + + it 'does not count an undefined hash key or an out of bound array index (which are both :undef)' do + expect(scope.function_count([["foo",:undef,:undef]])).to eq(1) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb new file mode 100755 index 000000000..d8d961848 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/delete_at_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the delete_at function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("delete_at").should == "function_delete_at" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_delete_at([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should delete an item at specified location from an array" do + result = scope.function_delete_at([['a','b','c'],1]) + result.should(eq(['a','c'])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb new file mode 100755 index 000000000..2f29c93c0 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/delete_spec.rb @@ -0,0 +1,38 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the delete function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("delete").should == "function_delete" + end + + it "should raise a ParseError if there are fewer than 2 arguments" do + lambda { scope.function_delete([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if there are greater than 2 arguments" do + lambda { scope.function_delete([[], 'foo', 'bar']) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a TypeError if a number is passed as the first argument" do + lambda { scope.function_delete([1, 'bar']) }.should( raise_error(TypeError)) + end + + it "should delete all instances of an element from an array" do + result = scope.function_delete([['a','b','c','b'],'b']) + result.should(eq(['a','c'])) + end + + it "should delete all instances of a substring from a string" do + result = scope.function_delete(['foobarbabarz','bar']) + result.should(eq('foobaz')) + end + + it "should delete a key from a hash" do + result = scope.function_delete([{ 'a' => 1, 'b' => 2, 'c' => 3 },'b']) + result.should(eq({ 'a' => 1, 'c' => 3 })) + end + +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb new file mode 100755 index 000000000..fb3b4feca --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/dirname_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the dirname function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("dirname").should == "function_dirname" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_dirname([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return dirname for an absolute path" do + result = scope.function_dirname(['/path/to/a/file.ext']) + result.should(eq('/path/to/a')) + end + + it "should return dirname for a relative path" do + result = scope.function_dirname(['path/to/a/file.ext']) + result.should(eq('path/to/a')) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb new file mode 100755 index 000000000..acef1f05d --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/downcase_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the downcase function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("downcase").should == "function_downcase" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_downcase([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should downcase a string" do + result = scope.function_downcase(["ASFD"]) + result.should(eq("asfd")) + end + + it "should do nothing to a string that is already downcase" do + result = scope.function_downcase(["asdf asdf"]) + result.should(eq("asdf asdf")) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb new file mode 100755 index 000000000..774587522 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/empty_spec.rb @@ -0,0 +1,23 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the empty function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + it "should exist" do + Puppet::Parser::Functions.function("empty").should == "function_empty" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_empty([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return a true for an empty string" do + result = scope.function_empty(['']) + result.should(eq(true)) + end + + it "should return a false for a non-empty string" do + result = scope.function_empty(['asdf']) + result.should(eq(false)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb new file mode 100755 index 000000000..dba7a6bbd --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/flatten_spec.rb @@ -0,0 +1,27 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the flatten function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + it "should exist" do + Puppet::Parser::Functions.function("flatten").should == "function_flatten" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_flatten([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if there is more than 1 argument" do + lambda { scope.function_flatten([[], []]) }.should( raise_error(Puppet::ParseError)) + end + + it "should flatten a complex data structure" do + result = scope.function_flatten([["a","b",["c",["d","e"],"f","g"]]]) + result.should(eq(["a","b","c","d","e","f","g"])) + end + + it "should do nothing to a structure that is already flat" do + result = scope.function_flatten([["a","b","c","d"]]) + result.should(eq(["a","b","c","d"])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb new file mode 100644 index 000000000..dbc8c7735 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/floor_spec.rb @@ -0,0 +1,39 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the floor function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("floor").should == "function_floor" + end + + it "should raise a ParseError if there is less than 1 argument" do + lambda { scope.function_floor([]) }.should( raise_error(Puppet::ParseError, /Wrong number of arguments/)) + end + + it "should should raise a ParseError if input isn't numeric (eg. String)" do + lambda { scope.function_floor(["foo"]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/)) + end + + it "should should raise a ParseError if input isn't numeric (eg. Boolean)" do + lambda { scope.function_floor([true]) }.should( raise_error(Puppet::ParseError, /Wrong argument type/)) + end + + it "should return an integer when a numeric type is passed" do + result = scope.function_floor([12.4]) + result.is_a?(Integer).should(eq(true)) + end + + it "should return the input when an integer is passed" do + result = scope.function_floor([7]) + result.should(eq(7)) + end + + it "should return the largest integer less than or equal to the input" do + result = scope.function_floor([3.8]) + result.should(eq(3)) + end +end + diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb new file mode 100644 index 000000000..257772335 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/fqdn_rotate_spec.rb @@ -0,0 +1,33 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the fqdn_rotate function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("fqdn_rotate").should == "function_fqdn_rotate" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_fqdn_rotate([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should rotate a string and the result should be the same size" do + scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") + result = scope.function_fqdn_rotate(["asdf"]) + result.size.should(eq(4)) + end + + it "should rotate a string to give the same results for one host" do + scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1").twice + scope.function_fqdn_rotate(["abcdefg"]).should eql(scope.function_fqdn_rotate(["abcdefg"])) + end + + it "should rotate a string to give different values on different hosts" do + scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.1") + val1 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"]) + scope.expects(:lookupvar).with("::fqdn").returns("127.0.0.2") + val2 = scope.function_fqdn_rotate(["abcdefghijklmnopqrstuvwxyz01234567890987654321"]) + val1.should_not eql(val2) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb new file mode 100644 index 000000000..486bef6f2 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/get_module_path_spec.rb @@ -0,0 +1,46 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:get_module_path) do + Internals = PuppetlabsSpec::PuppetInternals + class StubModule + attr_reader :path + def initialize(path) + @path = path + end + end + + def scope(environment = "production") + Internals.scope(:compiler => Internals.compiler(:node => Internals.node(:environment => environment))) + end + + it 'should only allow one argument' do + expect { scope.function_get_module_path([]) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) + expect { scope.function_get_module_path(['1','2','3']) }.to raise_error(Puppet::ParseError, /Wrong number of arguments, expects one/) + end + it 'should raise an exception when the module cannot be found' do + expect { scope.function_get_module_path(['foo']) }.to raise_error(Puppet::ParseError, /Could not find module/) + end + describe 'when locating a module' do + let(:modulepath) { "/tmp/does_not_exist" } + let(:path_of_module_foo) { StubModule.new("/tmp/does_not_exist/foo") } + + before(:each) { Puppet[:modulepath] = modulepath } + + it 'should be able to find module paths from the modulepath setting' do + Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo) + scope.function_get_module_path(['foo']).should == path_of_module_foo.path + end + it 'should be able to find module paths when the modulepath is a list' do + Puppet[:modulepath] = modulepath + ":/tmp" + Puppet::Module.expects(:find).with('foo', 'production').returns(path_of_module_foo) + scope.function_get_module_path(['foo']).should == path_of_module_foo.path + end + it 'should respect the environment' do + pending("Disabled on Puppet 2.6.x") if Puppet.version =~ /^2\.6\b/ + Puppet.settings[:environment] = 'danstestenv' + Puppet::Module.expects(:find).with('foo', 'danstestenv').returns(path_of_module_foo) + scope('danstestenv').function_get_module_path(['foo']).should == path_of_module_foo.path + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb new file mode 100644 index 000000000..5ff834ee7 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/getvar_spec.rb @@ -0,0 +1,37 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:getvar) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + describe 'when calling getvar from puppet' do + + it "should not compile when no arguments are passed" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = '$foo = getvar()' + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + + it "should not compile when too many arguments are passed" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = '$foo = getvar("foo::bar", "baz")' + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + + it "should lookup variables in other namespaces" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = <<-'ENDofPUPPETcode' + class site::data { $foo = 'baz' } + include site::data + $foo = getvar("site::data::foo") + if $foo != 'baz' { + fail('getvar did not return what we expect') + } + ENDofPUPPETcode + scope.compiler.compile + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb new file mode 100755 index 000000000..a93b84253 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/grep_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the grep function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("grep").should == "function_grep" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_grep([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should grep contents from an array" do + result = scope.function_grep([["aaabbb","bbbccc","dddeee"], "bbb"]) + result.should(eq(["aaabbb","bbbccc"])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb new file mode 100755 index 000000000..c5264e4f3 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_interface_with_spec.rb @@ -0,0 +1,64 @@ +#!/usr/bin/env ruby -S rspec +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:has_interface_with) do + + let(:scope) do + PuppetlabsSpec::PuppetInternals.scope + end + + # The subject of these examples is the method itself. + subject do + function_name = Puppet::Parser::Functions.function(:has_interface_with) + scope.method(function_name) + end + + # We need to mock out the Facts so we can specify how we expect this function + # to behave on different platforms. + context "On Mac OS X Systems" do + before :each do + scope.stubs(:lookupvar).with("interfaces").returns('lo0,gif0,stf0,en1,p2p0,fw0,en0,vmnet1,vmnet8,utun0') + end + it 'should have loopback (lo0)' do + subject.call(['lo0']).should be_true + end + it 'should not have loopback (lo)' do + subject.call(['lo']).should be_false + end + end + context "On Linux Systems" do + before :each do + scope.stubs(:lookupvar).with("interfaces").returns('eth0,lo') + scope.stubs(:lookupvar).with("ipaddress").returns('10.0.0.1') + scope.stubs(:lookupvar).with("ipaddress_lo").returns('127.0.0.1') + scope.stubs(:lookupvar).with("ipaddress_eth0").returns('10.0.0.1') + scope.stubs(:lookupvar).with('muppet').returns('kermit') + scope.stubs(:lookupvar).with('muppet_lo').returns('mspiggy') + scope.stubs(:lookupvar).with('muppet_eth0').returns('kermit') + end + it 'should have loopback (lo)' do + subject.call(['lo']).should be_true + end + it 'should not have loopback (lo0)' do + subject.call(['lo0']).should be_false + end + it 'should have ipaddress with 127.0.0.1' do + subject.call(['ipaddress', '127.0.0.1']).should be_true + end + it 'should have ipaddress with 10.0.0.1' do + subject.call(['ipaddress', '10.0.0.1']).should be_true + end + it 'should not have ipaddress with 10.0.0.2' do + subject.call(['ipaddress', '10.0.0.2']).should be_false + end + it 'should have muppet named kermit' do + subject.call(['muppet', 'kermit']).should be_true + end + it 'should have muppet named mspiggy' do + subject.call(['muppet', 'mspiggy']).should be_true + end + it 'should not have muppet named bigbird' do + subject.call(['muppet', 'bigbird']).should be_false + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb new file mode 100755 index 000000000..5a6846082 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_address_spec.rb @@ -0,0 +1,39 @@ +#!/usr/bin/env ruby -S rspec +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:has_ip_address) do + + let(:scope) do + PuppetlabsSpec::PuppetInternals.scope + end + + subject do + function_name = Puppet::Parser::Functions.function(:has_ip_address) + scope.method(function_name) + end + + context "On Linux Systems" do + before :each do + scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo') + scope.stubs(:lookupvar).with('ipaddress').returns('10.0.2.15') + scope.stubs(:lookupvar).with('ipaddress_eth0').returns('10.0.2.15') + scope.stubs(:lookupvar).with('ipaddress_lo').returns('127.0.0.1') + end + + it 'should have primary address (10.0.2.15)' do + subject.call(['10.0.2.15']).should be_true + end + + it 'should have lookupback address (127.0.0.1)' do + subject.call(['127.0.0.1']).should be_true + end + + it 'should not have other address' do + subject.call(['192.1681.1.1']).should be_false + end + + it 'should not have "mspiggy" on an interface' do + subject.call(['mspiggy']).should be_false + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb new file mode 100755 index 000000000..c3a289e37 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_ip_network_spec.rb @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby -S rspec +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:has_ip_network) do + + let(:scope) do + PuppetlabsSpec::PuppetInternals.scope + end + + subject do + function_name = Puppet::Parser::Functions.function(:has_ip_network) + scope.method(function_name) + end + + context "On Linux Systems" do + before :each do + scope.stubs(:lookupvar).with('interfaces').returns('eth0,lo') + scope.stubs(:lookupvar).with('network').returns(:undefined) + scope.stubs(:lookupvar).with('network_eth0').returns('10.0.2.0') + scope.stubs(:lookupvar).with('network_lo').returns('127.0.0.1') + end + + it 'should have primary network (10.0.2.0)' do + subject.call(['10.0.2.0']).should be_true + end + + it 'should have loopback network (127.0.0.0)' do + subject.call(['127.0.0.1']).should be_true + end + + it 'should not have other network' do + subject.call(['192.168.1.0']).should be_false + end + end +end + diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb new file mode 100644 index 000000000..490daeae7 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/has_key_spec.rb @@ -0,0 +1,42 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:has_key) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + describe 'when calling has_key from puppet' do + it "should not compile when no arguments are passed" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = '$x = has_key()' + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + + it "should not compile when 1 argument is passed" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = "$x = has_key('foo')" + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + + it "should require the first value to be a Hash" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = "$x = has_key('foo', 'bar')" + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /expects the first argument to be a hash/) + end + end + + describe 'when calling the function has_key from a scope instance' do + it 'should detect existing keys' do + scope.function_has_key([{'one' => 1}, 'one']).should be_true + end + + it 'should detect existing keys' do + scope.function_has_key([{'one' => 1}, 'two']).should be_false + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb new file mode 100644 index 000000000..7c91be907 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/hash_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the hash function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("hash").should == "function_hash" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_hash([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert an array to a hash" do + result = scope.function_hash([['a',1,'b',2,'c',3]]) + result.should(eq({'a'=>1,'b'=>2,'c'=>3})) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb new file mode 100644 index 000000000..e7f4bcd6d --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_array_spec.rb @@ -0,0 +1,29 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the is_array function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("is_array").should == "function_is_array" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_is_array([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if passed an array" do + result = scope.function_is_array([[1,2,3]]) + result.should(eq(true)) + end + + it "should return false if passed a hash" do + result = scope.function_is_array([{'a'=>1}]) + result.should(eq(false)) + end + + it "should return false if passed a string" do + result = scope.function_is_array(["asdf"]) + result.should(eq(false)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb new file mode 100644 index 000000000..f2ea76dac --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_domain_name_spec.rb @@ -0,0 +1,64 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the is_domain_name function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("is_domain_name").should == "function_is_domain_name" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_is_domain_name([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a valid short domain name" do + result = scope.function_is_domain_name(["x.com"]) + result.should(be_true) + end + + it "should return true if the domain is ." do + result = scope.function_is_domain_name(["."]) + result.should(be_true) + end + + it "should return true if the domain is x.com." do + result = scope.function_is_domain_name(["x.com."]) + result.should(be_true) + end + + it "should return true if a valid domain name" do + result = scope.function_is_domain_name(["foo.bar.com"]) + result.should(be_true) + end + + it "should allow domain parts to start with numbers" do + result = scope.function_is_domain_name(["3foo.2bar.com"]) + result.should(be_true) + end + + it "should allow domain to end with a dot" do + result = scope.function_is_domain_name(["3foo.2bar.com."]) + result.should(be_true) + end + + it "should allow a single part domain" do + result = scope.function_is_domain_name(["orange"]) + result.should(be_true) + end + + it "should return false if domain parts start with hyphens" do + result = scope.function_is_domain_name(["-3foo.2bar.com"]) + result.should(be_false) + end + + it "should return true if domain contains hyphens" do + result = scope.function_is_domain_name(["3foo-bar.2bar-fuzz.com"]) + result.should(be_true) + end + + it "should return false if domain name contains spaces" do + result = scope.function_is_domain_name(["not valid"]) + result.should(be_false) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb new file mode 100644 index 000000000..b7d73b04a --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_float_spec.rb @@ -0,0 +1,33 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the is_float function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("is_float").should == "function_is_float" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_is_float([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a float" do + result = scope.function_is_float(["0.12"]) + result.should(eq(true)) + end + + it "should return false if a string" do + result = scope.function_is_float(["asdf"]) + result.should(eq(false)) + end + + it "should return false if an integer" do + result = scope.function_is_float(["3"]) + result.should(eq(false)) + end + it "should return true if a float is created from an arithmetical operation" do + result = scope.function_is_float([3.2*2]) + result.should(eq(true)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb new file mode 100644 index 000000000..bd40c5194 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_function_available.rb @@ -0,0 +1,31 @@ +#!/usr/bin/env rspec +require 'spec_helper' + +describe "the is_function_available function" do + before :all do + Puppet::Parser::Functions.autoloader.loadall + end + + before :each do + @scope = Puppet::Parser::Scope.new + end + + it "should exist" do + Puppet::Parser::Functions.function("is_function_available").should == "function_is_function_available" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { @scope.function_is_function_available([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return false if a nonexistent function is passed" do + result = @scope.function_is_function_available(['jeff_mccunes_left_sock']) + result.should(eq(false)) + end + + it "should return true if an available function is passed" do + result = @scope.function_is_function_available(['require']) + result.should(eq(true)) + end + +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb new file mode 100644 index 000000000..bbebf39f9 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_hash_spec.rb @@ -0,0 +1,29 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the is_hash function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("is_hash").should == "function_is_hash" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_is_hash([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if passed a hash" do + result = scope.function_is_hash([{"a"=>1,"b"=>2}]) + result.should(eq(true)) + end + + it "should return false if passed an array" do + result = scope.function_is_hash([["a","b"]]) + result.should(eq(false)) + end + + it "should return false if passed a string" do + result = scope.function_is_hash(["asdf"]) + result.should(eq(false)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb new file mode 100644 index 000000000..433579502 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_integer_spec.rb @@ -0,0 +1,34 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the is_integer function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("is_integer").should == "function_is_integer" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_is_integer([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if an integer" do + result = scope.function_is_integer(["3"]) + result.should(eq(true)) + end + + it "should return false if a float" do + result = scope.function_is_integer(["3.2"]) + result.should(eq(false)) + end + + it "should return false if a string" do + result = scope.function_is_integer(["asdf"]) + result.should(eq(false)) + end + + it "should return true if an integer is created from an arithmetical operation" do + result = scope.function_is_integer([3*2]) + result.should(eq(true)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb new file mode 100644 index 000000000..c0debb3d4 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_ip_address_spec.rb @@ -0,0 +1,39 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the is_ip_address function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("is_ip_address").should == "function_is_ip_address" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_is_ip_address([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if an IPv4 address" do + result = scope.function_is_ip_address(["1.2.3.4"]) + result.should(eq(true)) + end + + it "should return true if a full IPv6 address" do + result = scope.function_is_ip_address(["fe80:0000:cd12:d123:e2f8:47ff:fe09:dd74"]) + result.should(eq(true)) + end + + it "should return true if a compressed IPv6 address" do + result = scope.function_is_ip_address(["fe00::1"]) + result.should(eq(true)) + end + + it "should return false if not valid" do + result = scope.function_is_ip_address(["asdf"]) + result.should(eq(false)) + end + + it "should return false if IP octets out of range" do + result = scope.function_is_ip_address(["1.1.1.300"]) + result.should(eq(false)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb new file mode 100644 index 000000000..ca9c59047 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_mac_address_spec.rb @@ -0,0 +1,29 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the is_mac_address function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("is_mac_address").should == "function_is_mac_address" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_is_mac_address([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a valid mac address" do + result = scope.function_is_mac_address(["00:a0:1f:12:7f:a0"]) + result.should(eq(true)) + end + + it "should return false if octets are out of range" do + result = scope.function_is_mac_address(["00:a0:1f:12:7f:g0"]) + result.should(eq(false)) + end + + it "should return false if not valid" do + result = scope.function_is_mac_address(["not valid"]) + result.should(eq(false)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb new file mode 100644 index 000000000..d7440fb0a --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_numeric_spec.rb @@ -0,0 +1,39 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the is_numeric function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("is_numeric").should == "function_is_numeric" + end + + it "should raise a ParseError if there is less than 1 argument" do + lambda { scope.function_is_numeric([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if an integer" do + result = scope.function_is_numeric(["3"]) + result.should(eq(true)) + end + + it "should return true if a float" do + result = scope.function_is_numeric(["3.2"]) + result.should(eq(true)) + end + + it "should return true if an integer is created from an arithmetical operation" do + result = scope.function_is_numeric([3*2]) + result.should(eq(true)) + end + + it "should return true if a float is created from an arithmetical operation" do + result = scope.function_is_numeric([3.2*2]) + result.should(eq(true)) + end + + it "should return false if a string" do + result = scope.function_is_numeric(["asdf"]) + result.should(eq(false)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb new file mode 100644 index 000000000..3756bea8b --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/is_string_spec.rb @@ -0,0 +1,34 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the is_string function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("is_string").should == "function_is_string" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_is_string([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a string" do + result = scope.function_is_string(["asdf"]) + result.should(eq(true)) + end + + it "should return false if an integer" do + result = scope.function_is_string(["3"]) + result.should(eq(false)) + end + + it "should return false if a float" do + result = scope.function_is_string(["3.23"]) + result.should(eq(false)) + end + + it "should return false if an array" do + result = scope.function_is_string([["a","b","c"]]) + result.should(eq(false)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb new file mode 100644 index 000000000..a52fb719f --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/join_keys_to_values_spec.rb @@ -0,0 +1,40 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the join_keys_to_values function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("join_keys_to_values").should == "function_join_keys_to_values" + end + + it "should raise a ParseError if there are fewer than two arguments" do + lambda { scope.function_join_keys_to_values([{}]) }.should raise_error Puppet::ParseError + end + + it "should raise a ParseError if there are greater than two arguments" do + lambda { scope.function_join_keys_to_values([{}, 'foo', 'bar']) }.should raise_error Puppet::ParseError + end + + it "should raise a TypeError if the first argument is an array" do + lambda { scope.function_join_keys_to_values([[1,2], ',']) }.should raise_error TypeError + end + + it "should raise a TypeError if the second argument is an array" do + lambda { scope.function_join_keys_to_values([{}, [1,2]]) }.should raise_error TypeError + end + + it "should raise a TypeError if the second argument is a number" do + lambda { scope.function_join_keys_to_values([{}, 1]) }.should raise_error TypeError + end + + it "should return an empty array given an empty hash" do + result = scope.function_join_keys_to_values([{}, ":"]) + result.should == [] + end + + it "should join hash's keys to its values" do + result = scope.function_join_keys_to_values([{'a'=>1,2=>'foo',:b=>nil}, ":"]) + result.should =~ ['a:1','2:foo','b:'] + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb new file mode 100644 index 000000000..aafa1a7f7 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/join_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the join function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("join").should == "function_join" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_join([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should join an array into a string" do + result = scope.function_join([["a","b","c"], ":"]) + result.should(eq("a:b:c")) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb new file mode 100644 index 000000000..fdd7a7073 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/keys_spec.rb @@ -0,0 +1,21 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the keys function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("keys").should == "function_keys" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_keys([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return an array of keys when given a hash" do + result = scope.function_keys([{'a'=>1, 'b'=>2}]) + # =~ performs 'array with same elements' (set) matching + # For more info see RSpec::Matchers::MatchArray + result.should =~ ['a','b'] + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb new file mode 100644 index 000000000..b280ae7ac --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/lstrip_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the lstrip function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("lstrip").should == "function_lstrip" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_lstrip([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should lstrip a string" do + result = scope.function_lstrip([" asdf"]) + result.should(eq('asdf')) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb new file mode 100755 index 000000000..ff6f2b361 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/max_spec.rb @@ -0,0 +1,27 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the max function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("max").should == "function_max" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_max([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should be able to compare strings" do + scope.function_max(["albatross","dog","horse"]).should(eq("horse")) + end + + it "should be able to compare numbers" do + scope.function_max([6,8,4]).should(eq(8)) + end + + it "should be able to compare a number with a stringified number" do + scope.function_max([1,"2"]).should(eq("2")) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb new file mode 100644 index 000000000..6e9a023fa --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/member_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the member function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("member").should == "function_member" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_member([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if a member is in an array" do + result = scope.function_member([["a","b","c"], "a"]) + result.should(eq(true)) + end + + it "should return false if a member is not in an array" do + result = scope.function_member([["a","b","c"], "d"]) + result.should(eq(false)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb new file mode 100644 index 000000000..04169e7e7 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/merge_spec.rb @@ -0,0 +1,47 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:merge) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + describe 'when calling merge from puppet' do + it "should not compile when no arguments are passed" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = '$x = merge()' + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + + it "should not compile when 1 argument is passed" do + pending("Fails on 2.6.x, see bug #15912") if Puppet.version =~ /^2\.6\./ + Puppet[:code] = "$my_hash={'one' => 1}\n$x = merge($my_hash)" + expect { + scope.compiler.compile + }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + end + + describe 'when calling merge on the scope instance' do + it 'should require all parameters are hashes' do + expect { new_hash = scope.function_merge([{}, '2'])}.to raise_error(Puppet::ParseError, /unexpected argument type String/) + end + + it 'should be able to merge two hashes' do + new_hash = scope.function_merge([{'one' => '1', 'two' => '1'}, {'two' => '2', 'three' => '2'}]) + new_hash['one'].should == '1' + new_hash['two'].should == '2' + new_hash['three'].should == '2' + end + + it 'should merge multiple hashes' do + hash = scope.function_merge([{'one' => 1}, {'one' => '2'}, {'one' => '3'}]) + hash['one'].should == '3' + end + + it 'should accept empty hashes' do + scope.function_merge([{},{},{}]).should == {} + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb new file mode 100755 index 000000000..71d593ef0 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/min_spec.rb @@ -0,0 +1,27 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the min function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("min").should == "function_min" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_min([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should be able to compare strings" do + scope.function_min(["albatross","dog","horse"]).should(eq("albatross")) + end + + it "should be able to compare numbers" do + scope.function_min([6,8,4]).should(eq(4)) + end + + it "should be able to compare a number with a stringified number" do + scope.function_min([1,"2"]).should(eq(1)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb new file mode 100644 index 000000000..b56196d3c --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/num2bool_spec.rb @@ -0,0 +1,67 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the num2bool function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("num2bool").should == "function_num2bool" + end + + it "should raise a ParseError if there are no arguments" do + lambda { scope.function_num2bool([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if there are more than 1 arguments" do + lambda { scope.function_num2bool(["foo","bar"]) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if passed something non-numeric" do + lambda { scope.function_num2bool(["xyzzy"]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return true if passed string 1" do + result = scope.function_num2bool(["1"]) + result.should(be_true) + end + + it "should return true if passed string 1.5" do + result = scope.function_num2bool(["1.5"]) + result.should(be_true) + end + + it "should return true if passed number 1" do + result = scope.function_num2bool([1]) + result.should(be_true) + end + + it "should return false if passed string 0" do + result = scope.function_num2bool(["0"]) + result.should(be_false) + end + + it "should return false if passed number 0" do + result = scope.function_num2bool([0]) + result.should(be_false) + end + + it "should return false if passed string -1" do + result = scope.function_num2bool(["-1"]) + result.should(be_false) + end + + it "should return false if passed string -1.5" do + result = scope.function_num2bool(["-1.5"]) + result.should(be_false) + end + + it "should return false if passed number -1" do + result = scope.function_num2bool([-1]) + result.should(be_false) + end + + it "should return false if passed float -1.5" do + result = scope.function_num2bool([-1.5]) + result.should(be_false) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb new file mode 100644 index 000000000..f179ac111 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/parsejson_spec.rb @@ -0,0 +1,22 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the parsejson function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("parsejson").should == "function_parsejson" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_parsejson([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert JSON to a data structure" do + json = <<-EOS +["aaa","bbb","ccc"] +EOS + result = scope.function_parsejson([json]) + result.should(eq(['aaa','bbb','ccc'])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb new file mode 100644 index 000000000..0c7aea8a5 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/parseyaml_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the parseyaml function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("parseyaml").should == "function_parseyaml" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_parseyaml([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert YAML to a data structure" do + yaml = <<-EOS +- aaa +- bbb +- ccc +EOS + result = scope.function_parseyaml([yaml]) + result.should(eq(['aaa','bbb','ccc'])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb new file mode 100644 index 000000000..761db6be2 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/pick_spec.rb @@ -0,0 +1,34 @@ +#!/usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the pick function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("pick").should == "function_pick" + end + + it 'should return the correct value' do + scope.function_pick(['first', 'second']).should == 'first' + end + + it 'should return the correct value if the first value is empty' do + scope.function_pick(['', 'second']).should == 'second' + end + + it 'should remove empty string values' do + scope.function_pick(['', 'first']).should == 'first' + end + + it 'should remove :undef values' do + scope.function_pick([:undef, 'first']).should == 'first' + end + + it 'should remove :undefined values' do + scope.function_pick([:undefined, 'first']).should == 'first' + end + + it 'should error if no values are passed' do + expect { scope.function_pick([]) }.to raise_error(Puppet::Error, /Must provide non empty value./) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb new file mode 100644 index 000000000..5cf592bfb --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/prefix_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the prefix function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("prefix").should == "function_prefix" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_prefix([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return a prefixed array" do + result = scope.function_prefix([['a','b','c'], 'p']) + result.should(eq(['pa','pb','pc'])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb new file mode 100644 index 000000000..42751f460 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/range_spec.rb @@ -0,0 +1,34 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the range function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("range").should == "function_range" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_range([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return a letter range" do + result = scope.function_range(["a","d"]) + result.should(eq(['a','b','c','d'])) + end + + it "should return a number range" do + result = scope.function_range(["1","4"]) + result.should(eq([1,2,3,4])) + end + + it "should work with padded hostname like strings" do + expected = ("host01".."host10").to_a + scope.function_range(["host01","host10"]).should eq expected + end + + it "should coerce zero padded digits to integers" do + expected = (0..10).to_a + scope.function_range(["00", "10"]).should eq expected + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb new file mode 100755 index 000000000..f2cb74193 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/reject_spec.rb @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby + +require 'spec_helper' + +describe "the reject function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("reject").should == "function_reject" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_reject([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should reject contents from an array" do + result = scope.function_reject([["1111", "aaabbb","bbbccc","dddeee"], "bbb"]) + result.should(eq(["1111", "dddeee"])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb new file mode 100644 index 000000000..1b5920654 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/reverse_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the reverse function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("reverse").should == "function_reverse" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_reverse([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should reverse a string" do + result = scope.function_reverse(["asdfghijkl"]) + result.should(eq('lkjihgfdsa')) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb new file mode 100644 index 000000000..d90de1d06 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/rstrip_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the rstrip function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("rstrip").should == "function_rstrip" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_rstrip([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should rstrip a string" do + result = scope.function_rstrip(["asdf "]) + result.should(eq('asdf')) + end + + it "should rstrip each element in an array" do + result = scope.function_rstrip([["a ","b ", "c "]]) + result.should(eq(['a','b','c'])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb new file mode 100644 index 000000000..93346d537 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/shuffle_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the shuffle function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("shuffle").should == "function_shuffle" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_shuffle([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should shuffle a string and the result should be the same size" do + result = scope.function_shuffle(["asdf"]) + result.size.should(eq(4)) + end + + it "should shuffle a string but the sorted contents should still be the same" do + result = scope.function_shuffle(["adfs"]) + result.split("").sort.join("").should(eq("adfs")) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb new file mode 100644 index 000000000..b1c435a30 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/size_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the size function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("size").should == "function_size" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_size([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return the size of a string" do + result = scope.function_size(["asdf"]) + result.should(eq(4)) + end + + it "should return the size of an array" do + result = scope.function_size([["a","b","c"]]) + result.should(eq(3)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb new file mode 100644 index 000000000..3187a5aec --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/sort_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the sort function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("sort").should == "function_sort" + end + + it "should raise a ParseError if there is not 1 arguments" do + lambda { scope.function_sort(['','']) }.should( raise_error(Puppet::ParseError)) + end + + it "should sort an array" do + result = scope.function_sort([["a","c","b"]]) + result.should(eq(['a','b','c'])) + end + + it "should sort a string" do + result = scope.function_sort(["acb"]) + result.should(eq('abc')) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb new file mode 100644 index 000000000..60e5a3028 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/squeeze_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the squeeze function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("squeeze").should == "function_squeeze" + end + + it "should raise a ParseError if there is less than 2 arguments" do + lambda { scope.function_squeeze([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should squeeze a string" do + result = scope.function_squeeze(["aaabbbbcccc"]) + result.should(eq('abc')) + end + + it "should squeeze all elements in an array" do + result = scope.function_squeeze([["aaabbbbcccc","dddfff"]]) + result.should(eq(['abc','df'])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb new file mode 100644 index 000000000..ef6350f25 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/str2bool_spec.rb @@ -0,0 +1,31 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the str2bool function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("str2bool").should == "function_str2bool" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_str2bool([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert string 'true' to true" do + result = scope.function_str2bool(["true"]) + result.should(eq(true)) + end + + it "should convert string 'undef' to false" do + result = scope.function_str2bool(["undef"]) + result.should(eq(false)) + end + + it "should return the boolean it was called with" do + result = scope.function_str2bool([true]) + result.should(eq(true)) + result = scope.function_str2bool([false]) + result.should(eq(false)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb new file mode 100644 index 000000000..df8fb8e90 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/str2saltedsha512_spec.rb @@ -0,0 +1,45 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the str2saltedsha512 function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("str2saltedsha512").should == "function_str2saltedsha512" + end + + it "should raise a ParseError if there is less than 1 argument" do + expect { scope.function_str2saltedsha512([]) }.to( raise_error(Puppet::ParseError) ) + end + + it "should raise a ParseError if there is more than 1 argument" do + expect { scope.function_str2saltedsha512(['foo', 'bar', 'baz']) }.to( raise_error(Puppet::ParseError) ) + end + + it "should return a salted-sha512 password hash 136 characters in length" do + result = scope.function_str2saltedsha512(["password"]) + result.length.should(eq(136)) + end + + it "should raise an error if you pass a non-string password" do + expect { scope.function_str2saltedsha512([1234]) }.to( raise_error(Puppet::ParseError) ) + end + + it "should generate a valid password" do + # Allow the function to generate a password based on the string 'password' + password_hash = scope.function_str2saltedsha512(["password"]) + + # Separate the Salt and Password from the Password Hash + salt = password_hash[0..7] + password = password_hash[8..-1] + + # Convert the Salt and Password from Hex to Binary Data + str_salt = Array(salt.lines).pack('H*') + str_password = Array(password.lines).pack('H*') + + # Combine the Binary Salt with 'password' and compare the end result + saltedpass = Digest::SHA512.digest(str_salt + 'password') + result = (str_salt + saltedpass).unpack('H*')[0] + result.should == password_hash + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb new file mode 100644 index 000000000..df42b6f26 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/strftime_spec.rb @@ -0,0 +1,29 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the strftime function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("strftime").should == "function_strftime" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_strftime([]) }.should( raise_error(Puppet::ParseError)) + end + + it "using %s should be higher then when I wrote this test" do + result = scope.function_strftime(["%s"]) + result.to_i.should(be > 1311953157) + end + + it "using %s should be lower then 1.5 trillion" do + result = scope.function_strftime(["%s"]) + result.to_i.should(be < 1500000000) + end + + it "should return a date when given %Y-%m-%d" do + result = scope.function_strftime(["%Y-%m-%d"]) + result.should =~ /^\d{4}-\d{2}-\d{2}$/ + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb new file mode 100644 index 000000000..fccdd2606 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/strip_spec.rb @@ -0,0 +1,18 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the strip function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + it "should exist" do + Puppet::Parser::Functions.function("strip").should == "function_strip" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_strip([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should strip a string" do + result = scope.function_strip([" ab cd "]) + result.should(eq('ab cd')) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb new file mode 100644 index 000000000..c28f719c8 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/suffix_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the suffix function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("suffix").should == "function_suffix" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_suffix([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return a suffixed array" do + result = scope.function_suffix([['a','b','c'], 'p']) + result.should(eq(['ap','bp','cp'])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb new file mode 100644 index 000000000..808b41587 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/swapcase_spec.rb @@ -0,0 +1,19 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the swapcase function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("swapcase").should == "function_swapcase" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_swapcase([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should swapcase a string" do + result = scope.function_swapcase(["aaBBccDD"]) + result.should(eq('AAbbCCdd')) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb new file mode 100644 index 000000000..e9fb76e6a --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/time_spec.rb @@ -0,0 +1,29 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the time function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("time").should == "function_time" + end + + it "should raise a ParseError if there is more than 2 arguments" do + lambda { scope.function_time(['','']) }.should( raise_error(Puppet::ParseError)) + end + + it "should return a number" do + result = scope.function_time([]) + result.should be_an(Integer) + end + + it "should be higher then when I wrote this test" do + result = scope.function_time([]) + result.should(be > 1311953157) + end + + it "should be lower then 1.5 trillion" do + result = scope.function_time([]) + result.should(be < 1500000000) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb new file mode 100755 index 000000000..d1ea4c80c --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/to_bytes_spec.rb @@ -0,0 +1,58 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the to_bytes function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("to_bytes").should == "function_to_bytes" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_to_bytes([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should convert kB to B" do + result = scope.function_to_bytes(["4 kB"]) + result.should(eq(4096)) + end + + it "should work without B in unit" do + result = scope.function_to_bytes(["4 k"]) + result.should(eq(4096)) + end + + it "should work without a space before unit" do + result = scope.function_to_bytes(["4k"]) + result.should(eq(4096)) + end + + it "should work without a unit" do + result = scope.function_to_bytes(["5678"]) + result.should(eq(5678)) + end + + it "should convert fractions" do + result = scope.function_to_bytes(["1.5 kB"]) + result.should(eq(1536)) + end + + it "should convert scientific notation" do + result = scope.function_to_bytes(["1.5e2 B"]) + result.should(eq(150)) + end + + it "should do nothing with a positive number" do + result = scope.function_to_bytes([5678]) + result.should(eq(5678)) + end + + it "should should raise a ParseError if input isn't a number" do + lambda { scope.function_to_bytes(["foo"]) }.should( raise_error(Puppet::ParseError)) + end + + it "should should raise a ParseError if prefix is unknown" do + lambda { scope.function_to_bytes(["5 uB"]) }.should( raise_error(Puppet::ParseError)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb new file mode 100644 index 000000000..8fec88f26 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/type_spec.rb @@ -0,0 +1,43 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the type function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + it "should exist" do + Puppet::Parser::Functions.function("type").should == "function_type" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_type([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return string when given a string" do + result = scope.function_type(["aaabbbbcccc"]) + result.should(eq('string')) + end + + it "should return array when given an array" do + result = scope.function_type([["aaabbbbcccc","asdf"]]) + result.should(eq('array')) + end + + it "should return hash when given a hash" do + result = scope.function_type([{"a"=>1,"b"=>2}]) + result.should(eq('hash')) + end + + it "should return integer when given an integer" do + result = scope.function_type(["1"]) + result.should(eq('integer')) + end + + it "should return float when given a float" do + result = scope.function_type(["1.34"]) + result.should(eq('float')) + end + + it "should return boolean when given a boolean" do + result = scope.function_type([true]) + result.should(eq('boolean')) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb new file mode 100644 index 000000000..5d48d49b7 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/unique_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the unique function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("unique").should == "function_unique" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_unique([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should remove duplicate elements in a string" do + result = scope.function_unique(["aabbc"]) + result.should(eq('abc')) + end + + it "should remove duplicate elements in an array" do + result = scope.function_unique([["a","a","b","b","c"]]) + result.should(eq(['a','b','c'])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb new file mode 100644 index 000000000..5db55138a --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/upcase_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the upcase function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("upcase").should == "function_upcase" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_upcase([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should upcase a string" do + result = scope.function_upcase(["abc"]) + result.should(eq('ABC')) + end + + it "should do nothing if a string is already upcase" do + result = scope.function_upcase(["ABC"]) + result.should(eq('ABC')) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb new file mode 100644 index 000000000..371de4687 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/uriescape_spec.rb @@ -0,0 +1,24 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the uriescape function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("uriescape").should == "function_uriescape" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_uriescape([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should uriescape a string" do + result = scope.function_uriescape([":/?#[]@!$&'()*+,;= "]) + result.should(eq('%3A%2F%3F%23%5B%5D%40%21%24%26%27%28%29%2A%2B%2C%3B%3D%20')) + end + + it "should do nothing if a string is already safe" do + result = scope.function_uriescape(["ABCdef"]) + result.should(eq('ABCdef')) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb new file mode 100644 index 000000000..08aaf7899 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_absolute_path_spec.rb @@ -0,0 +1,83 @@ +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:validate_absolute_path) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + # The subject of these examples is the method itself. + subject do + # This makes sure the function is loaded within each test + function_name = Puppet::Parser::Functions.function(:validate_absolute_path) + scope.method(function_name) + end + + describe "Valid Paths" do + def self.valid_paths + %w{ + C:/ + C:\\ + C:\\WINDOWS\\System32 + C:/windows/system32 + X:/foo/bar + X:\\foo\\bar + /var/tmp + /var/lib/puppet + /var/opt/../lib/puppet + } + end + + context "Without Puppet::Util.absolute_path? (e.g. Puppet <= 2.6)" do + before :each do + # The intent here is to mock Puppet to behave like Puppet 2.6 does. + # Puppet 2.6 does not have the absolute_path? method. This is only a + # convenience test, stdlib should be run with the Puppet 2.6.x in the + # $LOAD_PATH in addition to 2.7.x and master. + Puppet::Util.expects(:respond_to?).with(:absolute_path?).returns(false) + end + valid_paths.each do |path| + it "validate_absolute_path(#{path.inspect}) should not fail" do + expect { subject.call [path] }.not_to raise_error Puppet::ParseError + end + end + end + + context "Puppet without mocking" do + valid_paths.each do |path| + it "validate_absolute_path(#{path.inspect}) should not fail" do + expect { subject.call [path] }.not_to raise_error Puppet::ParseError + end + end + end + end + + describe 'Invalid paths' do + context 'Garbage inputs' do + [ + nil, + [ nil ], + { 'foo' => 'bar' }, + { }, + '', + ].each do |path| + it "validate_absolute_path(#{path.inspect}) should fail" do + expect { subject.call [path] }.to raise_error Puppet::ParseError + end + end + end + + context 'Relative paths' do + %w{ + relative1 + . + .. + ./foo + ../foo + etc/puppetlabs/puppet + opt/puppet/bin + }.each do |path| + it "validate_absolute_path(#{path.inspect}) should fail" do + expect { subject.call [path] }.to raise_error Puppet::ParseError + end + end + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb new file mode 100644 index 000000000..4b31cfde4 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_array_spec.rb @@ -0,0 +1,38 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:validate_array) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + describe 'when calling validate_array from puppet' do + + %w{ true false }.each do |the_string| + it "should not compile when #{the_string} is a string" do + Puppet[:code] = "validate_array('#{the_string}')" + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) + end + + it "should not compile when #{the_string} is a bare word" do + Puppet[:code] = "validate_array(#{the_string})" + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) + end + end + + it "should compile when multiple array arguments are passed" do + Puppet[:code] = <<-'ENDofPUPPETcode' + $foo = [ ] + $bar = [ 'one', 'two' ] + validate_array($foo, $bar) + ENDofPUPPETcode + scope.compiler.compile + end + + it "should not compile when an undef variable is passed" do + Puppet[:code] = <<-'ENDofPUPPETcode' + $foo = undef + validate_array($foo) + ENDofPUPPETcode + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not an Array/) + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb new file mode 100644 index 000000000..ab5c140d1 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_augeas_spec.rb @@ -0,0 +1,102 @@ +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:validate_augeas), :if => Puppet.features.augeas? do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + # The subject of these examplres is the method itself. + subject do + # This makes sure the function is loaded within each test + function_name = Puppet::Parser::Functions.function(:validate_augeas) + scope.method(function_name) + end + + context 'Using Puppet::Parser::Scope.new' do + + describe 'Garbage inputs' do + inputs = [ + [ nil ], + [ [ nil ] ], + [ { 'foo' => 'bar' } ], + [ { } ], + [ '' ], + [ "one", "one", "MSG to User", "4th arg" ], + ] + + inputs.each do |input| + it "validate_augeas(#{input.inspect}) should fail" do + expect { subject.call [input] }.to raise_error Puppet::ParseError + end + end + end + + describe 'Valid inputs' do + inputs = [ + [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns' ], + [ "proc /proc proc nodev,noexec,nosuid 0 0\n", 'Fstab.lns'], + ] + + inputs.each do |input| + it "validate_augeas(#{input.inspect}) should not fail" do + expect { subject.call input }.not_to raise_error + end + end + end + + describe "Valid inputs which should raise an exception without a message" do + # The intent here is to make sure valid inputs raise exceptions when they + # don't specify an error message to display. This is the behvior in + # 2.2.x and prior. + inputs = [ + [ "root:x:0:0:root\n", 'Passwd.lns' ], + [ "127.0.1.1\n", 'Hosts.lns' ], + ] + + inputs.each do |input| + it "validate_augeas(#{input.inspect}) should fail" do + expect { subject.call input }.to raise_error /validate_augeas.*?matched less than it should/ + end + end + end + + describe "Nicer Error Messages" do + # The intent here is to make sure the function returns the 3rd argument + # in the exception thrown + inputs = [ + [ "root:x:0:0:root\n", 'Passwd.lns', [], 'Failed to validate passwd content' ], + [ "127.0.1.1\n", 'Hosts.lns', [], 'Wrong hosts content' ], + ] + + inputs.each do |input| + it "validate_augeas(#{input.inspect}) should fail" do + expect { subject.call input }.to raise_error /#{input[2]}/ + end + end + end + + describe "Passing simple unit tests" do + inputs = [ + [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']], + [ "root:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']], + ] + + inputs.each do |input| + it "validate_augeas(#{input.inspect}) should fail" do + expect { subject.call input }.not_to raise_error + end + end + end + + describe "Failing simple unit tests" do + inputs = [ + [ "foobar:x:0:0:root:/root:/bin/bash\n", 'Passwd.lns', ['$file/foobar']], + [ "root:x:0:0:root:/root:/bin/sh\n", 'Passwd.lns', ['$file/root/shell[.="/bin/sh"]', 'foobar']], + ] + + inputs.each do |input| + it "validate_augeas(#{input.inspect}) should fail" do + expect { subject.call input }.to raise_error /testing path/ + end + end + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb new file mode 100644 index 000000000..261fb2352 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_bool_spec.rb @@ -0,0 +1,51 @@ +#! /usr/bin/env/ruby -S rspec + +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:validate_bool) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + describe 'when calling validate_bool from puppet' do + + %w{ true false }.each do |the_string| + + it "should not compile when #{the_string} is a string" do + Puppet[:code] = "validate_bool('#{the_string}')" + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/) + end + + it "should compile when #{the_string} is a bare word" do + Puppet[:code] = "validate_bool(#{the_string})" + scope.compiler.compile + end + + end + + it "should not compile when an arbitrary string is passed" do + Puppet[:code] = 'validate_bool("jeff and dan are awesome")' + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/) + end + + it "should not compile when no arguments are passed" do + Puppet[:code] = 'validate_bool()' + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /wrong number of arguments/) + end + + it "should compile when multiple boolean arguments are passed" do + Puppet[:code] = <<-'ENDofPUPPETcode' + $foo = true + $bar = false + validate_bool($foo, $bar, true, false) + ENDofPUPPETcode + scope.compiler.compile + end + + it "should compile when multiple boolean arguments are passed" do + Puppet[:code] = <<-'ENDofPUPPETcode' + $foo = true + $bar = false + validate_bool($foo, $bar, true, false, 'jeff') + ENDofPUPPETcode + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a boolean/) + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb new file mode 100644 index 000000000..69ea7f496 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_cmd_spec.rb @@ -0,0 +1,81 @@ +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:validate_cmd) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + # The subject of these examplres is the method itself. + subject do + # This makes sure the function is loaded within each test + function_name = Puppet::Parser::Functions.function(:validate_cmd) + scope.method(function_name) + end + + context 'Using Puppet::Parser::Scope.new' do + + describe 'Garbage inputs' do + inputs = [ + [ nil ], + [ [ nil ] ], + [ { 'foo' => 'bar' } ], + [ { } ], + [ '' ], + [ "one", "one", "MSG to User", "4th arg" ], + ] + + inputs.each do |input| + it "validate_cmd(#{input.inspect}) should fail" do + expect { subject.call [input] }.to raise_error Puppet::ParseError + end + end + end + + describe 'Valid inputs' do + inputs = [ + [ '/full/path/to/something', '/bin/echo' ], + [ '/full/path/to/something', '/bin/cat' ], + ] + + inputs.each do |input| + it "validate_cmd(#{input.inspect}) should not fail" do + expect { subject.call input }.not_to raise_error + end + end + end + + describe "Valid inputs which should raise an exception without a message" do + # The intent here is to make sure valid inputs raise exceptions when they + # don't specify an error message to display. This is the behvior in + # 2.2.x and prior. + inputs = [ + [ "hello", "/bin/false" ], + ] + + inputs.each do |input| + it "validate_cmd(#{input.inspect}) should fail" do + expect { subject.call input }.to raise_error /validate_cmd.*?failed to validate content with command/ + end + end + end + + describe "Nicer Error Messages" do + # The intent here is to make sure the function returns the 3rd argument + # in the exception thrown + inputs = [ + [ "hello", [ "bye", "later", "adios" ], "MSG to User" ], + [ "greetings", "salutations", "Error, greetings does not match salutations" ], + ] + + inputs.each do |input| + it "validate_cmd(#{input.inspect}) should fail" do + expect { subject.call input }.to raise_error /#{input[2]}/ + end + end + end + + describe "Test output message" do + it "validate_cmd('whatever', 'kthnksbye') should fail" do + expect { subject.call ['whatever', 'kthnksbye'] }.to raise_error /kthnksbye.* returned 1/ + end + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb new file mode 100644 index 000000000..a0c35c230 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_hash_spec.rb @@ -0,0 +1,43 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:validate_hash) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + describe 'when calling validate_hash from puppet' do + + %w{ true false }.each do |the_string| + + it "should not compile when #{the_string} is a string" do + Puppet[:code] = "validate_hash('#{the_string}')" + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) + end + + it "should not compile when #{the_string} is a bare word" do + Puppet[:code] = "validate_hash(#{the_string})" + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) + end + + end + + it "should compile when multiple hash arguments are passed" do + Puppet[:code] = <<-'ENDofPUPPETcode' + $foo = {} + $bar = { 'one' => 'two' } + validate_hash($foo, $bar) + ENDofPUPPETcode + scope.compiler.compile + end + + it "should not compile when an undef variable is passed" do + Puppet[:code] = <<-'ENDofPUPPETcode' + $foo = undef + validate_hash($foo) + ENDofPUPPETcode + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a Hash/) + end + + end + +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb new file mode 100644 index 000000000..d189efb66 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_re_spec.rb @@ -0,0 +1,76 @@ +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:validate_re) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + # The subject of these examplres is the method itself. + subject do + # This makes sure the function is loaded within each test + function_name = Puppet::Parser::Functions.function(:validate_re) + scope.method(function_name) + end + + context 'Using Puppet::Parser::Scope.new' do + + describe 'Garbage inputs' do + inputs = [ + [ nil ], + [ [ nil ] ], + [ { 'foo' => 'bar' } ], + [ { } ], + [ '' ], + [ "one", "one", "MSG to User", "4th arg" ], + ] + + inputs.each do |input| + it "validate_re(#{input.inspect}) should fail" do + expect { subject.call [input] }.to raise_error Puppet::ParseError + end + end + end + + describe 'Valid inputs' do + inputs = [ + [ '/full/path/to/something', '^/full' ], + [ '/full/path/to/something', 'full' ], + [ '/full/path/to/something', ['full', 'absent'] ], + [ '/full/path/to/something', ['full', 'absent'], 'Message to the user' ], + ] + + inputs.each do |input| + it "validate_re(#{input.inspect}) should not fail" do + expect { subject.call input }.not_to raise_error + end + end + end + describe "Valid inputs which should raise an exception without a message" do + # The intent here is to make sure valid inputs raise exceptions when they + # don't specify an error message to display. This is the behvior in + # 2.2.x and prior. + inputs = [ + [ "hello", [ "bye", "later", "adios" ] ], + [ "greetings", "salutations" ], + ] + + inputs.each do |input| + it "validate_re(#{input.inspect}) should fail" do + expect { subject.call input }.to raise_error /validate_re.*?does not match/ + end + end + end + describe "Nicer Error Messages" do + # The intent here is to make sure the function returns the 3rd argument + # in the exception thrown + inputs = [ + [ "hello", [ "bye", "later", "adios" ], "MSG to User" ], + [ "greetings", "salutations", "Error, greetings does not match salutations" ], + ] + + inputs.each do |input| + it "validate_re(#{input.inspect}) should fail" do + expect { subject.call input }.to raise_error /#{input[2]}/ + end + end + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb new file mode 100755 index 000000000..eccf908de --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_slength_spec.rb @@ -0,0 +1,48 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe "the validate_slength function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("validate_slength").should == "function_validate_slength" + end + + it "should raise a ParseError if there is less than 2 arguments" do + expect { scope.function_validate_slength([]) }.to(raise_error(Puppet::ParseError)) + expect { scope.function_validate_slength(["asdf"]) }.to(raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if argument 2 doesn't convert to a fixnum" do + expect { scope.function_validate_slength(["moo",["2"]]) }.to(raise_error(Puppet::ParseError, /Couldn't convert whatever you passed/)) + end + + it "should raise a ParseError if argument 2 converted, but to 0, e.g. a string" do + expect { scope.function_validate_slength(["moo","monkey"]) }.to(raise_error(Puppet::ParseError, /please pass a positive number as max_length/)) + end + + it "should raise a ParseError if argument 2 converted, but to 0" do + expect { scope.function_validate_slength(["moo","0"]) }.to(raise_error(Puppet::ParseError, /please pass a positive number as max_length/)) + end + + it "should fail if string greater then size" do + expect { scope.function_validate_slength(["test", 2]) }.to(raise_error(Puppet::ParseError, /It should have been less than or equal to/)) + end + + it "should fail if you pass an array of something other than strings" do + expect { scope.function_validate_slength([["moo",["moo"],Hash.new["moo" => 7]], 7]) }.to(raise_error(Puppet::ParseError, /is not a string, it's a/)) + end + + it "should fail if you pass something other than a string or array" do + expect { scope.function_validate_slength([Hash.new["moo" => "7"],6]) }.to(raise_error(Puppet::ParseError), /please pass a string, or an array of strings/) + end + + it "should not fail if string is smaller or equal to size" do + expect { scope.function_validate_slength(["test", 5]) }.to_not(raise_error(Puppet::ParseError)) + end + + it "should not fail if array of string is are all smaller or equal to size" do + expect { scope.function_validate_slength([["moo","foo","bar"], 5]) }.to_not(raise_error(Puppet::ParseError)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb new file mode 100644 index 000000000..3b4fb3e1d --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/validate_string_spec.rb @@ -0,0 +1,60 @@ +#! /usr/bin/env ruby -S rspec + +require 'spec_helper' + +describe Puppet::Parser::Functions.function(:validate_string) do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + describe 'when calling validate_string from puppet' do + + %w{ foo bar baz }.each do |the_string| + + it "should compile when #{the_string} is a string" do + Puppet[:code] = "validate_string('#{the_string}')" + scope.compiler.compile + end + + it "should compile when #{the_string} is a bare word" do + Puppet[:code] = "validate_string(#{the_string})" + scope.compiler.compile + end + + end + + %w{ true false }.each do |the_string| + it "should compile when #{the_string} is a string" do + Puppet[:code] = "validate_string('#{the_string}')" + scope.compiler.compile + end + + it "should not compile when #{the_string} is a bare word" do + Puppet[:code] = "validate_string(#{the_string})" + expect { scope.compiler.compile }.to raise_error(Puppet::ParseError, /is not a string/) + end + end + + it "should compile when multiple string arguments are passed" do + Puppet[:code] = <<-'ENDofPUPPETcode' + $foo = '' + $bar = 'two' + validate_string($foo, $bar) + ENDofPUPPETcode + scope.compiler.compile + end + + it "should compile when an explicitly undef variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do + Puppet[:code] = <<-'ENDofPUPPETcode' + $foo = undef + validate_string($foo) + ENDofPUPPETcode + scope.compiler.compile + end + + it "should compile when an undefined variable is passed (NOTE THIS MAY NOT BE DESIRABLE)" do + Puppet[:code] = <<-'ENDofPUPPETcode' + validate_string($foobarbazishouldnotexist) + ENDofPUPPETcode + scope.compiler.compile + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb new file mode 100644 index 000000000..08e95a567 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/values_at_spec.rb @@ -0,0 +1,38 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the values_at function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("values_at").should == "function_values_at" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_values_at([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should raise a ParseError if you try to use a range where stop is greater then start" do + lambda { scope.function_values_at([['a','b'],["3-1"]]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return a value at from an array" do + result = scope.function_values_at([['a','b','c'],"1"]) + result.should(eq(['b'])) + end + + it "should return a value at from an array when passed a range" do + result = scope.function_values_at([['a','b','c'],"0-1"]) + result.should(eq(['a','b'])) + end + + it "should return chosen values from an array when passed number of indexes" do + result = scope.function_values_at([['a','b','c'],["0","2"]]) + result.should(eq(['a','c'])) + end + + it "should return chosen values from an array when passed ranges and multiple indexes" do + result = scope.function_values_at([['a','b','c','d','e','f','g'],["0","2","4-5"]]) + result.should(eq(['a','c','e','f'])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb new file mode 100644 index 000000000..14ae41763 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/values_spec.rb @@ -0,0 +1,31 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the values function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should exist" do + Puppet::Parser::Functions.function("values").should == "function_values" + end + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_values([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should return values from a hash" do + result = scope.function_values([{'a'=>'1','b'=>'2','c'=>'3'}]) + # =~ is the RSpec::Matchers::MatchArray matcher. + # A.K.A. "array with same elements" (multiset) matching + result.should =~ %w{ 1 2 3 } + end + + it "should return a multiset" do + result = scope.function_values([{'a'=>'1','b'=>'3','c'=>'3'}]) + result.should =~ %w{ 1 3 3 } + result.should_not =~ %w{ 1 3 } + end + + it "should raise a ParseError unless a Hash is provided" do + lambda { scope.function_values([['a','b','c']]) }.should( raise_error(Puppet::ParseError)) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb new file mode 100644 index 000000000..f45ab1730 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/parser/functions/zip_spec.rb @@ -0,0 +1,15 @@ +#! /usr/bin/env ruby -S rspec +require 'spec_helper' + +describe "the zip function" do + let(:scope) { PuppetlabsSpec::PuppetInternals.scope } + + it "should raise a ParseError if there is less than 1 arguments" do + lambda { scope.function_zip([]) }.should( raise_error(Puppet::ParseError)) + end + + it "should be able to zip an array" do + result = scope.function_zip([['1','2','3'],['4','5','6']]) + result.should(eq([["1", "4"], ["2", "5"], ["3", "6"]])) + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb new file mode 100644 index 000000000..7857d399f --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/provider/file_line/ruby_spec.rb @@ -0,0 +1,127 @@ +require 'puppet' +require 'tempfile' +provider_class = Puppet::Type.type(:file_line).provider(:ruby) +describe provider_class do + context "when adding" do + before :each do + # TODO: these should be ported over to use the PuppetLabs spec_helper + # file fixtures once the following pull request has been merged: + # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files + tmp = Tempfile.new('tmp') + @tmpfile = tmp.path + tmp.close! + @resource = Puppet::Type::File_line.new( + {:name => 'foo', :path => @tmpfile, :line => 'foo'} + ) + @provider = provider_class.new(@resource) + end + it 'should detect if the line exists in the file' do + File.open(@tmpfile, 'w') do |fh| + fh.write('foo') + end + @provider.exists?.should be_true + end + it 'should detect if the line does not exist in the file' do + File.open(@tmpfile, 'w') do |fh| + fh.write('foo1') + end + @provider.exists?.should be_nil + end + it 'should append to an existing file when creating' do + @provider.create + File.read(@tmpfile).chomp.should == 'foo' + end + end + + context "when matching" do + before :each do + # TODO: these should be ported over to use the PuppetLabs spec_helper + # file fixtures once the following pull request has been merged: + # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files + tmp = Tempfile.new('tmp') + @tmpfile = tmp.path + tmp.close! + @resource = Puppet::Type::File_line.new( + { + :name => 'foo', + :path => @tmpfile, + :line => 'foo = bar', + :match => '^foo\s*=.*$', + } + ) + @provider = provider_class.new(@resource) + end + + it 'should raise an error if more than one line matches, and should not have modified the file' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo=blah\nfoo2\nfoo=baz") + end + @provider.exists?.should be_nil + expect { @provider.create }.to raise_error(Puppet::Error, /More than one line.*matches/) + File.read(@tmpfile).should eql("foo1\nfoo=blah\nfoo2\nfoo=baz") + end + + it 'should replace a line that matches' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo=blah\nfoo2") + end + @provider.exists?.should be_nil + @provider.create + File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2") + end + it 'should add a new line if no lines match' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo2") + end + @provider.exists?.should be_nil + @provider.create + File.read(@tmpfile).should eql("foo1\nfoo2\nfoo = bar\n") + end + it 'should do nothing if the exact line already exists' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo = bar\nfoo2") + end + @provider.exists?.should be_true + @provider.create + File.read(@tmpfile).chomp.should eql("foo1\nfoo = bar\nfoo2") + end + end + + context "when removing" do + before :each do + # TODO: these should be ported over to use the PuppetLabs spec_helper + # file fixtures once the following pull request has been merged: + # https://github.com/puppetlabs/puppetlabs-stdlib/pull/73/files + tmp = Tempfile.new('tmp') + @tmpfile = tmp.path + tmp.close! + @resource = Puppet::Type::File_line.new( + {:name => 'foo', :path => @tmpfile, :line => 'foo', :ensure => 'absent' } + ) + @provider = provider_class.new(@resource) + end + it 'should remove the line if it exists' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo\nfoo2") + end + @provider.destroy + File.read(@tmpfile).should eql("foo1\nfoo2") + end + + it 'should remove the line without touching the last new line' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo\nfoo2\n") + end + @provider.destroy + File.read(@tmpfile).should eql("foo1\nfoo2\n") + end + + it 'should remove any occurence of the line' do + File.open(@tmpfile, 'w') do |fh| + fh.write("foo1\nfoo\nfoo2\nfoo\nfoo") + end + @provider.destroy + File.read(@tmpfile).should eql("foo1\nfoo2\n") + end + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb new file mode 100644 index 000000000..2030b83f2 --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/type/anchor_spec.rb @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby + +require 'puppet' + +anchor = Puppet::Type.type(:anchor).new(:name => "ntp::begin") + +describe anchor do + it "should stringify normally" do + anchor.to_s.should == "Anchor[ntp::begin]" + end +end diff --git a/deployment/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb b/deployment/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb new file mode 100644 index 000000000..edc64bd1e --- /dev/null +++ b/deployment/modules/stdlib/spec/unit/puppet/type/file_line_spec.rb @@ -0,0 +1,69 @@ +require 'puppet' +require 'tempfile' +describe Puppet::Type.type(:file_line) do + let :file_line do + Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'line', :path => '/tmp/path') + end + it 'should accept a line and path' do + file_line[:line] = 'my_line' + file_line[:line].should == 'my_line' + file_line[:path] = '/my/path' + file_line[:path].should == '/my/path' + end + it 'should accept a match regex' do + file_line[:match] = '^foo.*$' + file_line[:match].should == '^foo.*$' + end + it 'should not accept a match regex that does not match the specified line' do + expect { + Puppet::Type.type(:file_line).new( + :name => 'foo', + :path => '/my/path', + :line => 'foo=bar', + :match => '^bar=blah$' + )}.to raise_error(Puppet::Error, /the value must be a regex that matches/) + end + it 'should accept a match regex that does match the specified line' do + expect { + Puppet::Type.type(:file_line).new( + :name => 'foo', + :path => '/my/path', + :line => 'foo=bar', + :match => '^\s*foo=.*$' + )}.not_to raise_error + end + it 'should accept posix filenames' do + file_line[:path] = '/tmp/path' + file_line[:path].should == '/tmp/path' + end + it 'should not accept unqualified path' do + expect { file_line[:path] = 'file' }.to raise_error(Puppet::Error, /File paths must be fully qualified/) + end + it 'should require that a line is specified' do + expect { Puppet::Type.type(:file_line).new(:name => 'foo', :path => '/tmp/file') }.to raise_error(Puppet::Error, /Both line and path are required attributes/) + end + it 'should require that a file is specified' do + expect { Puppet::Type.type(:file_line).new(:name => 'foo', :line => 'path') }.to raise_error(Puppet::Error, /Both line and path are required attributes/) + end + it 'should default to ensure => present' do + file_line[:ensure].should eq :present + end + + it "should autorequire the file it manages" do + catalog = Puppet::Resource::Catalog.new + file = Puppet::Type.type(:file).new(:name => "/tmp/path") + catalog.add_resource file + catalog.add_resource file_line + + relationship = file_line.autorequire.find do |rel| + (rel.source.to_s == "File[/tmp/path]") and (rel.target.to_s == file_line.to_s) + end + relationship.should be_a Puppet::Relationship + end + + it "should not autorequire the file it manages if it is not managed" do + catalog = Puppet::Resource::Catalog.new + catalog.add_resource file_line + file_line.autorequire.should be_empty + end +end diff --git a/deployment/modules/stdlib/spec/watchr.rb b/deployment/modules/stdlib/spec/watchr.rb new file mode 100644 index 000000000..885ef1d5f --- /dev/null +++ b/deployment/modules/stdlib/spec/watchr.rb @@ -0,0 +1,86 @@ +ENV['FOG_MOCK'] ||= 'true' +ENV['AUTOTEST'] = 'true' +ENV['WATCHR'] = '1' + +system 'clear' + +def growl(message) + growlnotify = `which growlnotify`.chomp + title = "Watchr Test Results" + image = case message + when /(\d+)\s+?(failure|error)/i + ($1.to_i == 0) ? "~/.watchr_images/passed.png" : "~/.watchr_images/failed.png" + else + '~/.watchr_images/unknown.png' + end + options = "-w -n Watchr --image '#{File.expand_path(image)}' -m '#{message}' '#{title}'" + system %(#{growlnotify} #{options} &) +end + +def run(cmd) + puts(cmd) + `#{cmd}` +end + +def run_spec_test(file) + if File.exist? file + result = run "rspec --format p --color #{file}" + growl result.split("\n").last + puts result + else + puts "FIXME: No test #{file} [#{Time.now}]" + end +end + +def filter_rspec(data) + data.split("\n").find_all do |l| + l =~ /^(\d+)\s+exampl\w+.*?(\d+).*?failur\w+.*?(\d+).*?pending/ + end.join("\n") +end + +def run_all_tests + system('clear') + files = Dir.glob("spec/**/*_spec.rb").join(" ") + result = run "rspec #{files}" + growl_results = filter_rspec result + growl growl_results + puts result + puts "GROWL: #{growl_results}" +end + +# Ctrl-\ +Signal.trap 'QUIT' do + puts " --- Running all tests ---\n\n" + run_all_tests +end + +@interrupted = false + +# Ctrl-C +Signal.trap 'INT' do + if @interrupted then + @wants_to_quit = true + abort("\n") + else + puts "Interrupt a second time to quit" + @interrupted = true + Kernel.sleep 1.5 + # raise Interrupt, nil # let the run loop catch it + run_suite + end +end + +def file2spec(file) + result = file.sub('lib/puppet/', 'spec/unit/puppet/').gsub(/\.rb$/, '_spec.rb') + result = file.sub('lib/facter/', 'spec/unit/facter/').gsub(/\.rb$/, '_spec.rb') +end + + +watch( 'spec/.*_spec\.rb' ) do |md| + #run_spec_test(md[0]) + run_all_tests +end +watch( 'lib/.*\.rb' ) do |md| + # run_spec_test(file2spec(md[0])) + run_all_tests +end diff --git a/deployment/modules/stdlib/tests/file_line.pp b/deployment/modules/stdlib/tests/file_line.pp new file mode 100644 index 000000000..eea693e15 --- /dev/null +++ b/deployment/modules/stdlib/tests/file_line.pp @@ -0,0 +1,9 @@ +# This is a simple smoke test +# of the file_line resource type. +file { '/tmp/dansfile': + ensure => present +}-> +file_line { 'dans_line': + line => 'dan is awesome', + path => '/tmp/dansfile', +} diff --git a/deployment/modules/stdlib/tests/has_interface_with.pp b/deployment/modules/stdlib/tests/has_interface_with.pp new file mode 100644 index 000000000..e1f1353cd --- /dev/null +++ b/deployment/modules/stdlib/tests/has_interface_with.pp @@ -0,0 +1,10 @@ +include stdlib +info('has_interface_with(\'lo\'):', has_interface_with('lo')) +info('has_interface_with(\'loX\'):', has_interface_with('loX')) +info('has_interface_with(\'ipaddress\', \'127.0.0.1\'):', has_interface_with('ipaddress', '127.0.0.1')) +info('has_interface_with(\'ipaddress\', \'127.0.0.100\'):', has_interface_with('ipaddress', '127.0.0.100')) +info('has_interface_with(\'network\', \'127.0.0.0\'):', has_interface_with('network', '127.0.0.0')) +info('has_interface_with(\'network\', \'128.0.0.0\'):', has_interface_with('network', '128.0.0.0')) +info('has_interface_with(\'netmask\', \'255.0.0.0\'):', has_interface_with('netmask', '255.0.0.0')) +info('has_interface_with(\'netmask\', \'256.0.0.0\'):', has_interface_with('netmask', '256.0.0.0')) + diff --git a/deployment/modules/stdlib/tests/has_ip_address.pp b/deployment/modules/stdlib/tests/has_ip_address.pp new file mode 100644 index 000000000..8429a8855 --- /dev/null +++ b/deployment/modules/stdlib/tests/has_ip_address.pp @@ -0,0 +1,3 @@ +include stdlib +info('has_ip_address(\'192.168.1.256\'):', has_ip_address('192.168.1.256')) +info('has_ip_address(\'127.0.0.1\'):', has_ip_address('127.0.0.1')) diff --git a/deployment/modules/stdlib/tests/has_ip_network.pp b/deployment/modules/stdlib/tests/has_ip_network.pp new file mode 100644 index 000000000..a15d8c011 --- /dev/null +++ b/deployment/modules/stdlib/tests/has_ip_network.pp @@ -0,0 +1,4 @@ +include stdlib +info('has_ip_network(\'127.0.0.0\'):', has_ip_network('127.0.0.0')) +info('has_ip_network(\'128.0.0.0\'):', has_ip_network('128.0.0.0')) + diff --git a/deployment/modules/stdlib/tests/init.pp b/deployment/modules/stdlib/tests/init.pp new file mode 100644 index 000000000..9675d8374 --- /dev/null +++ b/deployment/modules/stdlib/tests/init.pp @@ -0,0 +1 @@ +include stdlib diff --git a/deployment/site.pp b/deployment/site.pp new file mode 100755 index 000000000..66157e0eb --- /dev/null +++ b/deployment/site.pp @@ -0,0 +1,66 @@ +stage { 'pre': + before => Stage['main'], +} + +node default { + # update apt + class { 'apt': + stage => pre + } + + # configure ssh to our liking + include sshd + + # general packages + package { ['git', 'build-essential', 'vim']: + ensure => installed, + } + + # configure mysql + class { '::mysql::server': + root_password => '7FzSCogWAFCt' + } -> mysql::db { 'evap': + user => 'evap', + password => '0Am5dWVSC9kd', + } + + # python environment + package { ['python', 'python-dev', 'python-pip', 'python-imaging', 'python-lxml', 'libxml2-dev', 'libxslt-dev']: + ensure => latest, + require => Package['build-essential'] + } -> class { 'mysql::bindings': + python_enable => True + } -> exec { '/vagrant/requirements.txt': + provider => shell, + command => 'pip --log-file /tmp/pip.log install -r /vagrant/requirements.txt' + } -> file { 'evap-localsettings': + name => '/vagrant/evap/localsettings.py', + source => 'puppet:///modules/evap/localsettings.py' + } -> exec { 'django-syncdb': + provider => shell, + command => 'python manage.py syncdb --noinput --migrate', + cwd => '/vagrant' + } -> exec { 'django-collectstatic': + provider => shell, + command => 'python manage.py collectstatic --noinput', + cwd => '/vagrant' + } + + # apache environment + class { 'apache': + default_vhost => false + } + class { 'apache::mod::wsgi': + } + apache::vhost { 'evap': + default_vhost => true, + vhost_name => '*', + port => '80', + docroot => '/vagrant/evap/staticfiles', + aliases => [ { alias => '/static', path => '/vagrant/evap/staticfiles' } ], + wsgi_daemon_process => 'wsgi', + wsgi_daemon_process_options => { processes => '2', threads => '15', display-name => '%{GROUP}' }, + wsgi_process_group => 'wsgi', + wsgi_script_aliases => { '/' => '/vagrant/handler.wsgi' } + } +}