'Ansible add_host dynamically from variable

I am looking for a way to use the Ansible add_host module to set the variable from a variable, like shown below:

- name: Add a host alias that we reach through a tunnel (Ansible 2.0 and newer)
  add_host:
    hostname: '{{ hostvars_hostname }}'
    "{{ hostvars_variable }}": "{{ inventory_hostname }}"

I am using hostvars to ensure the variable is available across an entire inventory so set_fact does not really accomplish the same thing.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source