Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent simultaneous deploys with Ansible

Tags:

ansible

Anyone on my team can SSH into our special deploy server, and from there run an Ansible playbook to push new code to machines.

We're worried about what will happen if two people try to do deploys simultaneously. We'd like to make it so that the playbook will fail if anyone else is currently running it.

Any suggestions for how to do this? The standard solution is to use a pid file, but Ansible does not have built-in support for these.

like image 750
James Koppel Avatar asked Feb 19 '14 02:02

James Koppel


People also ask

How do I make an Ansible task run only once?

For such requirements where we need one tasks to run only once on a batch of hosts and we will be running that from Ansible controller node, we have feature parameter named run_once. When we have this parameter mentioned in a task, that task will run only once on first host it finds despite the host batch.

Does Ansible work in parallel?

Ansible's parallel processes are known as forks, and the default number of forks is five. The more forks you set, the more resources are used on the Ansible control node.

How do I limit Ansible hosts?

You can also limit the hosts you target on a particular run with the --limit flag. Negated limit. Note that single quotes MUST be used to prevent bash interpolation.

What is parallel forks in Ansible?

Ansible works by spinning off forks of itself and talking to many remote systems independently. The forks parameter controls how many hosts are configured by Ansible in parallel. By default, the forks parameter in Ansible is a very conservative 5.


1 Answers

Personally I use RunDeck ( http://rundeck.org/ ) as a wrapper around my Ansible playbooks for multiple reasons:

  • You can set a RunDeck 'job' to only be able to be run at one time (or set it to run as many times at the same time as you want)
  • You can set up users within the system so that auditing of who has run what is listed clearly
  • You can set additional variables with constraints on what can be used (specify a list of options)
  • Its a whole lot cheaper than Ansible Tower (RunDeck is free)
  • It has a full API for running jobs pragmatically from build systems
  • You don't need to write complicated bash wrappers around the ansible-playbook command
  • SSH can become a litmus test of 'something needs an ansible script written' - I don't allow SSH access except in full on break/fix situations, and we have happier SA's as a result
  • Lastly, and definitely way up there in the 'nice to have' category is you can schedule RunDeck jobs to run ansible playbooks in a very easy way for anybody who logs on to the console to see what is running when

There are many more good reasons of course, but my fingers are getting tired of typing ;)

like image 167
keba Avatar answered Sep 25 '22 08:09

keba