ansible 增加本机/etc/hosts 下hostsname 与IP


 

 

---
- 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}}"

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM