Ansible vs Chef, Puppet & Salt
Ansible was not the first configuration management tool. CFEngine (1993) started the field; Puppet (2005), Chef (2009) and Salt (2011) dominated before Ansible (2012) took the lead with its agentless, YAML-first approach. You will meet all of them in older or larger organisations.
Side by side
| Ansible | Puppet | Chef | Salt | |
|---|---|---|---|---|
| language | YAML + Jinja2 | Puppet DSL (declarative) | Ruby DSL (recipes, cookbooks) | YAML + Jinja2 (states) |
| model | push, agentless over SSH | pull: agent asks the server every 30 min | pull: chef-client on each node | push and pull: minions connected to a master over ZeroMQ, or agentless salt-ssh |
| central server | optional (AWX / Automation Platform) | Puppet Server (+ PuppetDB) | Chef Infra Server | Salt master |
| ordering | top to bottom | dependency graph (explicit require, before) |
top to bottom | require/order |
| drift correction | when you run it | automatically on every agent run | automatically on every client run | scheduled or event-driven (reactor) |
| owner | Red Hat (IBM) | Perforce | Progress | Broadcom (VMware) |
Push vs pull
Push (Ansible): you decide when changes happen, there is nothing to install or keep running on the nodes, and a run is easy to follow in one terminal. The downside: drift is only fixed when somebody (or a scheduler) runs the playbook, and the control node must reach every host.
Pull (Puppet, Chef): every node converges itself on a schedule, so drift is corrected within 30 minutes without anyone doing anything, and nodes behind NAT only need to reach the server. The cost: an agent on every machine, a server to run and secure, certificates to manage, and changes that land "some time in the next half hour".
Ansible can approximate pull with ansible-pull (each node clones a Git repository and runs a playbook against itself from cron) or with scheduled jobs in AWX.
The same task in four tools
Install nginx and make sure it runs:
# Ansible
- name: Nginx
hosts: web
become: true
tasks:
- name: Package
ansible.builtin.apt: {name: nginx}
- name: Service
ansible.builtin.service: {name: nginx, state: started, enabled: true}# Puppet (manifest)
package { 'nginx': ensure => installed }
service { 'nginx':
ensure => running,
enable => true,
require => Package['nginx'],
}# Chef (recipe)
package 'nginx'
service 'nginx' do
action [:enable, :start]
end# Salt (state file nginx.sls)
nginx:
pkg.installed: []
service.running:
- enable: true
- require:
- pkg: nginxWhich one when
| Situation | Usual choice |
|---|---|
| new project, Linux VMs, small to large fleets | Ansible |
| network devices (switches, routers, firewalls) | Ansible (huge vendor collection support) |
| thousands of long-lived servers that must self-correct continuously | Puppet or Chef (or Ansible with frequent scheduled runs) |
| event-driven remediation at scale | Salt (reactor), or Event-Driven Ansible |
| containers on Kubernetes | none of them: images + manifests + GitOps |
| first boot of a cloud VM | cloud-init, then one of the above |
The idea that unites them is the one from devops-intro: describe the desired state in version-controlled code, and let a tool converge reality to it. Once you know Ansible well, reading a Puppet manifest or a Salt state is mostly a matter of syntax.
A tiny model of convergence
All four tools do the same thing at their core: compare desired and actual state per resource, act only on the differences, and report. Here it is as a runnable model:
desired = {
"pkg:nginx": "installed",
"pkg:telnet": "absent",
"file:/etc/motd": "Managed by config management\n",
"svc:nginx": "running",
}
actual = {
"pkg:nginx": "absent",
"pkg:telnet": "installed",
"file:/etc/motd": "Managed by config management\n",
"svc:nginx": "stopped",
}
def converge(desired, actual):
report = {"ok": 0, "changed": 0}
for res, want in desired.items():
have = actual.get(res)
if have == want:
report["ok"] += 1
print(f"ok: {res}")
else:
actual[res] = want # the "module" fixes it
report["changed"] += 1
print(f"changed: {res}: {have!r} -> {want!r}")
return report
print("run 1:", converge(desired, actual))
print("run 2:", converge(desired, actual))changed: pkg:nginx: 'absent' -> 'installed'
changed: pkg:telnet: 'installed' -> 'absent'
ok: file:/etc/motd
changed: svc:nginx: 'stopped' -> 'running'
run 1: {'ok': 1, 'changed': 3}
ok: pkg:nginx
ok: pkg:telnet
ok: file:/etc/motd
ok: svc:nginx
run 2: {'ok': 4, 'changed': 0}
Run 1 fixes three resources, run 2 finds nothing to do: idempotency, the same in every tool.
Test yourself
What is the main architectural difference between Ansible and Puppet?
- Ansible uses Ruby
- Ansible pushes over SSH without agents; Puppet agents pull from a server on a schedule
- Puppet has no server
- Ansible needs PuppetDB
Which tool's states look most like Ansible (YAML + Jinja2)?
- Chef
- Puppet
- Salt
- CFEngine
How can Ansible approximate the pull model?
ansible-pullfrom cron, or scheduled runs in AWX- It can't
- By installing Puppet
- With
--check