# play\_hosts

**URL:** <https://forum.ansible.com/t/play-hosts/15613>\
**Category:** Ansible Project\
**Created:** [July 6, 2014, 1:06pm UTC](https://forum.ansible.com/t/play-hosts/15613 "2014-07-06T13:06:43Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sturban](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@sturban](https://forum.ansible.com/u/sturban)\
**Post date:** [July 6, 2014, 1:06pm UTC](https://forum.ansible.com/t/play-hosts/15613/1 "2014-07-06T13:06:43Z")

</div>

Hi,

I am a n00b and I am trying to create a CA playbook that first locally creates certs, keys etc (using easy-rsa’s pkitool) and then deploys these to the different play\_hosts. -I might be going about this the wrong way, but is there a way to register the play\_hosts in a list that can then be used when I change play\_hosts to be just localhost, and then when I do the deploy go back to the original play\_hosts?

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [July 6, 2014, 3:03pm UTC](https://forum.ansible.com/t/play-hosts/15613/2 "2014-07-06T15:03:32Z")

</div>

you already have a play\_hosts variable with the ‘current active hosts’ in the play​, but it will be reset every play.

In this case I would just rewrite the play to use:

with\_items: groups[‘all’]

---

<div class="post-metadata">

**Author:** ![sturban](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@sturban](https://forum.ansible.com/u/sturban)\
**Post date:** [July 6, 2014, 4:46pm UTC](https://forum.ansible.com/t/play-hosts/15613/3 "2014-07-06T16:46:13Z")

</div>

​-The problem with ‘with\_items: groups[‘all’]’ is that it takes that directly from /etc/ansible/hosts rather than using whatever hosts-pattern that was supplied on the command-line - i.e. ‘–limit ​somehosts’

`

# somehosts.yml

---

<div class="post-metadata">

**Author:** ![sturban](https://avatars.discourse-cdn.com/v4/letter/s/dfb087/32.png) [@sturban](https://forum.ansible.com/u/sturban)\
**Post date:** [July 7, 2014, 12:18pm UTC](https://forum.ansible.com/t/play-hosts/15613/4 "2014-07-07T12:18:13Z")

</div>

What should current\_host be replaced with so that the below only runs for the host localhost?

`

---

<div class="post-metadata">

**Author:** ![Brian\_Coca1](https://avatars.discourse-cdn.com/v4/letter/b/278dde/32.png) [@Brian\_Coca1](https://forum.ansible.com/u/Brian_Coca1)\
**Post date:** [July 7, 2014, 12:21pm UTC](https://forum.ansible.com/t/play-hosts/15613/5 "2014-07-07T12:21:49Z")

</div>

when: inventory\_hostname == 'localhost’​

---

<div class="post-metadata">

**Author:** ![Michael\_DeHaan1](https://avatars.discourse-cdn.com/v4/letter/m/5e9695/32.png) [@Michael\_DeHaan1](https://forum.ansible.com/u/Michael_DeHaan1)\
**Post date:** [July 7, 2014, 7:24pm UTC](https://forum.ansible.com/t/play-hosts/15613/6 "2014-07-07T19:24:57Z")

</div>

" with\_items: groups[‘all’]"

I wouldn’t. I’d use the host loop since it’s already there.

- hosts: all  
tasks:
- local\_action: …
