thanks for pointing map, previously I had in my playbook temporary facts.
--------------
 - set_fact:
     tmp_list1: '{{ ansible_vcs_nodes | default([])|lower }}'

 - set_fact:
    tmp_list2: '{{ groups["all"]|lower }}'

 - add_host:
       name: '{{ item }}'
       groups: other_nodes
   with_items:
      - '{{  tmp_list1 | difference(tmp_list2) }}'
--------------
which is pretty ugly ;-)

But for my case, I still find ireplace_hostname (or whatever the
attribute name would be ) of  feature useful, as I  need same letters
sizing from groups["patched_nodes"] as it was in ansible_vcs_nodes for
few roles. which are case sensitive for hostname unfortunately.

So far I have another temporary variable
-------------
 - set_fact:
    vcs_nodes: '{{vcs_nodes|default([]) + [ item ] }}'
   when: item|lower in groups["patched_nodes"]|lower
   with_items:
      '{{ ansible_vcs_nodes }}'
 ------------

with ireplace_hostname , I could use directly groups["patched_nodes"]
and don't have to set_fact like snippet above.

Regards
marek


2018-04-11 17:20 GMT+02:00 Andrew Gaffney <and...@agaffney.org>:
> Instead of modifying add_host to ignore case, why not just pass the values
> through the jinja2 'lower' filter when passing them to add_host in your
> playbook? You can even do something like the following to de-dupe with
> existing inventory hosts:
>
> {{ (list_with_new_hosts | map("lower")) | difference(groups.all |
> map("lower")) }}
>
> This will give you a list of hosts that only exist in the new list, taking
> into account case differences, with all results in lowercase.
>
> Andrew Gaffney
> agaffney.org
>
> On Wed, Apr 11, 2018 at 8:37 AM, Marek Slebodnik <mslebod...@gmail.com>
> wrote:
>>
>> Hello,
>>
>> I've got playbook with dynamic inventory. And what bothers me is, that
>> add_host is case sensitive.
>>
>> So when I have in my initial inventory
>> ----
>> kserVer3
>> ---
>> and tasks which which returns hostname from VCS cluster, returns:
>> ['Kserver3', 'KServer4']
>>
>> I end up with inventory.
>>
>> -------
>> kserVer3
>> Kserver3
>> Kserver4
>> -------
>> And as kserver3 and Kserver3 are same host.
>>
>> What I would suggest is additional add_host: attributes.
>>
>> e.g. ignore_case: True,
>> and then final inventory would be
>> ---
>> kserVer3
>> Kserver4
>> ---
>> and ireplace_hostname: True
>> with result
>> ---
>> Kserver3
>> Kserver4
>> ---
>>
>> Before I start implementation, I would appreciate other's opinions.
>>
>> Regards
>> Marek Slebodnik
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Ansible Development" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to ansible-devel+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to ansible-devel+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to