September 2018
Beginner to intermediate
214 pages
5h 53m
English
This is another simple module that does the simple job of changing a hostname. To make this module more exciting, we will use some of the playbook features with it. This module takes one input, the new hostname, and changes the hostname of the remote host. We can use the playbook predefined variable, {{ inventory_hostname }}. This variable calls the hostname for the Ansible inventory and uses it with the playbook.
First, we need to change the inventory file to look as follows:
[servers]server0 ansible_host=192.168.10.10 server1 ansible_host=192.168.10.11 server2 ansible_host=192.168.10.12
Then, we use the following playbook:
- name: change hostname hostname: name: "{{ inventory_hostname }}"
After executing the playbook, ...
Read now
Unlock full access