forked from compmodels/jupyterhub-deploy
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
95 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
--- | ||
- hosts: jupyterhub_host | ||
vars_files: | ||
- ['secrets.yml', 'secrets.vault.yml'] | ||
- ['users.yml', 'users.vault.yml'] | ||
- ['vars.local.yml', 'vars.yml'] | ||
|
||
vars_prompt: | ||
assignment: "Which assignment?" | ||
|
||
tasks: | ||
- name: collect submissions | ||
collect_submissions: | ||
src: '.nbgrader/submissions/{{ assignment }}.tar.gz' | ||
dest: '/srv/assignments/submissions.tar.gz' | ||
users: "{{ instructors }}" | ||
overwrite: yes | ||
sudo: yes | ||
|
||
- name: download submissions | ||
fetch: | ||
src: '/srv/assignments/submissions.tar.gz' | ||
dest: '{{ assignment_path }}/{{ assignment }}/submissions.tar.gz' | ||
flat: yes | ||
fail_on_missing: yes | ||
sudo: yes |
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,52 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
|
||
import os | ||
import tarfile | ||
|
||
def main(): | ||
module = AnsibleModule( | ||
argument_spec={ | ||
'src': dict(required=True), | ||
'dest': dict(required=True), | ||
'users': dict(required=True, type='list'), | ||
'overwrite': dict(default=False, type='bool') | ||
} | ||
) | ||
|
||
src = module.params["src"] | ||
dest = module.params["dest"] | ||
users = module.params["users"] | ||
overwrite = module.params["overwrite"] | ||
|
||
if os.path.exists(dest) and not overwrite: | ||
module.exit_json(changed=False) | ||
elif os.path.exists(dest): | ||
os.remove(dest) | ||
|
||
tf = tarfile.open(dest, 'w:gz') | ||
|
||
for user in users: | ||
homedir = os.path.abspath('/home/{}'.format(user)) | ||
if not homedir.startswith('/home/'): | ||
tf.close() | ||
os.remove(dest) | ||
module.fail_json(msg="Home directory is invalid: {}".format(homedir)) | ||
if not os.path.exists(homedir): | ||
tf.close() | ||
os.remove(dest) | ||
module.fail_json(msg="Home directory does not exist: {}".format(homedir)) | ||
|
||
pth = os.path.join(homedir, src) | ||
if not os.path.exists(pth): | ||
continue | ||
|
||
tf.add(pth, arcname="{}.tar.gz".format(user)) | ||
|
||
tf.close() | ||
|
||
module.exit_json(changed=True) | ||
|
||
|
||
from ansible.module_utils.basic import * | ||
main() |
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,17 @@ | ||
#!/bin/bash | ||
|
||
ROOT=$(dirname $0)/.. | ||
|
||
if [ ! -e ${ROOT}//inventory ]; then | ||
echo "Please create an inventory file with your hosts." | ||
echo " cp inventory.example inventory" | ||
exit 1 | ||
fi | ||
|
||
if [ -e ${ROOT}/secrets.yml ]; then | ||
VAULT_ARG= | ||
else | ||
VAULT_ARG=--ask-vault-pass | ||
fi | ||
|
||
exec ansible-playbook ${ROOT}/download.yml -i ${ROOT}/inventory ${VAULT_ARG} $@ |