plays
tasks
actions to take inside a play
registers
capture output from a task
handlers
handle errors and can execute an action
ansible-playbook -i inventory/hosts playbook.yml --ask-vault-pass
/playbook.yml
/inventory
/hosts
/roles
/webserver
/tasks
/main.yml
/files
/database
/tasks
/main.yml
Iterate over all of the packages to install them:
---
- hosts: all
tasks:
- name: Install list of packages
apt: name={{item}} state=installed
with_items:
- apache2
- vim
- tmux
- mosh
Also works with a variable: with_items: "{{ var-packages }}"
You can call with_items
using the inventories file, and access sub-groups using []
# Display inventory using groups['webserver']
- debug:
msg: "{{ item }}"
with_items:
- "{{ groups['webserver'] }}"
Includes can be at play or task levels:
- include: play-level-include.yml
- name: play level include
hosts: all
tasks:
ansible-vault encrypt vault.yml
ansible-vault decrypt vault.yml
ansible-vault view vault.yml --ask-vault-pass