Hi All, 


I have a task which has multiple with_items and hence it picks the latest 
defined item (arbiter) in the delegate which is not the expected result:


```

  run_once: true
  delegate_to: "{{ item }}"
  with_items:
     - "{{ groups['mongodb-active'] }}"
  shell: /usr/bin/mongo --eval 'printjson(rs.add("{{ item }}:27017"))'
  with_items:
    - "{{ groups['mongodb-arbiter'] }}"```

```

I tried using below too, but failed - "ERROR! Unexpected Exception, this is 
probably a bug: unhashable type: 'list'":



- name: Choosing active server

  set_fact:

    active_server: "{{ groups['mongodb-active'] }}"

    

- name: Add secondaries 

  run_once: true

  delegate_to: "{{ active_server }}"

  shell: /usr/bin/mongo --eval 'printjson(rs.add("{{ item }}:27017"))'

  with_items:

    - "{{ groups['mongodb-arbiter'] }}"




On Thursday, 15 March 2018 20:52:45 UTC-4, Žarko Aleksić wrote:
>
> I was working on the similar thing and stumbled across your post. Might be 
> too late for you, but it might help someone else. You can achieve this 
> easily by setting random server as a fact once at the beginning of the 
> playbook. Then referencing that (now static) fact as part of delagate_to.
>
> I used this:
>
>
>
>     - name: Choosing random DB server to use
>       set_fact:
>          random_server: "{{ groups.groupname|random}}"
>
>
>     - name: executing the script on random server
>       shell: /path/to/script
>       delegate_to: "{{ random_server }}"
>
>
>
>
> On Wednesday, November 18, 2015 at 5:35:51 PM UTC-6, Elliott Barrere wrote:
>>
>> Okay, just getting back to this.  I have this in my site.yaml file in 
>> group_vars:
>>
>> rwdc_server: '{{groups.rwdcs|random}}'
>>
>>
>> but it appears that the rwdc_server variable gets a different domain 
>> controller from the group each time it's accessed (sometimes it's the same 
>> one, but not always).  I need the value to be consistent so I can run a 
>> series of commands on the same box.  Is this possible?
>>
>> I'd rather not pin it to a single box (with e.g. {{groups.rwdcs[0]}}), 
>> for basic load balancing & HA...
>>
>

-- 
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-project+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/c1a95d8b-2e6c-43eb-9d45-22672f70f4d8%40googlegroups.com.

Reply via email to