Run playbook against multiple hosts with different variables

103 views
Skip to first unread message

Nitrous

unread,
Mar 2, 2022, 10:34:43 AM3/2/22
to Ansible Project
So, we build alot of servers with different specs, and our YAML file variables for the build specs differ (like different CPU/RAM/HDD etc) , but the playbooks remain the same.

Currently, to run multiple builds concurrently, I have to open new ssh session to the Ansible server everytime and run the builds for each server using:

So first ssh session will run the build for the firsr server like this: 
ansible-playbook playbooks/newonpremserver.yml -e "hostname=server01" -vvvv

Second ssh session will run the build for the second server like this: 
ansible-playbook playbooks/newonpremserver.yml -e "hostname=server02" -vvvv

and so on..

Please suggest a better way to run builds concurrently.

Dan Linder

unread,
Mar 5, 2022, 12:02:43 AM3/5/22
to Ansible Project
Do you have an inventory file setup that has "server01" and "server02" setup in group(s)?  For instance, instead of running the two examples above, setup an inventory file with both servers listed:

# inventory.ini
server01
server02

Then run your playbook like this:
ansible-playbook playbooks/newonpremserver.yml -i inventory.ini -vvvv

Your playbook will run on both 01 and 02 at the same time.  If you have "server01" through "server99", then just add them to the inventory file and the playbook will run on all of them in parallel.

Nitrous

unread,
Mar 5, 2022, 8:49:29 PM3/5/22
to Ansible Project
Yes, I have hosts (servers) added to my host file as a group (is that the inventory file)?

Foe example:

[onprem]
server01
server02
Reply all
Reply to author
Forward
0 new messages