dokku / ansible-dokku

Ansible modules for installing and configuring Dokku
MIT License
176 stars 44 forks source link

dokku_service_create: support passing flags #158

Open blockloop opened 1 year ago

blockloop commented 1 year ago

Some plugins use flags to customize their options. See MySQL. This allows you to pass flags to the dokku_service_create command so that MySQL and others can be customized.

ltalirz commented 1 year ago

Thanks @blockloop !

I notice one of the examples of dokku_service_create uses the environment field to pass environment variables to the service creation. Am I understanding correctly that some, but not all of the flags of the mysql service can also be passed in this way? For some fields (e.g. MYSQL_IMAGE, MYSQL_CUSTOM_ENV) it is explicitly documented; does it also work for the other flags or not?

The reason I'm asking is just that there doesn't appear to be precedent in the ansible-dokku role for passing flags along in the way you suggest (and I guess one could debate over whether the leading -- should be part of the key or not).

blockloop commented 1 year ago

I'm not really sure of a way to pass the password as a flag to the mysql plugin. I've tried MYSQL_PASSWORD=secretpassword and MYSQL_CUSTOM_ENV="USER=myuser;PASSWORD=secretpassword" and neither of them work. I would rather use the environment variables, but I don't know that the plugin exposes it that way.

The only thing that works with the MySQL plugin is the following:

dokku mysql:create tmpdb --user myuser --password secretpassword
blockloop commented 1 year ago

Yeah according to this you can't pass in password as an environment variable. You have to use the flags for any of the additional parameters like memory, shm, password, etc.

ltalirz commented 1 year ago

Ok, thanks for checking!

In that case happy to accept the contribution. Please update the README as described in https://github.com/dokku/ansible-dokku/blob/master/CONTRIBUTING.md

I do wonder whether, instead of using separate key-value pairs, it would be easier to just pass the entire set of flags along as a single string [1]. True, it would be less structured, but on the other hand I understand we want a "generic pass-through" that works with all plugins, so we can anyhow not do any meaningful validation of, say, the passed fields at this point. Maybe some options don't require a value, ...

[1] I see that there are "special" cases like -c where you will want to have quotation marks around the value passed to the option which might get tricky with your current implementation (could probably also be done by default for all options though).