I have a configuration that includes something like this:
[[secretstores.os]]
id = "some_store"
keyring = "telegraf"
[[inputs.mysql]]
servers = ["mysql_user:@{some_store:mysql_password}@tcp(mysqlserver.example.com:3306)/"]
Starting telegraf
with this configuration fails because the secret store doesn’t exist. I don’t see a way to create the secret store from the command line or any other way to ensure that the secret store exists when telegraf
starts with this configuration.
I have a solution, but it doens’t seem like it could be the best or most straightforward way to do this. For context, I’m doing this in Ansible.
In my initial configuration, I replace the reference to the secret store with a placeholder:
[[secretstores.os]]
id = "some_store"
keyring = "telegraf"
[[inputs.mysql]]
servers = ["mysql_user:mysql_password_placeholder@tcp(mysqlserver.example.com:3306)/"]
I then (re)start telegraf, and that creates the secret store.
Next, I set the password in the secret store so that I can now use it.
Lastly, I replace the password placeholder with a reference to the password in the secret store (see ansible.builtin.lineinfile):
ansible.builtin.lineinfile:
path: "{{ telegraf_config_file }}"
regexp: "^(.*)mysql_password_placeholder(.*)$"
line: '\1@{some_store:mysql_password}\2'
backrefs: yes
notify: restart telegraf
This all works, but it just feels a bit weird:
- create a dummy configuration, kinda like a template
- (re)start
telegraf
so it will create the secret store - correct the dummy configuration to be a correct configuration
- restart
telegraf
Is there a better way to do this?
Many thanks!