Hi,

I would like to define a dict in group_vars/all.yml where a key inside this 
dict would consist of a fixed string concatened to the result of : "{{ 
hostvars[inventory_hostname]['ansible_hostname'] }}".

This should looks like following:

✘ root@lab:~/playbook# cat group_vars/all.yml
---
my_dict:
  "something.{{ hostvars[inventory_hostname]['ansible_hostname'] }}":
    "key1": "value1"
    "key2": "value2"



✔ root@lab:~/playbook# cat roles/test/tasks/test.yml
---
- name: print my_dict
  debug:
    msg: "{{ my_dict }}"



✔ root@lab:~/playbook# ansible-playbook -i hosts site.yml

PLAY [all] 
*********************************************************************

TASK [setup] 
*******************************************************************
ok: [127.0.0.1]

TASK [test : print my_dict] 
****************************************************
ok: [127.0.0.1] => {
    "msg": {
        "something.{{ hostvars[inventory_hostname]['ansible_hostname'] }}": 
{
            "key1": "value1",
            "key2": "value2"
        }
    }
}

But as you can see, when I print it with a simple debug task, it hasn't the 
behaviour I was expected.
I was more thinking about something as following :

TASK [test : print my_dict] 
****************************************************
ok: [127.0.0.1] => {
    "msg": {
        "something.mygreathostname": {
            "key1": "value1",
            "key2": "value2"
        }
    }
}

Do you have an idea how could I do it ?

Thanks,

Guillaume

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/34a40530-632c-4926-9ab4-76111375af0e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to