I've solved it this way
- https://github.com/ansible/ansible/issues/12086#issuecomment-327927275
On Thursday, September 7, 2017 at 8:14:35 PM UTC+2, Giovanni Gaglione wrote:
>
> I basically need the index of the current hostname, but I can't find a
> way.
> {{ groups['browsers'].index(inventory_hostname) }} will return always the
> same index (because the hostname is always the same).
>
> I couldn't find any other way. Do you know if the API offers something
> more appropriate? Still doing research...
> On Thursday, September 7, 2017 at 7:17:08 PM UTC+2, Giovanni Gaglione
> wrote:
>>
>> Hi Jesse,
>>
>> Could you make an example of this solution?
>>
>> My scenario is like the following:
>>
>> [myhost]
>> 192.168.1.1
>> 192.168.1.1
>> 192.168.1.1
>> 192.168.1.1
>> 192.168.1.1
>> 192.168.1.1
>> 192.168.1.1
>>
>> But then, when ansible iterates over these host, I would like to have a
>> unique name of the host (example `192.168.1.1-3th`). It seems there is not
>> way to get the index of the host.
>>
>> Any suggestion?
>>
>> On Tuesday, September 3, 2013 at 6:33:39 AM UTC+2, Jesse Keating wrote:
>>>
>>> On Aug 28, 2013, at 9:52 AM, CS <[email protected]> wrote:
>>> >
>>> > Thanks for the response. I thought of using bash `wait` and a script,
>>> but I would like to stay in Ansible as much as possible.
>>> >
>>> > My use case is that there are multiple "slow enough" independent tasks
>>> that happen on a host, but I can't fire and forget because I need to know
>>> that they either succeed or fail. That seems like a pretty common use case,
>>> and I have other things too that would benefit from this kind of
>>> parallelism, but maybe I'm using Ansible in a non-standard way. In this
>>> case, I'm installing N (2 or 3 for now) python virtualenvs for independent
>>> services on a single host, each of which takes about 5 minutes to install.
>>> I'd love to have developers wait 5 minutes rather than 5N minutes for that
>>> part of the installation, and there are other tasks too that nothing else
>>> depends on but that need to be reported as succeeding or failing.
>>> >
>>> > Are there any other approaches I might consider using Ansible apart
>>> from moving all the parallel tasks into a script?
>>>
>>> What I've done to accomplish this is to create fake inventory entries,
>>> one entry per action I want to do in parallel. Then I have a play that
>>> works over this group of "hosts" to execute the action(s) I want done, all
>>> delegated to localhost.
>>>
>>> This kicks in Ansible's forking and lets the tasks run in parallel.
>>>
>>> -jlk
>>>
>>>
--
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/71263640-65af-44a6-a711-97b3f88fa77c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.