Module: Formatron::CloudFormation::Scripts
- Defined in:
- lib/formatron/cloud_formation/scripts.rb
Overview
Generates scripts for setting up instances with CloudFormation init rubocop:disable Metrics/ModuleLength
Class Method Summary collapse
-
.chef_server(username:, first_name:, last_name:, email:, password:, organization_short_name:, organization_full_name:, bucket:, user_pem_key:, organization_pem_key:, kms_key:, chef_server_version:, ssl_cert_key:, ssl_key_key:, cookbooks_bucket:) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/ParameterLists.
- .linux_common(sub_domain:, hosted_zone_name:) ⇒ Object
-
.nat(cidr:) ⇒ Object
rubocop:disable Metrics/MethodLength.
-
.windows_administrator(name:, password:) ⇒ Object
rubocop:disable Metrics/MethodLength.
- .windows_common(sub_domain:, hosted_zone_name:) ⇒ Object
-
.windows_signal(wait_condition_handle:) ⇒ Object
rubocop:disable Metrics/MethodLength.
Class Method Details
.chef_server(username:, first_name:, last_name:, email:, password:, organization_short_name:, organization_full_name:, bucket:, user_pem_key:, organization_pem_key:, kms_key:, chef_server_version:, ssl_cert_key:, ssl_key_key:, cookbooks_bucket:) ⇒ Object
rubocop:disable Metrics/MethodLength rubocop:disable Metrics/ParameterLists
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/formatron/cloud_formation/scripts.rb', line 115 def self.chef_server( username:, first_name:, last_name:, email:, password:, organization_short_name:, organization_full_name:, bucket:, user_pem_key:, organization_pem_key:, kms_key:, chef_server_version:, ssl_cert_key:, ssl_key_key:, cookbooks_bucket: ) # rubocop:disable Metrics/LineLength " #!/bin/bash -v\n\n set -e\n\n export HOME=/root\n export PATH=$PATH:/usr/local/sbin/\n export PATH=$PATH:/usr/sbin/\n export PATH=$PATH:/sbin\n\n apt-get -y update\n apt-get -y install wget ntp cron git libfreetype6 libpng3 python-pip\n pip install awscli\n\n mkdir -p $HOME/.aws\n cat << EOF > $HOME/.aws/config\n [default]\n s3 =\n signature_version = s3v4\n region = ${REGION}\n EOF\n\n mkdir -p /etc/opscode/chef-server.rb.d\n\n cat << EOF > /etc/opscode/chef-server.rb\n Dir[File.dirname(__FILE__) + '/chef-server.rb.d/*.rb'].each do |file|\n self.instance_eval File.read(file), file\n end\n EOF\n\n cat << EOF > /etc/opscode/chef-server.rb.d/s3_cookbooks_bucket.rb\n bookshelf['enable'] = false\n bookshelf['external_url'] = 'https://s3-${REGION}.amazonaws.com'\n bookshelf['vip'] = 's3-${REGION}.amazonaws.com'\n bookshelf['access_key_id'] = '${ACCESS_KEY_ID}'\n bookshelf['secret_access_key'] = '${SECRET_ACCESS_KEY}'\n opscode_erchef['s3_bucket'] = '\#{cookbooks_bucket}'\n EOF\n\n cat << EOF > /etc/opscode/chef-server.rb.d/ssl_certificate.rb\n nginx['ssl_certificate'] = '/etc/nginx/ssl/chef.crt'\n nginx['ssl_certificate_key'] = '/etc/nginx/ssl/chef.key'\n EOF\n\n mkdir -p /etc/nginx/ssl\n aws s3api get-object --bucket \#{bucket} --key \#{ssl_cert_key} /etc/nginx/ssl/chef.crt\n aws s3api get-object --bucket \#{bucket} --key \#{ssl_key_key} /etc/nginx/ssl/chef.key\n\n wget -O /tmp/chef-server-core.deb https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/trusty/chef-server-core_\#{chef_server_version}_amd64.deb\n dpkg -i /tmp/chef-server-core.deb\n\n chef-server-ctl reconfigure >> /var/log/chef-install.log\n chef-server-ctl user-create \#{username} \#{first_name} \#{last_name} \#{email} \#{password} --filename $HOME/user.pem >> /var/log/chef-install.log\n chef-server-ctl org-create \#{organization_short_name} \"\#{organization_full_name}\" --association_user \#{username} --filename $HOME/organization.pem >> /var/log/chef-install.log\n\n chef-server-ctl install opscode-manage >> /var/log/chef-install.log\n chef-server-ctl reconfigure >> /var/log/chef-install.log\n opscode-manage-ctl reconfigure >> /var/log/chef-install.log\n\n chef-server-ctl install opscode-push-jobs-server >> /var/log/chef-install.log\n chef-server-ctl reconfigure >> /var/log/chef-install.log\n opscode-push-jobs-server-ctl reconfigure >> /var/log/chef-install.log\n\n chef-server-ctl install opscode-reporting >> /var/log/chef-install.log\n chef-server-ctl reconfigure >> /var/log/chef-install.log\n opscode-reporting-ctl reconfigure >> /var/log/chef-install.log\n\n aws s3api put-object --bucket \#{bucket} --key \#{user_pem_key} --body $HOME/user.pem --ssekms-key-id \#{kms_key} --server-side-encryption aws:kms\n aws s3api put-object --bucket \#{bucket} --key \#{organization_pem_key} --body $HOME/organization.pem --ssekms-key-id \#{kms_key} --server-side-encryption aws:kms\n EOH\n # rubocop:enable Metrics/LineLength\nend\n".gsub(/^ {10}/, '') |
.linux_common(sub_domain:, hosted_zone_name:) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/formatron/cloud_formation/scripts.rb', line 6 def self.linux_common(sub_domain:, hosted_zone_name:) # rubocop:disable Metrics/LineLength " #/bin/bash -v\n set -e\n SHORTNAME=\#{sub_domain}\n PUBLIC_DNS=${SHORTNAME}.\#{hosted_zone_name}\n PRIVATE_IPV4=`(curl http://169.254.169.254/latest/meta-data/local-ipv4)`\n hostname $SHORTNAME\n echo $PUBLIC_DNS | tee /etc/hostname\n echo \"$PRIVATE_IPV4 $PUBLIC_DNS $SHORTNAME\" >> /etc/hosts\n EOH\n # rubocop:enable Metrics/LineLength\nend\n".gsub(/^ {10}/, '') |
.nat(cidr:) ⇒ Object
rubocop:disable Metrics/MethodLength
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/formatron/cloud_formation/scripts.rb', line 91 def self.nat(cidr:) # rubocop:disable Metrics/LineLength " #/bin/bash -v\n set -e\n if ! grep --quiet '^net.ipv4.ip_forward=1$' /etc/sysctl.conf; then\n sed -i '/^#net.ipv4.ip_forward=1$/c\\\\net.ipv4.ip_forward=1' /etc/sysctl.conf\n sysctl -p /etc/sysctl.conf\n fi\n iptables -t nat -A POSTROUTING -o eth0 -s \#{cidr} -j MASQUERADE\n iptables-save > /etc/iptables.rules\n cat << EOF > /etc/network/if-pre-up.d/iptablesload\n #!/bin/sh\n iptables-restore < /etc/iptables.rules\n exit 0\n EOF\n chmod +x /etc/network/if-pre-up.d/iptablesload\n EOH\n # rubocop:enable Metrics/LineLength\nend\n".gsub(/^ {10}/, '') |
.windows_administrator(name:, password:) ⇒ Object
rubocop:disable Metrics/MethodLength
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/formatron/cloud_formation/scripts.rb', line 32 def self.windows_administrator(name:, password:) # rubocop:disable Metrics/LineLength " $newAdminName = '\#{name}'\n $adminPassword = '\#{password}'\n\n # disable password policy\n secedit /export /cfg c:\\\\secpol.cfg\n (gc C:\\\\secpol.cfg).replace(\"PasswordComplexity = 1\", \"PasswordComplexity = 0\") | Out-File C:\\\\secpol.cfg\n secedit /configure /db c:\\\\windows\\\\security\\\\local.sdb /cfg c:\\\\secpol.cfg /areas SECURITYPOLICY\n rm -force c:\\\\secpol.cfg -confirm:$false\n\n # find the local administrator user\n $computerName = $env:COMPUTERNAME\n $computer = [ADSI] \"WinNT://$computerName,Computer\"\n foreach ( $childObject in $computer.Children ) {\n # Skip objects that are not users.\n if ( $childObject.Class -ne \"User\" ) {\n continue\n }\n $type = \"System.Security.Principal.SecurityIdentifier\"\n $childObjectSID = new-object $type($childObject.objectSid[0],0)\n if ( $childObjectSID.Value.EndsWith(\"-500\") ) {\n $adminName = $childObject.Name[0]\n\n # set the new password\n $adminUser = [ADSI] \"WinNT://$computerName/$adminName,User\"\n $adminUser.SetPassword($adminPassword)\n\n # set the new name\n $user = Get-WMIObject Win32_UserAccount -Filter \"Name='$adminName'\"\n $result = $user.Rename($newAdminName)\n\n break\n }\n }\n EOH\n # rubocop:enable Metrics/LineLength\nend\n".gsub(/^ {10}/, '') |
.windows_common(sub_domain:, hosted_zone_name:) ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'lib/formatron/cloud_formation/scripts.rb', line 21 def self.windows_common(sub_domain:, hosted_zone_name:) # rubocop:disable Metrics/LineLength " wmic computersystem where name=\"%COMPUTERNAME%\" call rename name=\"\#{sub_domain}\"\n REG ADD HKLM\\\\SYSTEM\\\\CurrentControlSet\\\\services\\\\Tcpip\\\\Parameters /v Domain /t REG_SZ /d \#{hosted_zone_name} /f\n shutdown.exe /r /t 00\n EOH\n # rubocop:enable Metrics/LineLength\nend\n".gsub(/^ {10}/, '') |
.windows_signal(wait_condition_handle:) ⇒ Object
rubocop:disable Metrics/MethodLength
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/formatron/cloud_formation/scripts.rb', line 74 def self.windows_signal(wait_condition_handle:) { 'Fn::Join' => [ '', [ 'cfn-signal.exe -e 0 ', { 'Fn::Base64' => { Ref: wait_condition_handle } } ] ] } end |