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

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:

主站蜘蛛池模板: 团风县| 棋牌| 芒康县| 逊克县| 晋宁县| 井研县| 宁阳县| 辽源市| 内江市| 缙云县| 阿拉善右旗| 昌乐县| 隆化县| 平昌县| 邹平县| 申扎县| 枞阳县| 青龙| 临桂县| 沧州市| 建瓯市| 咸丰县| 琼结县| 托克逊县| 饶阳县| 博罗县| 腾冲县| 宁都县| 高邑县| 安塞县| 二连浩特市| 罗甸县| 若羌县| 麻城市| 乐都县| 治多县| 新和县| 当涂县| 信阳市| 新闻| 扬州市|