0

I am currently using in defaults/main.yml:

myRoleName_host: "{{ ansible_host }}"

but some people feel we shouldn't use ansible_host. I know we can reference from host_vars but from within the role you have no guarantee about the host name, so that doesn't seem like a good option. Or should myRoleName_host just be a mandatory variable that the play has to set in order to call the role?

Edit: The goal is to allow the host to be written in the config files/templates that need to be on the server, as well as url variables that the role produces. Other roles depend on these url output variables.

achyrd
  • 401
  • 1
  • 3
  • 9
  • 3
    What are you trying to accomplish? – larsks Dec 04 '20 at 21:53
  • Well within the role there are config file, SQL files, urls that all need the actual host in them. Also We use this variable as an output/API that the role produces so other roles can reference it – achyrd Dec 04 '20 at 22:01
  • Wouldn't the fact `ansible_facts.nodename` be safer then? – β.εηοιτ.βε Dec 04 '20 at 22:14
  • Is there an actual variable `ansible_facts.nodename` or by nodename do you mean using the actual group or host name from the inventory? – achyrd Dec 04 '20 at 22:35
  • `inventory_hostname`, `inventory_hostname_short`, `ansible_fqdn` are some possible candidates to get the name of a host from inventory/facts. – Zeitounator Dec 05 '20 at 13:20

0 Answers0