Chef and Ansible Comparison

Table mapping the concepts between Chef and Ansible:

Chef TermAnsible TermNotes
resourcemodule
cookbookrole
recipes/default.rbtasks/main.yml
templates/templates/
files/files/
ohai automatic attributesfacts
chef workstationcontrol machine
chef servercontrol machineTechnically there is no server with ansible, just the workstation. But many server concepts map to the control machine.
chef server's node inventoryinventory files on the control machine
chef server's cookbook inventory
playbooks, roles, etc on the control machine
node searchmagic vars hostvars, group_names, and groups.
environmentsmultiple inventories: inventories/prod/hosts inventories/dev/hosts
environment attributesgroup_vars within those multiple inventories: inventories/prod/group_vars/all inventories/dev/group_vars/all
data bags for prod, staging, dev, etcgroup vars (see environment attributes)

rolesgroups
role attributesgroup_vars. Examples: inventories/prod/group_vars/web and inventories/dev/group_vars/db
node attributesadd variables to hosts directly in the inventory file, or in host_vars file such as /etc/ansible/hosts_vars/host1
attributes/default.rbvars/main.yml and defaults/main.yml
run_listplaybookAnsible 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 startcreate 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 attributesvars/main.yml
metadata.rbmeta/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."

Leave a Reply

Your email address will not be published. Required fields are marked *