Skip to content

Instantly share code, notes, and snippets.

@pratikmallya
Last active August 29, 2015 14:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pratikmallya/7fdc3eed6f9d83f1c4f3 to your computer and use it in GitHub Desktop.
Save pratikmallya/7fdc3eed6f9d83f1c4f3 to your computer and use it in GitHub Desktop.
heat_template_version: 2013-05-23
description: |
This is a Heat template to deploy a single Linux server running Drupal.
parameter_groups:
- label: Server Settings
parameters:
- image
- flavor
- label: Drupal Settings
parameters:
- domain
- username
- label: rax-dev-params
parameters:
- server_hostname
- database_name
parameters:
# Server settings
server_hostname:
label: Server Name
description: Hostname to use for the server that's built.
type: string
default: Drupal
constraints:
- length:
min: 1
max: 64
- allowed_pattern: "^[a-zA-Z][a-zA-Z0-9-]*$"
description: |
Must begin with a letter and contain only alphanumeric characters.
image:
label: Operating System
description: |
Required: Server image used for all servers that are created as a part of
this deployment.
type: string
default: Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
constraints:
- allowed_values:
- Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
description: Must be a supported operating system.
flavor:
label: Server Size
description: |
Required: Rackspace Cloud Server flavor to use. The size is based on the
amount of RAM for the provisioned server.
type: string
default: 4 GB General Purpose v1
constraints:
- allowed_values:
- 1 GB General Purpose v1
- 2 GB General Purpose v1
- 4 GB General Purpose v1
- 8 GB General Purpose v1
- 15 GB I/O v1
- 30 GB I/O v1
- 1GB Standard Instance
- 2GB Standard Instance
- 4GB Standard Instance
- 8GB Standard Instance
- 15GB Standard Instance
- 30GB Standard Instance
description: |
Must be a valid Rackspace Cloud Server flavor for the region you have
selected to deploy into.
# Durpal settings
domain:
label: Site Domain
description: Domain to be used with the Drupal site
type: string
default: "example.com"
constraints:
- allowed_pattern: "^[a-zA-Z0-9.-]{1,255}.[a-zA-Z]{2,15}$"
description: Must be a valid domain name
# Database and system user configuration
database_name:
label: Database Name
description: Drupal database name
type: string
default: drupal
constraints:
- allowed_pattern: "^[0-9a-zA-Z$_]{1,64}$"
description: |
Maximum length of 64 characters, may only contain letters, numbers, and
underscores.
username:
label: Username
description: "Username for the Drupal admin login"
type: string
default: admin
constraints:
- allowed_pattern: "^(.){1,16}$"
description: |
Must be shorter than 16 characters, this is due to MySQL's maximum
username length.
resources:
wait_condition:
type: OS::Heat::SwiftSignal
properties:
handle: { get_resource: wait_condition_handle }
timeout: 1800
wait_condition_handle:
type: OS::Heat::SwiftSignalHandle
# Random password generation
database_password:
type: "OS::Heat::RandomString"
properties:
length: 16
sequence: lettersdigits
drupal_password:
type: "OS::Heat::RandomString"
properties:
length: 16
sequence: lettersdigits
mysql_root_password:
type: "OS::Heat::RandomString"
properties:
length: 16
sequence: lettersdigits
# SSH KEYS
ssh_key:
type: "OS::Nova::KeyPair"
properties:
name: { get_param: "OS::stack_id" }
save_private_key: true
# Server resources
drupal_server:
type: "OS::Nova::Server"
properties:
name: { get_param: server_hostname }
flavor: { get_param: flavor }
image: { get_param: image }
key_name: { get_resource: ssh_key }
metadata:
rax-heat: { get_param: "OS::stack_id" }
config_drive: "true"
user_data_format: RAW
user_data:
str_replace:
template: |
#cloud-config
package_update: true
packages:
- git
write_files:
# Set salt-minion to only use local resources
- path: /etc/salt/minion.d/local.conf
permissions: '0644'
content: |
file_client: local
mysql.default_file: '/etc/mysql/debian.cnf'
# Write out Pillar top.sls
- path: /srv/pillar/top.sls
permissions: '0600'
content: |
base:
'*':
- localhost
# Write out State top.sls
- path: /srv/salt/top.sls
permissions: '0644'
content: |
base:
'*':
- salt-minion
- apache
- composer
- drush
- mysql
- mysql.database
- mysql.user
- mysql.grant
- php
- drupal
- holland
- holland.mysqldump
# Example Pillar Data using %value% notation
# See example pillar data from states repository.
- path: /srv/pillar/localhost.sls
permissions: '0600'
content: |
apache:
vhosts:
- domain: %domain%
docroot: /var/www/%domain%
drupal:
domain: %domain%
admin_user: %username%
admin_pass: %drupal_password%
db_host: localhost
db_name: %database_name%
db_user: drupal_user
db_pass: %database_password%
holland:
backupsets:
default:
"holland:backup":
plugin: mysqldump
backups-to-keep: 7
auto-purge-failures: yes
purge-policy: after-backup
estimated-size-factor: 1.0
mysqldump:
file-per-database: yes
compression:
method: gzip
inline: yes
level: 1
"mysql:client":
user: root
password: %mysql_root_password%
mysql:
root_password: %mysql_root_password%
mysql-database:
name: %database_name%
mysql-grant:
user: drupal_user
database: %database_name%
host: localhost
grants: all privileges
mysql-user:
user: drupal_user
pass: %database_password%
host: localhost
# Salt Bootstrap script
- path: /tmp/heat/salt_run.sh
permissions: '0500'
content: |
#!/bin/bash
# Install salt-minion using Salt Bootstrap
curl -L https://bootstrap.saltstack.com | sudo sh -s --
salt-minion --versions
# Clone down States
mkdir -p /tmp/heat/states
git clone https://github.com/rackspace-orchestration-templates/salt-states.git /tmp/heat/states
cp -nr /tmp/heat/states/* /srv/salt/
# Run local highstate
salt-call --local state.highstate
# Open and Enable ufw
ufw allow 443
ufw allow 80
ufw allow 22
ufw --force enable
wc_notify --data-binary '{"status": "SUCCESS"}'
runcmd:
- /tmp/heat/salt_run.sh
params:
wc_notify: { get_attr: ['wait_condition_handle', 'curl_cli'] }
"%mysql_root_password%": { get_attr: [mysql_root_password, value] }
"%drupal_password%": { get_attr: [drupal_password, value] }
"%database_password%": { get_attr: [database_password, value] }
"%domain%": { get_param: domain }
"%username%": { get_param: username }
"%database_name%": { get_param: database_name }
outputs:
private_key:
description: SSH Private Key
value: { get_attr: [ssh_key, private_key] }
server_ip:
description: Server IP
value: { get_attr: [drupal_server, accessIPv4] }
drupal_url:
description: Drupal URL
value:
str_replace:
template: "http://%ip%"
params:
"%ip%": { get_attr: [drupal_server, accessIPv4] }
drupal_user:
description: Drupal User
value: { get_param: username }
drupal_password:
description: Drupal Password
value: { get_attr: [drupal_password, value] }
mysql_root_password:
description: MySQL Root Password
value: { get_attr: [mysql_root_password, value] }
heat_template_version: 2013-05-23
description: |
This is a Heat template to deploy a single Linux server running Drupal.
parameter_groups:
- label: Server Settings
parameters:
- image
- flavor
- label: Drupal Settings
parameters:
- domain
- username
- label: rax-dev-params
parameters:
- server_hostname
- database_name
parameters:
# Server settings
server_hostname:
label: Server Name
description: Hostname to use for the server that's built.
type: string
default: Drupal
constraints:
- length:
min: 1
max: 64
- allowed_pattern: "^[a-zA-Z][a-zA-Z0-9-]*$"
description: |
Must begin with a letter and contain only alphanumeric characters.
image:
label: Operating System
description: |
Required: Server image used for all servers that are created as a part of
this deployment.
type: string
default: Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
constraints:
- allowed_values:
- Ubuntu 14.04 LTS (Trusty Tahr) (PVHVM)
description: Must be a supported operating system.
flavor:
label: Server Size
description: |
Required: Rackspace Cloud Server flavor to use. The size is based on the
amount of RAM for the provisioned server.
type: string
default: 4 GB General Purpose v1
constraints:
- allowed_values:
- 1 GB General Purpose v1
- 2 GB General Purpose v1
- 4 GB General Purpose v1
- 8 GB General Purpose v1
- 15 GB I/O v1
- 30 GB I/O v1
- 1GB Standard Instance
- 2GB Standard Instance
- 4GB Standard Instance
- 8GB Standard Instance
- 15GB Standard Instance
- 30GB Standard Instance
description: |
Must be a valid Rackspace Cloud Server flavor for the region you have
selected to deploy into.
# Durpal settings
domain:
label: Site Domain
description: Domain to be used with the Drupal site
type: string
default: "example.com"
constraints:
- allowed_pattern: "^[a-zA-Z0-9.-]{1,255}.[a-zA-Z]{2,15}$"
description: Must be a valid domain name
# Database and system user configuration
database_name:
label: Database Name
description: Drupal database name
type: string
default: drupal
constraints:
- allowed_pattern: "^[0-9a-zA-Z$_]{1,64}$"
description: |
Maximum length of 64 characters, may only contain letters, numbers, and
underscores.
username:
label: Username
description: "Username for the Drupal admin login"
type: string
default: admin
constraints:
- allowed_pattern: "^(.){1,16}$"
description: |
Must be shorter than 16 characters, this is due to MySQL's maximum
username length.
resources:
wait_condition:
type: OS::Heat::SwiftSignal
properties:
handle: { get_resource: wait_condition_handle }
timeout: 1800
wait_condition_handle:
type: OS::Heat::SwiftSignalHandle
# Random password generation
database_password:
type: "OS::Heat::RandomString"
properties:
length: 16
sequence: lettersdigits
drupal_password:
type: "OS::Heat::RandomString"
properties:
length: 16
sequence: lettersdigits
mysql_root_password:
type: "OS::Heat::RandomString"
properties:
length: 16
sequence: lettersdigits
# SSH KEYS
ssh_key:
type: "OS::Nova::KeyPair"
properties:
name: { get_param: "OS::stack_id" }
save_private_key: true
# Server resources
drupal_server:
type: "OS::Nova::Server"
properties:
name: { get_param: server_hostname }
flavor: { get_param: flavor }
image: { get_param: image }
key_name: { get_resource: ssh_key }
metadata:
rax-heat: { get_param: "OS::stack_id" }
config_drive: "true"
user_data_format: RAW
user_data:
str_replace:
template: |
#cloud-config
package_update: true
packages:
- git
write_files:
# Set salt-minion to only use local resources
- path: /etc/salt/minion.d/local.conf
permissions: '0644'
content: |
file_client: local
mysql.default_file: '/etc/mysql/debian.cnf'
# Write out Pillar top.sls
- path: /srv/pillar/top.sls
permissions: '0600'
content: |
base:
'*':
- localhost
# Write out State top.sls
- path: /srv/salt/top.sls
permissions: '0644'
content: |
base:
'*':
- salt-minion
- apache
- composer
- drush
- mysql
- mysql.database
- mysql.user
- mysql.grant
- php
- drupal
- holland
- holland.mysqldump
# Example Pillar Data using %value% notation
# See example pillar data from states repository.
- path: /srv/pillar/localhost.sls
permissions: '0600'
content: |
apache:
vhosts:
- domain: %domain%
docroot: /var/www/%domain%
drupal:
domain: %domain%
admin_user: %username%
admin_pass: %drupal_password%
db_host: localhost
db_name: %database_name%
db_user: drupal_user
db_pass: %database_password%
holland:
backupsets:
default:
"holland:backup":
plugin: mysqldump
backups-to-keep: 7
auto-purge-failures: yes
purge-policy: after-backup
estimated-size-factor: 1.0
mysqldump:
file-per-database: yes
compression:
method: gzip
inline: yes
level: 1
"mysql:client":
user: root
password: %mysql_root_password%
mysql:
root_password: %mysql_root_password%
mysql-database:
name: %database_name%
mysql-grant:
user: drupal_user
database: %database_name%
host: localhost
grants: all privileges
mysql-user:
user: drupal_user
pass: %database_password%
host: localhost
# Salt Bootstrap script
- path: /tmp/heat/salt_run.sh
permissions: '0500'
content: |
#!/bin/bash
# Install salt-minion using Salt Bootstrap
curl -L https://bootstrap.saltstack.com | sudo sh -s --
salt-minion --versions
# Clone down States
mkdir -p /tmp/heat/states
git clone https://github.com/rackspace-orchestration-templates/salt-states.git /tmp/heat/states
cp -nr /tmp/heat/states/* /srv/salt/
# Run local highstate
salt-call --local state.highstate
# Open and Enable ufw
ufw allow 443
ufw allow 80
ufw allow 22
ufw --force enable
wc_notify --data-binary '{"status": "SUCCESS"}'
runcmd:
- /tmp/heat/salt_run.sh
params:
wc_notify: { get_attr: ['wait_condition_handle', 'curl_cli'] }
"%mysql_root_password%": { get_attr: [mysql_root_password, value] }
"%drupal_password%": { get_attr: [drupal_password, value] }
"%database_password%": { get_attr: [database_password, value] }
"%domain%": { get_param: domain }
"%username%": { get_param: username }
"%database_name%": { get_param: database_name }
outputs:
private_key:
description: SSH Private Key
value: { get_attr: [ssh_key, private_key] }
server_ip:
description: Server IP
value: { get_attr: [drupal_server, accessIPv4] }
drupal_url:
description: Drupal URL
value:
str_replace:
template: "http://%ip%"
params:
"%ip%": { get_attr: [drupal_server, accessIPv4] }
drupal_user:
description: Drupal User
value: { get_param: username }
drupal_password:
description: Drupal Password
value: { get_attr: [drupal_password, value] }
mysql_root_password:
description: MySQL Root Password
value: { get_attr: [mysql_root_password, value] }
service_ip:
value: { get_attr: [drupal_server, networks, private, 0] }
description: App Node Private IP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment