Pouyan
Pouyan

Reputation: 519

Make ansible-playbook run the playbook for the given host only once

I have a build server which runs ansible playbooks, after each commit to the given playbook repository. The host data comes from a dynamic inventory. The problem I am encountering right now is that when I push several commits, the build servers runs the ansible-playbook for the same host after another and it creates a race condition on the host server. How can I make the ansible wait for the running playbook to finish and then start or simply not run when there is a playbook running on the host? (I want only one instance of ansible running in the host.)

Upvotes: 0

Views: 370

Answers (1)

clvx
clvx

Reputation: 328

You can check the ansible pid of the remote server before launching a playbook run. What OS/distro are you using? Hmm.. depending of what you are testing, you can spin up a container(docker or lxd) to test your environment for each commit. Take in account that if you creating/modifying network interfaces or creating device files, it won't suite your needs. I use this method to test my playbook roles in just one server having several unit tests for each role param.

Upvotes: 1

Related Questions