---
- hosts: all
  vars:
     IP: "{{ ansible_eth0['ipv4']['address'] }}"
  tasks:
    - name: 将原有的hosts文件备份
      shell: mv /etc/hosts /etc/hosts_bak

    - name: 将ansible端的hosts复制到各自机器上
      copy: src=/root/hosts dest=/etc/ owner=root group=root mode=0644

    - name: 在新的hosts文件后面追加各自机器内网ip和hostname
      lineinfile: dest=/etc/hosts line="{{IP}}  {{ansible_hostname}}"

 

相关文章:

  • 2021-07-27
  • 2021-08-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-21
  • 2022-12-23
  • 2021-12-25
猜你喜欢
  • 2021-10-06
  • 2022-12-23
  • 2022-12-23
  • 2022-01-31
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案