]> git-server-git.apps.pok.os.sepia.ceph.com Git - cephmetrics.git/commitdiff
ansible: Work with old Django versions
authorZack Cerza <zack@redhat.com>
Thu, 26 Oct 2017 19:04:09 +0000 (13:04 -0600)
committerZack Cerza <zack@redhat.com>
Fri, 27 Oct 2017 15:49:53 +0000 (09:49 -0600)
Signed-off-by: Zack Cerza <zack@redhat.com>
ansible/roles/ceph-grafana/tasks/configure_graphite_web.yml

index dc07a9289fa7a5a4a8a6cd195c51fc20aceca7dd..1679d5a7ec3872d9f3d1ee0cc3f81b945c51bbd5 100644 (file)
@@ -1,6 +1,18 @@
 ---
+# Older versions of Django use the 'syncdb' method for DB creation/migration.
+# Newer versions use 'migrate' but still have 'syncdb' available and
+# deprecated. We should be able to auto-discover the correct method.
+- name: Determine how to initialize Django DB
+  command: django-admin --help
+  register: django_cmd
+  no_log: true
+
+- name: Set django_init_method
+  set_fact:
+    django_init_method: "{% if 'migrate' in django_cmd.stdout_lines|map('trim')|list %}migrate{% else %}syncdb{% endif %}"
+
 - name: Create Graphite DB tables
-  command: /usr/bin/graphite-manage migrate --noinput
+  command: "/usr/bin/graphite-manage {{ django_init_method }} --noinput"
   become_user: "{{ graphite.unix_user[ansible_pkg_mgr] }}"
   register: migrate_cmd
   failed_when: migrate_cmd.rc != 0 and 'table "django_content_type" already exists' not in migrate_cmd.stderr
@@ -8,7 +20,9 @@
 - name: Run Graphite migrations if necessary
   command: /usr/bin/graphite-manage migrate --noinput --fake-initial
   become_user: "{{ graphite.unix_user[ansible_pkg_mgr] }}"
-  when: migrate_cmd.rc != 0
+  when:
+    - django_init_method == 'migrate'
+    - migrate_cmd.rc != 0
 
 - name: Build Graphite index
   command: "{{ graphite.build_index[ansible_pkg_mgr] }}"