Ansible - Playbooks âļī¸
Description đ
Playbooks
are written in yml
, and are the main way to automate Ansible
.
play
: defines the set of activities (tasks) to be run on hoststask
: an action to be performed on the host- i.e: execute a command, run a script, install a package
Basics đ
-
execute an
ansible playbook
ansible-playbook <path-to/playbook.yml> -i <path-to/inventory.txt>
-
playbook.yml
- name: <play name> hosts: <host-pattern> tasks: - name: <task name> <module>: <module-args>
Examples đ§Š
-
sample playbook
- name: Play 1 hosts: all tasks: - name: execute command 'date' command: date - name: execute script on server command: test_script.sh - name: install httpd service yum: name: httpd state: present - name: start web server service: name: httpd state: started