Centos 7.6 Install ansible-playbook change hostname

Centos 7.6 Install ansible-playbook change hostname_第1张图片

安装ansible

yum install ansible vim net-tools git -y

添加主机

vim  /etc/ansible/hosts

[all]
192.168.3.209 hostname=docker ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=1234.com
192.168.3.205 hostname=gitlab ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=1234.com

批量更改主机名称

vim /etc/ansible/roles/name.yml

---
- hosts: all
  remote_user: root

  tasks:
     - name: change name
       raw: "echo {{hostname|quote}} > /etc/hostname"
     - name:
       shell: hostname {{hostname|quote}}

执行安装操作

ansible-playbook /etc/ansible/roles/name.yml

批量更改完成

你可能感兴趣的:(Centos,Ansible)