How to generate a group of ip list by referencing a variable in play books?

Hi all:
I have a group of host whose IPs are 10.129.51.158,10.129.50.235,10.129.50.232 and I will define them as variable, like this
ip = 10.129.51.158,10.129.50.235,10.129.50.232

Is there any way to generate a play book like this by referencing this ip?

[my-role]
10.129.51.158

10.129.50.235

10.129.50.232

[my-role:vars]

Hi,

Hi all:
        I have a group of host whose IPs
are 10.129.51.158,10.129.50.235,10.129.50.232 and I will define them as
variable, like this
ip = 10.129.51.158,10.129.50.235,10.129.50.232

Is there any way to generate a play book like this by referencing this ip?

[my-role]
10.129.51.158
10.129.50.235
10.129.50.232

[my-role:vars]
,

I'm sorry, I do not understand your question. As you have not gotten
any answers yet, it might be others have not understood it, too.

What you outline above is part of a hosts file. But where do you want
to define the ip? And what should it be used for?

Do you want to iterate/loop over all members of your group my-role?
That can be done. See the example in the docs:
https://docs.ansible.com/ansible/playbooks_loops.html#id29

Johannes