Guest User

Untitled

a guest
Mar 6th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. from fabric.api import *
  2.  
  3. env.user='ubuntu'
  4. env.hosts = ['xyz.com','def.com', 'ghi.com', 'lol.com', 'rofl.com']
  5. env.roledefs['appagent'] = ['ghi.com', 'lol.com', 'rofl.com']
  6. env.password='<provide_your_ssh_connection_password>'
  7. env.parallel = True
  8.  
  9. def host():
  10. run('uname -a')
  11. hn = run('hostname')
  12. print "Hostname is : " , hn
  13.  
  14. @roles('appagent')
  15. @with_settings(warn_only=True)
  16. def install(name='apache2'):
  17. installed = run('service --status-all | grep -c ' + name)
  18. if int(installed) < 1:
  19. sudo('apt-get update')
  20. sudo('apt-get install -y ' + name)
  21. sudo('service ' + name + ' restart')
  22. else:
  23. print name + " is already installed, checking if its running or not"
  24. running = run('ps -A | grep -c ' + name)
  25. if int(running) == 0:
  26. print "starting " + name
  27. sudo('service ' + name + ' restart')
  28. else:
  29. print name + " already in running state"
Add Comment
Please, Sign In to add comment