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 ?
PS : Cross posting here for better coverage. http://stackoverflow.com/questions/24249492/accessing-the-host-names-in-the-ansible-hosts-file-in-a-loop-in-ansbile
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--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/352c1173-2d5b-474d-a769-30cc1a961909%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/u0j-DhqmOmc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEhzMJAiTwRnNKVirFsuzdouKZOcbF4VyADyoG9z3hFLXzoeew%40mail.gmail.com.
Now what if I want to put a different value 1,2,3 .... to a file /tmp/zookeeper/myid ?The my id file already exists but I want to an auto increment number which is different for each machine?
- name: Add server.number=hostname:2888:3888 the server configuration to config file zoo.cfg
lineinfile: dest={{zk_root_dir}}/zookeeper-3.4.6/conf/zoo.cfg line="server.{{ item.0}}={{ item.1 }}:2888:3888"
with_together:
- ["1","2","3","4"] #FIXME - this is a hack that needs to be fixed later
- groups['zookeeper']
--
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/u0j-DhqmOmc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEhzMJAN0rT4gS1BLC5PZoad8vwFomDYU7xWMGKt-C1ATbrpMQ%40mail.gmail.com.
- name: Add server.number=hostname:2888:3888 the server configuration to config file zoo.cfg
lineinfile: dest={{zk_root_dir}}/zookeeper-3.4.6/conf/zoo.cfg line="server.{{ item.0}}={{ item.1 }}:2888:3888"
lineinfile: dest={{zk_tmp_dir}}/myid line="{{ item.0}}"
with_together:
- ["1","2","3","4"] #FIXME - this is a hack that needs to be fixed later
- groups['zookeeper']
In my /tmp/myid file I get
1
2
3
4
but I want to have 1 in host1:myid, 2 in host2:myid, 3 in host3:myid and 4 in host4:myid
Any ideas ?
Now I've another problem.
If I want to write the server id to myid file then it writes it 4 times.
- name: Add server.number=hostname:2888:3888 the server configuration to config file zoo.cfg
lineinfile: dest={{zk_root_dir}}/zookeeper-3.4.6/conf/zoo.cfg line="server.{{ item.0}}={{ item.1 }}:2888:3888"
lineinfile: dest={{zk_tmp_dir}}/myid line="{{ item.0}}"
with_together:
- ["1","2","3","4"] #FIXME - this is a hack that needs to be fixed later
- groups['zookeeper']
In my /tmp/myid file I get
1
2
3
4
but I want to have 1 in host1:myid, 2 in host2:myid, 3 in host3:myid and 4 in host4:myid
Any ideas ?
--
On Mon, Jun 16, 2014 at 3:38 PM, Soumya Simanta <soumya....@gmail.com> wrote:
This is what I've and it work. It's not clean though. I'm sure there is a better way. Because this work for 4 servers but won't work for a N without me changing the line - ["1","2","3","4"]
- name: Add server.number=hostname:2888:3888 the server configuration to config file zoo.cfg
lineinfile: dest={{zk_root_dir}}/zookeeper-3.4.6/conf/zoo.cfg line="server.{{ item.0}}={{ item.1 }}:2888:3888"
with_together:
- ["1","2","3","4"] #FIXME - this is a hack that needs to be fixed later
- groups['zookeeper']
On Mon, Jun 16, 2014 at 2:34 PM, Serge van Ginderachter <se...@vanginderachter.be> wrote:
--
On 16 June 2014 20:32, Soumya Simanta <soumya....@gmail.com> wrote:
Now what if I want to put a different value 1,2,3 .... to a file /tmp/zookeeper/myid ?
The my id file already exists but I want to an auto increment number which is different for each machine?
sounds like nesting lookup plugins; anible suppport for that is limited thoughhave a look at with_nested
You received this message because you are subscribed to a topic in the Google Groups "Ansible Project" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/ansible-project/u0j-DhqmOmc/unsubscribe.
To unsubscribe from this group and all its topics, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CAEhzMJAN0rT4gS1BLC5PZoad8vwFomDYU7xWMGKt-C1ATbrpMQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CALrNVjWD_cTBmfXzxc8-7LkXyzcaESBm%2BkfAXgH02BDonGAq%2Bg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/539FE6BD.4030007%40yahoo.gr.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/539FE756.1080800%40yahoo.gr.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/539FEC22.1030704%40yahoo.gr.
Jinja2 has a special variable called "loop.index" that it seems you can use here, and then it's just the template module.
Keep it simple and don't put extra logic in your playbook.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgwPM2w%3DtoBth7tLMjaVTHiF7YS9_pYbxZ1CC%2B6CYs4MPQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/53A13A93.5070402%40yahoo.gr.
" It should be possible in both cases."
No, it shouldn't. Ansible play books don't use Jinja2 for loops - nor should Jinja2 be used in Ansible for logic.
In this case, the user needs to produce a configuration file, so using a template is exactly what is needed.
Your server_id solution is suboptimal and requires manual maintaince of that file when it could be automatically generated.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgxGFLAqVLwh08ht562_iD%3DMQJTw05m71N5UjccA%3DmjGLg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/53A1C7E7.7030706%40yahoo.gr.
" As you are expanding your deployments to more use cases (especially in the clustering domain) you will eventually need to construct task loops that allow you to do such basic things as accessing the loop index and back referencing to iterators"
This is also a general statement without a reason, FWIW.
This is very much a niche use case. Not really interested.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/CA%2BnsWgwr9Nr0O6iFCf6rvoCOMgHvXgKDDQO4qogs_Uo6Gty-Vg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/53A3F39F.8010508%40yahoo.gr.