Ansible populating a variable based on hostname
Following up on the indefatigable @michaelhampton’s suggestion, here is how you use host_vars
project root
-- host_vars
-- host1.yml
-- host2.yml
-- host3.yml
-- my_playbook.yml
So when you set up host1.yml, you can just put the value it needs there:
---
Certmap: www.mydomain.com
And when you need to access it, you just refer to it like:
{{ Certmap }}
It will change for different hosts so long as each host has a host_vars file with Certmap
defined.