The idea
Configuration management means writing down how every server should be set up, then letting a tool make each one match. No one logs in to change servers by hand, so they all stay the same.
Line 1 is the desired state: nginx (a web server program) switched on, listening on port 80. It says what the end result is, not the steps to get there. This style is called declarative.
One run: read, compare, change
A run starts by asking every server what it has now. Ansible calls these answers facts. web1 has nginx off, web2 is brand new and empty, web3 is already right.
Line 3 compares want with have. Taking one set of key-value pairs away from the other leaves only what is wanted but missing or wrong. web1 needs one fix, web2 needs two, web3 needs none.
Lines 4 and 5 make just those changes and report them. web1 gets one change, web2 gets two, and web3 is not touched at all. Ansible prints these as changed or ok.
Run it again, and drift
Run the tool a second time. Every server already matches, so every diff is empty and nothing changes. A step that gives the same result however many times it runs is called idempotent.
To test something, a person logs in to web3 and changes the port to 8080. Now web3 no longer matches the written state. This slow, silent difference is called configuration drift.
The next run reads every server again. Only web3 has a non-empty diff, so only its port goes back to 80. Running often on a schedule keeps drift short-lived.
Two ways to run
In push mode, the default in Ansible, the tool contacts each server. In pull mode each server checks in on a schedule and applies the state itself, as Puppet and Chef agents do. Either way, the loop is the same.
What happens
;; step 1/9 · idea
desired state (written once, in a file)
↓ a tool applies it
web1 web2 web3 …all made to match
tools: Ansible, Puppet, Chef, Salt
idea : say WHAT you want, not HOW
The figure shrinks each server to two settings. Real tools manage packages, files, users and services, and each one has its own check (is it installed? is the file the same?), but the idea is the same: compare, then change only what differs. The card is real Python 3. want.items() - have.items() works because items views act like sets when every value is hashable; dict() turns the leftover pairs back into a dict.