Variable depends on other variable

Hi

I am wondering is it possible to set variable’s value which depends on other variable’s value? Something like this:

dbname = prod:
if dbid == 1

dbname = dev:
if dbid == 2

Or maybe there is another way how to achieve this?

Thanks,
Edgars

Group variables are a great way to do this, and you can assign variables for both your prod and development groups that your machines are in.

See “group_vars/” in the docs for a nice place to put this info.

Technically you can use “set_fact” but needing it is something of a “playbook complexity smell” in most cases.

Could you give me example with set_facts? I am trying to set fact, but I am not sure how can I use that fact later in playbook

Edgars

ceturtdiena, 2013. gada 26. septembris 00:23:36 UTC+2, Edgars rakstīja:

You really should use group variables instead.

I have no groups here. I am running playbook and all tasks on localhost with connection=local. I have DB server with multiple DB instances. Depending on DB instance ID, I want to set config options.

Edgars

ceturtdiena, 2013. gada 26. septembris 00:23:36 UTC+2, Edgars rakstīja:

You could create some groups :slight_smile: