# What module(s) to use for Ansible to act on group of hosts

**URL:** <https://forum.ansible.com/t/what-module-s-to-use-for-ansible-to-act-on-group-of-hosts/43050>\
**Category:** Get Help\
**Created:** [May 28, 2025, 12:24pm UTC](https://forum.ansible.com/t/what-module-s-to-use-for-ansible-to-act-on-group-of-hosts/43050 "2025-05-28T12:24:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![trt757](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@trt757](https://forum.ansible.com/u/trt757)\
**Post date:** [May 28, 2025, 12:24pm UTC](https://forum.ansible.com/t/what-module-s-to-use-for-ansible-to-act-on-group-of-hosts/43050/1 "2025-05-28T12:24:08Z")

</div>

Can someone help me get my head wrapped around this?

I have a group of over 500 hosts. I want one central server to perform an action locally and create host-specific files for each host. It seems that if I try to use a hosts file, the action would then be performed on each host and I don’t want that.

I need to figure out how to get Ansible to read from a list of hosts, creating files for each host. So host1.file, then host2.file, then host3.file. I’m just not sure what module(s) to use for this effort.

---

<div class="post-metadata">

**Author:** ![mariolenz](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/mariolenz/32/108_2.png) [@mariolenz](https://forum.ansible.com/u/mariolenz)\
**Post date:** [May 28, 2025, 3:35pm UTC](https://forum.ansible.com/t/what-module-s-to-use-for-ansible-to-act-on-group-of-hosts/43050/2 "2025-05-28T15:35:08Z")

</div>

I’m not sure if I really understand. Do you want to create those files on the host where you run ansible?

If this is the case, maybe using a hosts file / normal inventory and [delegate\_to: localhost](https://docs.ansible.com/ansible/latest/playbook_guide/playbooks_delegation.html) might help you.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [May 28, 2025, 3:41pm UTC](https://forum.ansible.com/t/what-module-s-to-use-for-ansible-to-act-on-group-of-hosts/43050/3 "2025-05-28T15:41:46Z")

</div>

use `template` module, but as mariolenz suggested, you want to `delegate_to: localhost` to ensure the work is done on one host ( or ‘nfs\_server’, wherever you want the files to live).

---

<div class="post-metadata">

**Author:** ![trt757](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@trt757](https://forum.ansible.com/u/trt757)\
**Post date:** [May 28, 2025, 3:43pm UTC](https://forum.ansible.com/t/what-module-s-to-use-for-ansible-to-act-on-group-of-hosts/43050/4 "2025-05-28T15:43:55Z")

</div>

What I’m trying to do is to create the \*crt and \*.key files necessary to have encrypted rsyslog working. So I would need to run this playbook on our CA server, then figure out a way to copy all those host-specific files to the correct host (that’s a hurdle for another day).  
How could I feed ansible a list to run our key creation script against so that host1.crt, host1.key; host2.crt; host2.key is created in some directory on the CA. Later I’d figure out how to send them to the correct host.

---

<div class="post-metadata">

**Author:** ![trt757](https://avatars.discourse-cdn.com/v4/letter/t/c67d28/32.png) [@trt757](https://forum.ansible.com/u/trt757)\
**Post date:** [May 28, 2025, 3:45pm UTC](https://forum.ansible.com/t/what-module-s-to-use-for-ansible-to-act-on-group-of-hosts/43050/5 "2025-05-28T15:45:42Z")

</div>

Encrypted rsyslog is working within our org, but only against the servers, which there’s only about 40 or so. So running the certificate generation script against them manually was easy. I feel like by the time I figure out how to put a playbook together to do the 500 workstations, I could have just done it manually. But they insist it be automated.

---

<div class="post-metadata">

**Author:** ![bcoca](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/bcoca/32/9269_2.png) [@bcoca](https://forum.ansible.com/u/bcoca)\
**Post date:** [May 28, 2025, 3:46pm UTC](https://forum.ansible.com/t/what-module-s-to-use-for-ansible-to-act-on-group-of-hosts/43050/6 "2025-05-28T15:46:49Z")

</div>

so in general you create the certificate request at each server, copy it to the CA, generate the signed cert, then copy it back to the original host.

There are several ways to do this, I recommend 3 sections (using 1 block to delegate) you can also do 3 plays or other:

- play 1
  - hosts: all
  - generate requests
  - copy requests to controller (use fetch)  
block: (delegate\_to: CA server)
  - copy requests files
  - generate signed
  - copy signed back to controller (fetch again)  
end block
  - copy signed to host
  - clean up files on controller
