FreeKB - inventory_hostname variable (target server hostname)
Ansible - inventory_hostname variable (target server hostname)

This assumes you have installed Ansible, are familiar with the ansible-playbook command and have created a playbook.

Let's say you've a server with the following hostname.


The inventory_hostname variable will return the full hostname, like this.


The inventory_hostname_short variable will return only the short hostname, like this.



For example, let's say you have the following playbook.

- hosts: all
    - debug
        msg: full hostname is {{ inventory_hostname }}

    - debug
        msg: short hostname is {{ inventory_hostname_short }}


Running this playbook should return the following.

PLAY [all]

TASK [Gathering Facts]
ok: []

TASK [debug]
ok: [] => {
    "msg: "full hostname is"

TASK [debug]
ok: [] => {
    "msg: "short hostname is server1"

PLAY RECAP : ok=3  changed=0  unreacable=0  failed=0


Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 312ab in the box below so that we can be sure you are a human.