Reputation: 18322
Is there a built-in that allows for you to grab the hostname of the host you're on, excluding the inventory_hostname
variable? What I want to do is execute plays on multiple hosts, but they have to be manually ran on each host (security policy, don't worry about it). However, as part of this, we use template variables that require the actual hostname of the localhost. Is it possible to acquire this with something other than inventory_hostname
, since I assume that will just return localhost
?
Upvotes: 1
Views: 4767
Reputation: 13950
Sure- lots of ways to do that, but this one is friendly to local or remote running:
- command: hostname
register: hostname
- set_fact:
actual_hostname: hostname.stdout
# now you can use {{ actual_hostname }} wherever and have
# the value returned from running hostname on each target host.
Upvotes: 7