*Thank you so much kai. your solution made my day and it is totally great
and worked out finally.*
One more Question - Can we use dictionary in inventory hosts section like
below and access it in task using *with_dict* and *item.key* and
*item.value* as i have tried this but didn't get success
[brokers]
ansible-slave node_id=1 kafka_dict={1:9092,2:9093,3:9094}
ansible-slave-1 node_id=2 kafka_dict={1:9092,2:9093,3:9094,4:9095}
Then i declared them in variables section then i got success
[brokers]
ansible-slave
ansible-slave-1
[brokers:vars]
kafka_dict={1:9092,2:9093,3:9094}
I was able to use then item.key and item.value with with_dict construct and
everything worked fine but now i need to add different dictionary of
ansible-slave-1 host how can i add that since this dictionary is common?
I tried adding one more kafka_dict with different values in brokers:vars
but one of the kafka_dict is used in playbook for both of hosts i.e. last
one. for example like below
[brokers]
ansible-slave
ansible-slave-1
[brokers:vars]
kafka_dict={1:9092,2:9093,3:9094}
kafka_dict={1:9092,2:9093,3:9094,4:9094}
Can we define a host specific variables?
Regards,
On Sunday, November 12, 2017 at 8:09:42 PM UTC+5:30, Kai Stian Olstad wrote:
>
> On lørdag 11. november 2017 08.42.12 CET SHUBHAM JAIN wrote:
> > Thank you so much Kai for your solution. it will definitely help me.
> > I am using inventory_hostname so name will be different according to
> your
> > solution but i wanted same name.
> > I want to automate multiple kafka brokers on single node. that's why i
> am
> > looking for the solution.
> > As in server.properties file name will be different so it won't work.
> >
> > i tried below thing
> > [brokers]
> > ansible-slave node_id=1 kafka_port=[9092,9093,9094]
> > ansible-slave-1 node_id=2 kafka_port=[9092,9093,9094]
> >
> > But i am not able to iterate through kafka_port list with *with_items*
> > looping construct.
>
> I don't think you can specify a list in the inventory, you would need to
> use host_vars/ folder for that.
> Or you can do this "kafka_port=9092,9093,9094" and the with_items will be
>
> with_items: "{{ kafka_port.split(',') }}"
>
>
> > One more thing i need to do i.e. broker.id where i need to start from
> value
> > 1 and end to a number which is total number of brokers. How can i achive
> > this? Is there any notion of global variable which i can update and use
> > further.
> > For example in above case you can see i want to have three brokers on
> > ansible-slave node on ports 9092,9093,9094 and three brokers on
> > ansible-slave-1 node port 9092,9093,9094 so total brokers count 6 so i
> want
> > to assign broker.id 1 to 3 in the ansible-slave host and 4 to 6 in
> > ansible-slave-1 host.
>
> When you are using the with_items above or something simular you could
> calculate it, the item is the kafka_port
>
> {{ item - 9091 + (node_id - 1) * 3 }}
>
>
> --
> Kai Stian Olstad
>
--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/ansible-project/f3949815-d20f-4abb-9294-d937f2b62c64%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.