# Strange failure when trying to delegate\_to using a group member

**URL:** <https://forum.ansible.com/t/strange-failure-when-trying-to-delegate-to-using-a-group-member/28552>\
**Category:** Ansible Project\
**Created:** [September 11, 2018, 8:05pm UTC](https://forum.ansible.com/t/strange-failure-when-trying-to-delegate-to-using-a-group-member/28552 "2018-09-11T20:05:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Will\_Dennis](https://avatars.discourse-cdn.com/v4/letter/w/919ad9/32.png) [@Will\_Dennis](https://forum.ansible.com/u/Will_Dennis)\
**Post date:** [September 11, 2018, 8:05pm UTC](https://forum.ansible.com/t/strange-failure-when-trying-to-delegate-to-using-a-group-member/28552/1 "2018-09-11T20:05:21Z")

</div>

I am trying to use a delegate\_to in a play where the delegated-to host is the (only) member of a group, where the groupname is ‘slurm-prictlr’. The play looks like:

- name: Ensure MUNGE key from Slurm primary controller is on this client  
synchronize:  
src: /etc/munge/munge.key  
dest: /etc/munge/munge.key  
delegate\_to: $item  
with\_items: “{{ groups.slurm-prictlr[0] }}”  
when: “‘slurm-prictlr’ not in group\_names”

However, when I run the playbook with this play on a host, I’m getting:

fatal: [myhost]: FAILED! =\> {  
“msg”: “‘prictlr’ is undefined”  
}

Are hyphens in group names the problem? Or what else may be the problem here?

---

<div class="post-metadata">

**Author:** ![sivel](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/sivel/32/1198_2.png) [@sivel](https://forum.ansible.com/u/sivel)\
**Post date:** [September 11, 2018, 8:20pm UTC](https://forum.ansible.com/t/strange-failure-when-trying-to-delegate-to-using-a-group-member/28552/2 "2018-09-11T20:20:11Z")

</div>

The problem is that you have used a hyphen in your group name. That does not meet the requirements for a valid python name, so you cannot use dot syntax.

In your current form, jinja2, thinks that you want to perform subtraction between variables at `groups.slurm` and `prictlr[0]`.

You will need to instead use bracket syntax:

with\_items: “{{ groups[‘slurm-prictlr’][0] }}”

With that being said, I’d really recommend renaming your groups to use underscores, instead of hyphens.

---

<div class="post-metadata">

**Author:** ![Will\_Dennis](https://avatars.discourse-cdn.com/v4/letter/w/919ad9/32.png) [@Will\_Dennis](https://forum.ansible.com/u/Will_Dennis)\
**Post date:** [September 11, 2018, 8:45pm UTC](https://forum.ansible.com/t/strange-failure-when-trying-to-delegate-to-using-a-group-member/28552/3 "2018-09-11T20:45:52Z")

</div>

Advice taken, replaced hypens in group names with underscores, everything works now (after I also fixed the “$item” in the delegate\_to to be the correct “{{ item }}” syntax)

Thanks for the quick help!
