Bootstrap FreeKB - Ansible - Change hostname
Ansible - Change hostname

Updated:   |  Ansible articles

If you are not familiar with modules, check out Ansible - Getting Started with Modules.

The hostname module is used to update the hostname of managed nodes, such as updating the /etc/hostname file on the managed node, assuming the managed node is a Linux system. This module would typically be used with the -i or --limit command line options, so that only a single manage node is targeted. Also, the -e or --extra-vars command line option would probably be used to define the new hostname.

ansible-playbook foo.yml -i server1.example.com, --extra-vars "newhostname=server1"

 

Here is what you would probably have in your playbook.

---
- hosts: all
  tasks:
  - name: set new hostname to {{ newhostname }}
    hostname:
      name: "{{ newhostname }}"

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


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