The inventory_hostname magic variable will return the hostname of a manage node as listed in your default hosts file or your own inventory file. The ansible_hostname magic variable will return the hostname of a managed node (e.g. the target system), just like the Linux hostname command. Or, the following can be used to invoke this module on the control node (that's your Ansible server).
For example, let's say you have the following playbook.
---
- hosts: all
tasks:
- debug
msg: Ansible hostname is {{ ansible_hostname }}
- debug
msg: Inventory hostname is {{ inventory_hostname }}
- debug
msg: Short inventory hostname is {{ inventory_hostname_short }}
Running this playbook could return something like this.
TASK [debug]
ok: [server1.example.com] => {
"msg: "Ansible hostname is server1"
}
TASK [debug]
ok: [server1.example.com] => {
"msg: "Inventory hostname is server1.example.com"
}
TASK [debug]
ok: [server1.example.com] => {
"msg: "Short inventory hostname is server1"
}