# Fetch list of hosts in cluster and do something with them

**URL:** <https://forum.ansible.com/t/fetch-list-of-hosts-in-cluster-and-do-something-with-them/17204>\
**Category:** Ansible Project\
**Created:** [January 7, 2015, 11:17am UTC](https://forum.ansible.com/t/fetch-list-of-hosts-in-cluster-and-do-something-with-them/17204 "2015-01-07T11:17:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Slootman](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@Paul\_Slootman](https://forum.ansible.com/u/Paul_Slootman)\
**Post date:** [January 7, 2015, 11:17am UTC](https://forum.ansible.com/t/fetch-list-of-hosts-in-cluster-and-do-something-with-them/17204/1 "2015-01-07T11:17:31Z")

</div>

I’ve been wondering what the best way of accomplishing this is:

- We have a number of customers
- Each customer has one or more (Oracle Weblogic) clusters
- Each cluster has an Admin node
- I want to generate an (passphrase-less) ssh key for the “oracle” user on each Admin node
- The public key of the Admin node has to be installed on each node in the cluster so that the “oracle” user on the Admin node can reach each node non-interactively

I have a script that can be run on a host which prints out a list of hostnames in the cluster, iff the host is an Admin node:

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 7, 2015, 1:06pm UTC](https://forum.ansible.com/t/fetch-list-of-hosts-in-cluster-and-do-something-with-them/17204/2 "2015-01-07T13:06:56Z")

</div>

it seems you want something like:

- name: generate ssh key  
&nbsp;&nbsp;...  
&nbsp;&nbsp;when: clusterdata.stdout\_lines

- name: install generated key  
&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;&nbsp;when: not clusterdata.stdout\_lines

or you can check the length of clusterdata.stdout\_lines, which seems  
to be only populated on the admin node. I would still add it to your  
inventory as it is easier to segregate by groups or a group/host var.

---

<div class="post-metadata">

**Author:** ![Paul\_Slootman](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@Paul\_Slootman](https://forum.ansible.com/u/Paul_Slootman)\
**Post date:** [January 7, 2015, 2:19pm UTC](https://forum.ansible.com/t/fetch-list-of-hosts-in-cluster-and-do-something-with-them/17204/3 "2015-01-07T14:19:07Z")

</div>

Thanks, something like that might work for me, in combination with setting some local facts on the Admin server. I’ll be trying a couple of things…

Am I right in assuming that the following:

- name: create key for oracle  
user: name=oracle createhome=no generate\_ssh\_key=yes ssh\_key\_file=.ssh/id\_oracle ssh\_key\_passphrase=“” state=present

will not change anything for an existing oracle user, besides creating an ssh key if it doesn’t yet exist?

Paul

---

<div class="post-metadata">

**Author:** ![Brian\_Coca](https://avatars.discourse-cdn.com/v4/letter/b/6de8d8/32.png) [@Brian\_Coca](https://forum.ansible.com/u/Brian_Coca)\
**Post date:** [January 7, 2015, 2:23pm UTC](https://forum.ansible.com/t/fetch-list-of-hosts-in-cluster-and-do-something-with-them/17204/4 "2015-01-07T14:23:16Z")

</div>

sounds right
