(1)hosts文件
[task]
IP地址1 hostname=主机名1
IP地址2 hostname=主机名2
IP地址3 hostname=主机名3
[task:vars]
ansible_become=yes
ansible_become_method=sudo
ansible_become_user=root
ansible_become_password=密码
ansible_user=用户
ansible_password=密码
ansible_python_interpreter=/usr/bin/python
(2)yaml文件
--- - name: 设置主机名 hosts: all become: yes tasks: - name: 修改 /etc/hostname 文件 lineinfile: path: /etc/hostname line: "{{ hostname }}" create: yes - name: 设置主机名 command: hostnamectl set-hostname "{{ hostname }}" - name: 更新当前 shell 会话中的主机名 shell: | hostname "{{ hostname }}"
标签:name,批量,hostname,主机名,ansible,IP地址,become From: https://www.cnblogs.com/libin-linux/p/18410198