ansible 的主机表如下
[root@ansible AnsibleInstallRpm]# cat /etc/ansible/hosts
---
all:
hosts:
node1:
ansible_connection: ssh
ansible_host: 10.100.201.161
ansible_ssh_pass: xxx@123
ansible_ssh_user: root
http_port: 81
node2:
ansible_connection: ssh
ansible_host: 10.100.201.162
ansible_ssh_pass: xxx@123
ansible_ssh_user: root
http_port: 82
children:
nodes:
hosts:
node1:
node2:
现在有两种需求
第一种是在每台主机上修改hostname 名字 并且在/etc/hosts 中写上对应关系
[root@node2 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.100.201.162 node2
yml 脚本如下
---
- hosts: all
tasks:
- name: change name
shel