Ansible: how to get host specific variable value by hostname
问题 I'd like to insert initial values to a client's sqlite by Ansible and the values are different for every host. I created myrole/vars/main.yml: hostname1: id: id_1 value: value_1 hostname2: id: id_2 value: value_2 I want to to get it by {{ {{ inventory_hostname }}.id }} and insert the template of .sql, but it is not working. 回答1: You can achieve by modify your variable like this: clients: hostname1: id: id_1 value: value_1 hostname2: id: id_2 value: value_2 Then in your template: {{ clients