OLD | NEW |
(Empty) | |
| 1 # == Class: adblockplus::web::static |
| 2 # |
| 3 # Manage a simple Nginx-based webserver for static content |
| 4 # that uses a customizable deployment script to e.g. fetch the content |
| 5 # from a repository server (ref. http://hub.eyeo.com/issues/4523) |
| 6 # |
| 7 # === Parameters: |
| 8 # |
| 9 # [*domain*] |
| 10 # The domain name for the website. |
| 11 # |
| 12 # [*ssl_certificate*] |
| 13 # The name of the SSL certificate file within modules/private/files, if any. |
| 14 # Requires a private_key as well. |
| 15 # |
| 16 # [*ssl_private_key*] |
| 17 # The name of the private key file within modules/private/files, if any. |
| 18 # Requires a certificate as well. |
| 19 # |
| 20 # [*ensure*] |
| 21 # Whether to set up the website or not, e.g. "asbsent" or "present". |
| 22 # |
| 23 # [*deploy_user*] |
| 24 # User that will be used to issue commands. |
| 25 # |
| 26 # [*deploy_user_authorized_keys*] |
| 27 # Array of public keys that will have access to ssh commands |
| 28 # |
| 29 # [*hooks*] |
| 30 # Hash of adblockplus::web::static::hook items to set up in this context. |
| 31 # |
| 32 # === Examples: |
| 33 # |
| 34 # class {'adblockplus::web::static': |
| 35 # domain => 'help.eyeo.com', |
| 36 # hooks => { |
| 37 # uname => { |
| 38 # file => { |
| 39 # content => 'uname -a', |
| 40 # }, |
| 41 # }, |
| 42 # uptime => { |
| 43 # file => { |
| 44 # target => '/usr/bin/uptime', |
| 45 # ensure => 'link', |
| 46 # }, |
| 47 # }, |
| 48 # }, |
| 49 # } |
| 50 # |
| 51 class adblockplus::web::static ( |
| 52 $domain, |
| 53 $ssl_certificate = undef, |
| 54 $ssl_private_key = undef, |
| 55 $ensure = 'present', |
| 56 $deploy_user = 'web-deploy', |
| 57 $deploy_user_authorized_keys = [], |
| 58 $hooks = {}, |
| 59 ) { |
| 60 |
| 61 include adblockplus::web |
| 62 include nginx |
| 63 include ssh |
| 64 |
| 65 File { |
| 66 mode => '0755', |
| 67 owner => $deploy_user, |
| 68 group => $deploy_user, |
| 69 } |
| 70 |
| 71 ensure_resource('file', "/var/www/$domain", { |
| 72 ensure => ensure_directory_state($ensure), |
| 73 owner => 'www-data', |
| 74 group => 'www-data', |
| 75 }) |
| 76 |
| 77 ensure_resource('nginx::hostconfig', $title, { |
| 78 content => template('adblockplus/web/static.conf.erb'), |
| 79 certificate => $ssl_certificate, |
| 80 domain => $domain, |
| 81 is_default => true, |
| 82 private_key => $ssl_private_key, |
| 83 log => 'web.access.log', |
| 84 }) |
| 85 |
| 86 $content = [ |
| 87 "Match User ${deploy_user}", |
| 88 'AllowTcpForwarding no', |
| 89 'X11Forwarding no', |
| 90 'AllowAgentForwarding no', |
| 91 'GatewayPorts no', |
| 92 'ForceCommand /usr/local/bin/hooks_wrapper $SSH_ORIGINAL_COMMAND', |
| 93 ] |
| 94 |
| 95 ensure_resource('concat::fragment', 'helpcenter', { |
| 96 content => join($content, "\n\t"), |
| 97 ensure => 'present', |
| 98 target => 'sshd_config', |
| 99 order => '20', |
| 100 }) |
| 101 |
| 102 ensure_resource('adblockplus::user', $deploy_user, { |
| 103 authorized_keys => $deploy_user_authorized_keys, |
| 104 ensure => $ensure, |
| 105 shell => '/bin/bash', |
| 106 groups => ['www-data'], |
| 107 }) |
| 108 |
| 109 $wrapper_path = "/home/${deploy_user}/bin" |
| 110 ensure_resource('file', 'commands_dir', { |
| 111 path => $wrapper_path, |
| 112 ensure => ensure_directory_state($ensure), |
| 113 }) |
| 114 |
| 115 ensure_resource('file', '/usr/local/bin/hooks_wrapper', { |
| 116 ensure => ensure_file_state($ensure), |
| 117 content => template('adblockplus/web/hooks_wrapper.sh.erb'), |
| 118 }) |
| 119 |
| 120 # https://docs.puppet.com/puppet/latest/function.html#createresources |
| 121 create_resources('adblockplus::web::static::hook', $hooks) |
| 122 } |
| 123 |
OLD | NEW |