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.

server1.example.com

 

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

server1.example.com

 

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

server1

 

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

---
- hosts: all
  tasks:
    - 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: [server1.example.com]

TASK [debug]
ok: [server1.example.com] => {
    "msg: "full hostname is server1.example.com"
}

TASK [debug]
ok: [server1.example.com] => {
    "msg: "short hostname is server1"
}

PLAY RECAP
server1.example.com : 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.




Comments