# with\_items and groups of hosts

**URL:** <https://forum.ansible.com/t/with-items-and-groups-of-hosts/13442>\
**Category:** Ansible Project\
**Created:** [September 10, 2013, 7:11am UTC](https://forum.ansible.com/t/with-items-and-groups-of-hosts/13442 "2013-09-10T07:11:30Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Boden\_Garman](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@Boden\_Garman](https://forum.ansible.com/u/Boden_Garman)\
**Post date:** [September 10, 2013, 7:11am UTC](https://forum.ansible.com/t/with-items-and-groups-of-hosts/13442/1 "2013-09-10T07:11:30Z")

</div>

Hello!

We’re trying to set up a MySQL user for each one of our FreeRADIUS nodes on our master MySQL host.

# file /etc/ansible/hosts

[mysql-masters]  
db.company.local

[radius-servers]  
radius1.company.local  
radius2.comapny.local

In the role ‘mysql-masters’ we have this task:

- name: Add FreeRADIUS MySQL user  
mysql\_user: name={{ sql\_user }} host={{ item }} password={{ sql\_pass }} priv={{ sql\_db }}.\*:ALL  
with\_items: “{{ hosts[‘radius\_servers’] }}”

Unfortunately this approach isn’t working:  
TASK: [Add FreeRADIUS MySQL user] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [db.company.local] =\> with\_items expects a list

What’s the best way to go about this? I’m following the best practices role based layout.

Cheers!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 10, 2013, 12:37pm UTC](https://forum.ansible.com/t/with-items-and-groups-of-hosts/13442/2 "2013-09-10T12:37:23Z")

</div>

Any time you say “{{ }}” you are saying “hey, I want a string!”

So you don’t need to do this, and can just say

with\_items: hosts[‘radius\_servers’]

or (cleaner)

with\_items: hosts.radius\_servers

---

<div class="post-metadata">

**Author:** ![Boden\_Garman](https://avatars.discourse-cdn.com/v4/letter/b/9d8465/32.png) [@Boden\_Garman](https://forum.ansible.com/u/Boden_Garman)\
**Post date:** [September 10, 2013, 11:22pm UTC](https://forum.ansible.com/t/with-items-and-groups-of-hosts/13442/3 "2013-09-10T23:22:18Z")

</div>

Ah I see, thank you!

If anyone else has the same issue, I was actually looking for “groups[‘radius\_servers’]” not hosts.

Thanks again!

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan2](https://avatars.discourse-cdn.com/v4/letter/m/da6949/32.png) [@Michael\_DeHaan2](https://forum.ansible.com/u/Michael_DeHaan2)\
**Post date:** [September 11, 2013, 12:26pm UTC](https://forum.ansible.com/t/with-items-and-groups-of-hosts/13442/4 "2013-09-11T12:26:44Z")

</div>

Yes, I had assumed you had that explicitly defined somewhere.

For new readers, groups[‘foo’] is an Ansible provided list of all hostnames (or IPs, etc) in a given group.
