ansible IP


問題解決了,用IP: "{{ ansible_eth0'ipv4' }}"   而不是{{ansible_all_ipv4_addresses}}

修改了之后的playbook 如下:

---

- 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