0

I'm trying to automate zookeeper install using Ansible. I want to add a bunch of lines to my cfg file. Following is an example where there are 5 nodes. zoo1, zoo2, zoo3 etc the hosts that I've in my ansible_hosts file.

I want to implement it out with with_items but cannot figure it out. Any idea how to access the host name in the ansible_hosts file in a loop ?

initLimit=5
syncLimit=2
server.1=zoo1:2888:3888
server.2=zoo2:2888:3888
server.3=zoo3:2888:3888
server.4=zoo4:2888:3888
server.5=zoo5:2888:3888

2 Answers 2

2

Try using the lineinfile module with_items: groups['<GROUP_NAME>'] (or with_items: groups['all'] if you want to reference all of the defined hosts).

1
0

you can automate this by doing a loop in template

{% for host in groups['06'] %} server.{{ loop.index }}={{ hostvars[host]['ansible_eth0']['ipv4']['address'] }}:2888:3888 {% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.