how to use blocks in ansible
by Ansible. There is an inventory file ~/playbooks/inventory
on Ansible controller
which has all these three nodes added. Create a playbook ~/playbooks/blocks.yml
on Ansible controller
to install httpd web server
and start its service
. We need the tasks to be run only on CentOS
based web nodes.
Create the playbook using blocks to logically group the tasks (installation and service start) so that even if we run playbook for all hosts that are in inventory, the tasks are run only on CentOS
based nodes.
=================================
---
- hosts: all
tasks:
- block:
- name: install httpd
yum: name=httpd state=present
- name: start httpd
service: name=httpd state=started
when: ansible_distribution == "CentOS"
Comments
Post a Comment