Skip to content

Commit 39f946b

Browse files
committed
Merge pull request #2 from devjatkin/superuser
Superuser managment using manage.py
2 parents 24ede41 + 9a5b54a commit 39f946b

File tree

7 files changed

+37
-581
lines changed

7 files changed

+37
-581
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Role Variables
3636
* `graphite_admin_last_name`, default: `""`
3737
* `graphite_admin_last_login`, default: `"2014-07-21T10:11:17.464"`
3838
* `graphite_admin_username`, default: `"admin"`
39-
* `graphite_admin_password_hash`, is set to `admin` by default: `"pbkdf2_sha256$12000$kVwkSbtyrM2q$UiFHRnWZXQSLLv658mx7K+Fym6F5L0dJUh8iNHnFigk="`
39+
* `graphite_admin_password`, default: `"admin"`
4040

4141
The default is "60s:1d" (1 day data), this will keep data for 5 years.
4242
If you log a lot of data, you may need to restrict this to a shorter time.

defaults/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ graphite_secret_key: UNSAFE_DEFAULT
55
graphite_time_zone: "America/Los_Angeles"
66

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

1515
# The default is "60s:1d" (1 day data), this will keep data for 5 years.
1616
# If you log a lot of data, you may need to restrict this to a shorter time.

tasks/Debian.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
template: src=debian_carbon_service.j2 dest=/etc/init.d/carbon-cache
2121
notify: restart carbon-cache
2222

23-
- name: Check the install scripts perms.
23+
- name: Check the install scripts perms
2424
file: path=/etc/init.d/{{ item }} mode=0755 owner=root group=root
2525
with_items:
2626
- carbon-cache

tasks/RedHat.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
template: src=redhat_uwsgi_service.j2 dest=/etc/init.d/uwsgi
4040
notify: restart uwsgi
4141

42-
- name: Check the install scripts perms.
42+
- name: Check the install scripts perms
4343
file: path=/etc/init.d/{{ item }} mode=0755 owner=root group=root
4444
with_items:
4545
- carbon-cache

tasks/main.yml

+27-16
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
notify: restart carbon-cache
4545

4646
- name: Inspect graphite db
47-
command: sudo -u {{ graphite_user }} python {{ graphite_install_path }}/webapp/graphite/manage.py inspectdb
47+
command: python {{ graphite_install_path }}/webapp/graphite/manage.py inspectdb
48+
sudo_user: "{{ graphite_user }}"
4849
register: result
4950
changed_when: False
5051

@@ -54,23 +55,33 @@
5455
changed_when: False
5556

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

60-
- name: Install database (1/3) Upload import data
61-
template: src=dbdump.json.j2 dest=/tmp/graphite_dbdump.json
62-
when: result.stdout.find("AccountMygraph") == -1
63-
notify: restart carbon-cache
64-
65-
- name: Install database (2/3) Install data
66-
command: sudo -u {{ graphite_user }} python {{ graphite_install_path }}/webapp/graphite/manage.py loaddata /tmp/graphite_dbdump.json
67-
when: result.stdout.find("AccountMygraph") == -1
68-
notify: restart carbon-cache
69-
70-
- name: Install database (3/3) Remove temp file
71-
file: path=/tmp/graphite_dbdump.json state=absent
72-
when: result.stdout.find("AccountMygraph") == -1
73-
notify: restart carbon-cache
62+
- name: Create superuser account
63+
command: python {{ graphite_install_path }}/webapp/graphite/manage.py createsuperuser --username={{ graphite_admin_username }} --email={{ graphite_admin_email }} --noinput
64+
sudo_user: "{{ graphite_user }}"
65+
register: superuser_created
66+
args:
67+
creates: "{{ graphite_install_path }}/webapp/graphite/.superuser_created"
68+
69+
- name: Prepare to set up superuser password
70+
template: src=createsuperuser.py.j2 dest=/tmp/createsuperuser.py
71+
when: superuser_created|changed
72+
register: debug2
73+
74+
- name: Set superuser password
75+
shell: "python {{ graphite_install_path }}/webapp/graphite/manage.py shell < /tmp/createsuperuser.py"
76+
sudo_user: "{{ graphite_user }}"
77+
when: superuser_created|changed
78+
79+
- name: Create lock file
80+
file: path="{{ graphite_install_path }}/webapp/graphite/.superuser_created" state=touch
81+
when: superuser_created|changed
82+
83+
- name: Remove temp file
84+
file: path=/tmp/createsuperuser.py state=absent
7485

7586
- name: Make sure services are running
7687
service: name={{ item }} state=started

templates/createsuperuser.py.j2

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from django.contrib.auth.models import User
2+
3+
u = User.objects.get(username__exact='{{ graphite_admin_username }}')
4+
u.set_password('{{ graphite_admin_password }}')
5+
u.save()

0 commit comments

Comments
 (0)