Ansible Playbooks
Ansible Playbooks#
Playbooks are lists of tasks written in YAML.
Playbooks may be included in other playbooks.
Run a playbook#
ansible-playbook playbook.yml
Eg.
---
- hosts: all
tasks:
- name: Install Apache
command: yum install --quiet -y httpd httpd-devel
- name: Copy main Apache configuration
command: >
cp /path/to/config/httpd.conf /etc/httpd/conf/httpd.conf
- name: Copy Apache virtual host configuration
command: >
cp /path/to/config/httpd-vhosts.conf /etc/httpd/conf/httpd-vhosts.conf
- name: Start Apache
command: service httpd start
- name: Configure Apache to run at boot
command: chkconfig httpd on
The > sign following command: tells YAML to fold the next set of indented lines into a single string.
For tasks with one or two parameters, you can use compact module arguments:
yum: name=apache2 state=installed
Limit playbooks to specific hosts or groups#
ansible-playbook playbook.yml --limit webservers
This runs the playbook only on the webservers group, even if the playbook contains hosts: all.
To see a list of would-be affected servers by a playbook:
ansible-playbook playbook.yml --list-hosts