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复制到各自机器上
copy: src=/root/hosts dest=/etc/ owner=root group=root mode=0544
- name: 在新的hosts文件后面追加各自机器内网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?
The problem is solved, use IP: "{{ ansible_eth0'ipv4' }}" instead of {{ansible_all_ipv4_addresses}}
The modified playbook is as follows: