-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webplatform/ops#73 Creating task scripts
use-case: Set in place a system where we can use salt to achieve maintenance tasks without writing secrets in target machine, but instead use the pillar system. First task: send offsite (to DreamObjects) our backups
- Loading branch information
Showing
11 changed files
with
96 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,6 @@ | |
|
||
include: | ||
- backup.db | ||
- webplatform.swift-dreamobjects | ||
- mysql.server | ||
|
||
# | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{%- set endpoint = salt['pillar.get']('accounts:swift:dreamhost:endpoint') -%} | ||
{%- set key = salt['pillar.get']('dreamobjects:discourse:key', 'missing_key') -%} | ||
{%- set secret = salt['pillar.get']('dreamobjects:discourse:secret', 'missing_secret') -%} | ||
{%- set bucket = salt['pillar.get']('dreamobjects:discourse:bucket', 'missing_bucket') -%} | ||
{%- set dir = salt['pillar.get']('dreamobjects:discourse:dir', 'missing_dir') -%} | ||
|
||
/usr/local/sbin/dreamobjects_uploader.sh: | ||
cmd.wait: | ||
- onlyif: test -d {{ dir }} | ||
- cwd: {{ dir }} | ||
- stateful: True | ||
- env: | ||
- 'ST_KEY': '{{ secret }}' | ||
- 'ST_USER': '{{ key }}' | ||
- 'ST_AUTH': '{{ endpoint }}' | ||
- 'SYNC_DIR': '{{ dir }}' | ||
- 'SYNC_BUCKET': '{{ bucket }}' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
include: | ||
- tasks.dreamobjects_upload.apps.discourse | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{%- set rolesDict = salt['grains.get']('roles') -%} | ||
|
||
|
||
include: | ||
{%- if rolesDict|length() >= 1 %} | ||
{% for roleName in rolesDict %} | ||
- tasks.dreamobjects_upload.{{ roleName }} | ||
{% endfor %} | ||
{% endif %} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/bash | ||
|
||
set -e | ||
|
||
if [ ! -d "${SYNC_DIR}" ]; then | ||
echo "Directory ${SYNC_DIR} doesnt exist" | ||
exit 1 | ||
fi | ||
echo "Directory will be ${SYNC_DIR}" | ||
|
||
|
||
if [ -z "${SYNC_BUCKET}" ]; then | ||
echo "Required environment variable SYNC_BUCKET missing" | ||
exit 1 | ||
fi | ||
echo "Bucket will be ${SYNC_BUCKET}" | ||
|
||
|
||
if [ -z "${ST_AUTH}" ]; then | ||
echo "Required environment variable ST_AUTH missing" | ||
exit 1 | ||
fi | ||
echo "Endpoint will be ${ST_AUTH}" | ||
|
||
|
||
if [ -z "${ST_KEY}" ]; then | ||
echo "Required environment variable ST_KEY missing" | ||
exit 1 | ||
fi | ||
echo "Key will be ${ST_KEY}" | ||
|
||
|
||
if [ -z "${ST_USER}" ]; then | ||
echo "Required environment variable ST_USER missing" | ||
exit 1 | ||
fi | ||
echo "User will be ${ST_USER}" | ||
|
||
|
||
BIN=`which swift` | ||
|
||
if [ -z "${BIN}" ]; then | ||
echo "Python Swift client (python-swiftclient) not found" | ||
exit 1 | ||
fi | ||
|
||
cd ${SYNC_DIR} | ||
find ${SYNC_DIR} -type f -mtime -1 | sed 's/^\.\///' | sort -u > dreamobjects_upload.${SYNC_BUCKET}.list | ||
while read FILE; do swift upload ${SYNC_BUCKET} $FILE --changed; done < dreamobjects_upload.${SYNC_BUCKET}.list | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters