亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

python - problem with ansible getting ip
僅有的幸福
僅有的幸福 2017-05-18 10:56:00
0
1
782

Hello everyone!

I encountered a problem, that is, I need to adjust the zk of about 100 machines. Currently, a new zk ip has been written on the ansible control machine, and the plan is to distribute the file of this new zk ip to those 100 machines. in each machine, and then add their respective IPs and hostnames to this file in the files of these 100 machines.

So I wrote an ansible-playbook:

---

- hosts: all
  tasks:
        - name: 將原有的hosts文件備份
          shell: mv /etc/hosts /etc/hosts_bak

        - name: 將ansible端的hosts復(fù)制到各自機(jī)器上
          copy: src=/root/hosts dest=/etc/ owner=root group=root mode=0544

        - name: 在新的hosts文件后面追加各自機(jī)器內(nèi)網(wǎng)ip和hostname
          lineinfile: dest=/etc/hosts line="{{ansible_all_ipv4_addresses}}  {{ansible_hostname}}"

But after writing it and executing it, the effect is like this:

What I want is this effect:

What should I do?

僅有的幸福
僅有的幸福

reply all(1)
漂亮男人

The problem is solved, use IP: "{{ ansible_eth0'ipv4' }}" instead of {{ansible_all_ipv4_addresses}}

The modified playbook is as follows:

---

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

        - name: 將ansible端的hosts復(fù)制到各自機(jī)器上
          copy: src=/root/hosts dest=/etc/ owner=root group=root mode=0644

        - name: 在新的hosts文件后面追加各自機(jī)器內(nèi)網(wǎng)ip和hostname
          lineinfile: dest=/etc/hosts line="{{IP}}  {{ansible_hostname}}"
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template