# host as variable in a playbook ?

**URL:** <https://forum.ansible.com/t/host-as-variable-in-a-playbook/12150>\
**Category:** Ansible Project\
**Tags:** ansible-project\
**Created:** [December 19, 2012, 1:40am UTC](https://forum.ansible.com/t/host-as-variable-in-a-playbook/12150 "2012-12-19T01:40:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_DeHaan](https://avatars.discourse-cdn.com/v4/letter/m/c4cdca/32.png) [@Michael\_DeHaan](https://forum.ansible.com/u/Michael_DeHaan)\
**Post date:** [December 19, 2012, 1:40am UTC](https://forum.ansible.com/t/host-as-variable-in-a-playbook/12150/1 "2012-12-19T01:40:54Z")

</div>

with\_items takes an array.

You should define $mx as an array in that case.

If you want to just execute local commands for every machine in the  
group, that is actually:

hosts: whatever  
tasks:  
- name: blarg...  
&nbsp;&nbsp;&nbsp;local\_action: shell /usr/bin/cmk -II $inventory\_hostname

And that will call "cmk" with each hostname in the group "whatever" as  
a parameter.

You can also use different hosts by using "delegate\_to: hostname"  
instead of "local\_action".

Search for "delegate\_to" in the docs for more info.

Hope that helps? If not, let me know a bit more. Thanks!
