Popular searches
//

Migrate from Puppet to Ansible

17.12.2014 | 3 minutes reading time

In a previous post , I wrote about combining Ansible and Puppet, with Ansible as remote executor for arbitrary commands. In this post I take a look at how to migrate from Puppet to Ansible.

Combine the Execution of Ansible and Puppet

If you want to migrate from Puppet to Ansible, an all or nothing approach is hard to implement. It has all the disadvantages which apply to any Big Bang migration.
The other option is to migrate Puppet modules one by one to Ansible and remove them from Puppet. During the migration you would have to call both tools to provision a server. That is not very effective and error prone. So what can you do?
You can execute Puppet from within an Ansible playbook. This way you always execute both tools and will not miss any role or module.

But you cannot just call Puppet from Ansible, as Ansible expects a return code of 0 when everything works as expected. Puppet will return a code of 2 when it changed something, which is totally fine. However, Ansible interprets this as a failure and stops executing any other steps on this server. So you need to make Ansible accept 0 as well as 2 as successful return codes:

This way Puppet fits into Ansibles way of handling things.

Finegrained Integration of Puppet into Ansible

If you would like to take a more fine grained approach, you could use Puppet tags to execute Ansible tasks between two different Puppet agent calls:

Execution output

An important detail to consider when calling Puppet from Ansible is Puppet’s execution output. Even though Ansible now knows how to interpret Puppet’s return codes, Ansible only tells you that something changed, but not what changes were made:

If you want to see Puppet’s output, when something changed or went wrong, you can use the debug task:

The Puppet output does not look very nice, but it is better than having nothing at all. To make it a bit more readable, perhaps such an Ansible callback plugin might help. But this will be the topic of another post.

This post shows how to execute Puppet from inside Ansible Playbooks. I hope this post gives you a starting point on how to migrate your own Puppet installation to Ansible. As always, do not hesitate to contact me when you have any questions.