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

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:

主站蜘蛛池模板: 德惠市| 天津市| 黄平县| 天门市| 仁布县| 南陵县| 类乌齐县| 宁国市| 康定县| 巩留县| 余干县| 和静县| 葫芦岛市| 深州市| 齐齐哈尔市| 获嘉县| 澎湖县| 宁津县| 利川市| 洞头县| 社会| 安西县| 丁青县| 鹤岗市| 雷山县| 富裕县| 肥东县| 酉阳| 商河县| 富蕴县| 丹东市| 台东县| 于都县| 万源市| 顺义区| 随州市| 晋中市| 诏安县| 庐江县| 长岛县| 莆田市|