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

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:

主站蜘蛛池模板: 天祝| 柳州市| 米易县| 棋牌| 吉隆县| 通江县| 河南省| 双流县| 辽阳市| 万州区| 黑龙江省| 锡林郭勒盟| 疏附县| 姜堰市| 娄底市| 金平| 卢湾区| 永定县| 琼结县| 禄劝| 专栏| 鄂托克前旗| 格尔木市| 滦平县| 潜山县| 永城市| 应城市| 陆河县| 尼木县| 云阳县| 建德市| 蛟河市| 嘉义县| 贵阳市| 江陵县| 南丰县| 克东县| 盱眙县| 旅游| 偃师市| 昌江|