官术网_书友最值得收藏!

The hostname module

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, you can simply test it out using an ad hoc Ansible command:

ansible -m shell -a hostname servers

The result should look as follows:

主站蜘蛛池模板: 阳原县| 门源| 岱山县| 樟树市| 义马市| 德江县| 石泉县| 文昌市| 清丰县| 章丘市| 渑池县| 枣强县| 年辖:市辖区| 垦利县| 海兴县| 昌都县| 翁源县| 潢川县| 乐亭县| 江北区| 连山| 永春县| 东兴市| 怀来县| 淮北市| 城固县| 阳高县| 定结县| 永和县| 天长市| 浠水县| 鲜城| 伽师县| 桦川县| 樟树市| 泗水县| 玉林市| 武宁县| 闵行区| 淮北市| 清水河县|