Score:0

Load vars based on env in ansible

gr flag

Team, I have two vars that map to two environments. I want to use them in playbook but only one value should be applied based on env playbook runs on.

ex:

var = test1 > should be loaded when env1
var = test2 > should be loaded when env2

any hint how can i achieve this in ansible?

I want to write my task in such a way that this variables var carries test1 value when it is run on env1 and vice versa. is there a login I can use at task level? my task is below and when am running my playbook on clusterA it should use var=test1 and when running on clusterB it should use var=test2

    - name: Add persistent ddn volume
  mount:
    path: "{{ lustre_client_path }}"
    src: "{{ var }}"
    fstype: lustre
    state: mounted
Zeitounator avatar
fr flag
I suggest you read [Where to set an ansible variable](https://docs.ansible.com/ansible/latest/user_guide/playbooks_variables.html#variable-precedence-where-should-i-put-a-variable) and [How to build your inventory](https://docs.ansible.com/ansible/latest/user_guide/intro_inventory.html).
Score:-1
gr flag

Actually I figured out. I just had to create a separate file and called it configs.yml and place it in each cluster env playbook directly. This worked. So based on env is now loading.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.