Skip to content

Commit

Permalink
Merge pull request #2 from devjatkin/superuser
Browse files Browse the repository at this point in the history
Superuser managment using manage.py
  • Loading branch information
nsg committed Feb 7, 2015
2 parents 24ede41 + 9a5b54a commit 39f946b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 581 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Role Variables
* `graphite_admin_last_name`, default: `""`
* `graphite_admin_last_login`, default: `"2014-07-21T10:11:17.464"`
* `graphite_admin_username`, default: `"admin"`
* `graphite_admin_password_hash`, is set to `admin` by default: `"pbkdf2_sha256$12000$kVwkSbtyrM2q$UiFHRnWZXQSLLv658mx7K+Fym6F5L0dJUh8iNHnFigk="`
* `graphite_admin_password`, default: `"admin"`

The default is "60s:1d" (1 day data), this will keep data for 5 years.
If you log a lot of data, you may need to restrict this to a shorter time.
Expand Down
4 changes: 2 additions & 2 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ graphite_secret_key: UNSAFE_DEFAULT
graphite_time_zone: "America/Los_Angeles"

graphite_admin_date_joined: "2014-07-21T10:11:17.464"
graphite_admin_email: "root@localhost"
graphite_admin_email: "root@localhost.localhdomain"
graphite_admin_first_name: ""
graphite_admin_last_name: ""
graphite_admin_last_login: "2014-07-21T10:11:17.464"
graphite_admin_username: "admin"
graphite_admin_password_hash: "pbkdf2_sha256$12000$kVwkSbtyrM2q$UiFHRnWZXQSLLv658mx7K+Fym6F5L0dJUh8iNHnFigk=" # admin
graphite_admin_password: "admin"

# The default is "60s:1d" (1 day data), this will keep data for 5 years.
# If you log a lot of data, you may need to restrict this to a shorter time.
Expand Down
2 changes: 1 addition & 1 deletion tasks/Debian.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
template: src=debian_carbon_service.j2 dest=/etc/init.d/carbon-cache
notify: restart carbon-cache

- name: Check the install scripts perms.
- name: Check the install scripts perms
file: path=/etc/init.d/{{ item }} mode=0755 owner=root group=root
with_items:
- carbon-cache
Expand Down
2 changes: 1 addition & 1 deletion tasks/RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
template: src=redhat_uwsgi_service.j2 dest=/etc/init.d/uwsgi
notify: restart uwsgi

- name: Check the install scripts perms.
- name: Check the install scripts perms
file: path=/etc/init.d/{{ item }} mode=0755 owner=root group=root
with_items:
- carbon-cache
Expand Down
43 changes: 27 additions & 16 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
notify: restart carbon-cache

- name: Inspect graphite db
command: sudo -u {{ graphite_user }} python {{ graphite_install_path }}/webapp/graphite/manage.py inspectdb
command: python {{ graphite_install_path }}/webapp/graphite/manage.py inspectdb
sudo_user: "{{ graphite_user }}"
register: result
changed_when: False

Expand All @@ -54,23 +55,33 @@
changed_when: False

- name: Sync/create database
command: sudo -u {{ graphite_user }} python {{ graphite_install_path }}/webapp/graphite/manage.py syncdb --noinput
command: python {{ graphite_install_path }}/webapp/graphite/manage.py syncdb --noinput
sudo_user: "{{ graphite_user }}"
when: result.stdout.find("AccountMygraph") == -1

- name: Install database (1/3) Upload import data
template: src=dbdump.json.j2 dest=/tmp/graphite_dbdump.json
when: result.stdout.find("AccountMygraph") == -1
notify: restart carbon-cache

- name: Install database (2/3) Install data
command: sudo -u {{ graphite_user }} python {{ graphite_install_path }}/webapp/graphite/manage.py loaddata /tmp/graphite_dbdump.json
when: result.stdout.find("AccountMygraph") == -1
notify: restart carbon-cache

- name: Install database (3/3) Remove temp file
file: path=/tmp/graphite_dbdump.json state=absent
when: result.stdout.find("AccountMygraph") == -1
notify: restart carbon-cache
- name: Create superuser account
command: python {{ graphite_install_path }}/webapp/graphite/manage.py createsuperuser --username={{ graphite_admin_username }} --email={{ graphite_admin_email }} --noinput
sudo_user: "{{ graphite_user }}"
register: superuser_created
args:
creates: "{{ graphite_install_path }}/webapp/graphite/.superuser_created"

- name: Prepare to set up superuser password
template: src=createsuperuser.py.j2 dest=/tmp/createsuperuser.py
when: superuser_created|changed
register: debug2

- name: Set superuser password
shell: "python {{ graphite_install_path }}/webapp/graphite/manage.py shell < /tmp/createsuperuser.py"
sudo_user: "{{ graphite_user }}"
when: superuser_created|changed

- name: Create lock file
file: path="{{ graphite_install_path }}/webapp/graphite/.superuser_created" state=touch
when: superuser_created|changed

- name: Remove temp file
file: path=/tmp/createsuperuser.py state=absent

- name: Make sure services are running
service: name={{ item }} state=started
Expand Down
5 changes: 5 additions & 0 deletions templates/createsuperuser.py.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.contrib.auth.models import User

u = User.objects.get(username__exact='{{ graphite_admin_username }}')
u.set_password('{{ graphite_admin_password }}')
u.save()
Loading

0 comments on commit 39f946b

Please sign in to comment.