-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Change Grafana admin password in the apply mode (#2420)
- Loading branch information
Showing
5 changed files
with
64 additions
and
2 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,32 @@ | ||
from typing import Dict | ||
import configparser | ||
|
||
|
||
class FilterModule(object): | ||
""" Defines filters """ | ||
|
||
def filters(self): | ||
return { | ||
'from_ini': self.from_ini, | ||
} | ||
|
||
def from_ini(self, content: str, default_section_name: str = '__none__') -> Dict: | ||
""" | ||
Parse `content` in ini format which was obtained from a decoded file. | ||
:param content: to be parsed | ||
:param default_section_name: fields without section will be available under this key | ||
:return: properly parsed ini content | ||
""" | ||
fixed_content = content.replace('\\n', '\n').replace('\\', '') | ||
|
||
config = configparser.ConfigParser() | ||
|
||
try: | ||
config.read_string(fixed_content) | ||
except configparser.MissingSectionHeaderError: | ||
# content might be missing default header, add it and try to parse it once more | ||
config = configparser.ConfigParser() | ||
config.read_string(f'[{default_section_name}]\n{fixed_content}') | ||
|
||
return {section: dict(config.items(section)) for section in config.sections()} |
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
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 @@ | ||
--- | ||
- name: Fail when grafana admin password isn't set | ||
fail: | ||
msg: "Please specify grafana admin password (grafana_security.admin_password)" | ||
when: | ||
- grafana_security.admin_password is undefined or grafana_security.admin_password | length == 0 | ||
|
||
- name: Compare current grafana password set on the remote with the schema file | ||
block: | ||
- name: Fetch the grafana.ini file from the remote | ||
slurp: | ||
src: /etc/grafana/grafana.ini | ||
register: grafana_config_file | ||
|
||
- name: Parse grafana.ini content | ||
set_fact: | ||
grafana_config_file_content: "{{ grafana_config_file['content'] | b64decode | from_ini }}" | ||
|
||
- name: Fetch the password | ||
set_fact: | ||
current_admin_password: "{{ grafana_config_file_content['security']['admin_password'] }}" | ||
|
||
# Grafana admin password change is only available through the grafana-cli | ||
- name: Change admin password using grafana-cli | ||
command: grafana-cli admin reset-admin-password "{{ grafana_security.admin_password }}" | ||
when: grafana_security.admin_password != current_admin_password |
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
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