Chef and Ansible Comparison
Table mapping the concepts between Chef and Ansible:
Chef Term | Ansible Term | Notes |
resource | module | |
cookbook | role | |
recipes/default.rb | tasks/main.yml | |
templates/ | templates/ | |
files/ | files/ | |
ohai automatic attributes | facts | |
chef workstation | control machine | |
chef server | control machine | Technically there is no server with ansible, just the workstation. But many server concepts map to the control machine. |
chef server's node inventory | inventory files on the control machine | |
chef server's cookbook inventory | playbooks, roles, etc on the control machine | |
node search | magic vars hostvars, group_names, and groups. | |
environments | multiple inventories: inventories/prod/hosts inventories/dev/hosts | |
environment attributes | group_vars within those multiple inventories: inventories/prod/group_vars/all inventories/dev/group_vars/all | |
data bags for prod, staging, dev, etc | group vars (see environment attributes) | |
roles | groups | |
role attributes | group_vars. Examples: inventories/prod/group_vars/web and inventories/dev/group_vars/db | |
node attributes | add variables to hosts directly in the inventory file, or in host_vars file such as /etc/ansible/hosts_vars/host1 | |
attributes/default.rb | vars/main.yml and defaults/main.yml | |
run_list | playbook | Ansible Roles are optional, but recommended, and in that scenario an Ansible playbook is like a Chef run_list calling the Ansible Roles |
notify a service to start | create a "handler", and notify it | |
providers/ and resources/ | library/ | |
"creates" property | "creates" property | |
ignore_failure | ignore_errors | |
default level attributes | defaults/main.yml | |
override level attributes | vars/main.yml | |
metadata.rb | meta/main.yml | |
only_if not_if | when | |
template subdir based on os distribution | with_first_found , mentioned in playbooks_conditionals.html | |
wrapper cookbook | include other roles as dependencies in meta/main.yml. Override variables there. | |
run recipes/othertask.rb from within recipes/default.rb | Use an include statement. tasks/main.yml: - name: include othertask include: othertask.yml | |
run recipes/othertask.rb _instead_ of recipes/default.rb | Only main.yml will be called. Make main.yml into nothing more than a sort of "case statement", as follows. Add a variable in the playbook such as run_othertask { role: webserver, port: 5000, run_othertask: true } , and then in tasks/main.yml: - name: include othertask include: othertask.yml when: run_othertask is defined | |
include all attributes in the attributes/ dir | "Files in vars/ are not all automatically loaded - it would absolutely break certain classes of playbooks, so we can't/won't go there. include_vars is a good solution from the task file for specific files." | |