Fabric roles

Fabric can define roles for hosts, and run only the tasks to role members. For example, we might have a bunch of database servers on which we need to validate whether the MySql service is up, and other web servers on which we need to validate whether the Apache service is up. We can group these hosts into roles, and execute functions based on those roles:

#!/usr/bin/python__author__ = "Bassim Aly"__EMAIL__ = "basim.alyy@gmail.com"from fabric.api import *env.hosts = [    '10.10.10.140',  # ubuntu machine    '10.10.10.193',  # CentOS machine    '10.10.10.130',  ]env.roledefs = {    'webapps': ['10.10.10.140','10.10.10.193'],    'databases': ['10.10.10.130'],}env.user = "root"env.password = "access123"@roles('databases')def validate_mysql():    output ...

Get Hands-On Enterprise Automation with Python. now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.