forked from eduNEXT/configuration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopulate_configuration_model.yml
59 lines (58 loc) · 1.99 KB
/
populate_configuration_model.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
#
# edX Configuration
#
# github: https://github.com/edx/configuration
# wiki: https://openedx.atlassian.net/wiki/display/OpenOPS
# code style: https://openedx.atlassian.net/wiki/display/OpenOPS/Ansible+Code+Conventions
# license: https://github.com/edx/configuration/blob/master/LICENSE.TXT
#
# Usage: ansible-playbook -i lms-host-1, ./populate_configuration_model.yml -e "file=/path/to/json/file" -e "user=username"
#
# Overview:
# This executes the "populate_model" management command to populate a ConfigurationModel with
# data from the supplied JSON file.
#
# The username of an existing user must be specified to indicate who is performing the operation.
#
# JSON file format should be:
#
# { "model": "config_models.ExampleConfigurationModel",
# "data":
# [
# { "enabled": True,
# "color": "black"
# ...
# },
# { "enabled": False,
# "color": "yellow"
# ...
# },
# ...
# ]
# }
#
- hosts: all
vars:
python_path: /edx/bin/python.edxapp
manage_path: /edx/bin/manage.edxapp
lms_env: /edx/app/edxapp/edxapp_env
become_user: www-data
become: true
tasks:
- name: Create a temp directory
shell: mktemp -d /tmp/ansible_xblock_config.XXXXX
register: xblock_config_temp_directory
- name: Copy config file to remote server
copy:
src: "{{ file }}"
dest: "{{ xblock_config_temp_directory.stdout }}/{{ file | basename }}"
register: xblock_config_file
- name: Manage xblock configurations
shell: ". {{lms_env}} && {{ python_path }} {{ manage_path }} lms --settings=production populate_model -f {{ xblock_config_file.dest | quote }} -u {{ user }}"
register: command_result
changed_when: "'Import complete, 0 new entries created' not in command_result.stdout"
- debug: msg="{{ command_result.stdout }}"
- name: Clean up tempdir
file:
path: "{{ xblock_config_temp_directory.stdout }}"
state: absent