Strange failure when trying to delegate_to using a group member

25 views
Skip to first unread message

Willard Dennis

unread,
Sep 11, 2018, 4:05:21 PM9/11/18
to Ansible Project
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?

Matt Martz

unread,
Sep 11, 2018, 4:21:00 PM9/11/18
to ansible...@googlegroups.com
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.

--
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-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/b9cb6d71-573b-446d-8299-631e4db3b9d6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Matt Martz
@sivel
sivel.net

Willard Dennis

unread,
Sep 11, 2018, 4:45:52 PM9/11/18
to Ansible Project
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!
Reply all
Reply to author
Forward
0 new messages