一、hostname模块

hostname模块用于修改主机名(注意: 它不能修改/etc/hosts文件)

https://docs.ansible.com/ansible/latest/modules/hostname_module.html#hostname-module

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
将192.168.98.203机器的主机名修改为test_node3

[root@manage01 ~]# ansible -m hostname -a "name=test_node3" 192.168.98.203
192.168.98.203 | CHANGED => {
"ansible_facts": {
"ansible_domain": "",
"ansible_fqdn": "test_node3",
"ansible_hostname": "test_node3",
"ansible_nodename": "test_node3",
"discovered_interpreter_python": "/usr/libexec/platform-python"
},
"changed": true,
"name": "test_node3"
}


备注:批量修改需要使用playbook剧本

二、学习视频

视频:hostname模块