#NEWLINE# @ cli . command ( ) #NEWLINE# @ click . option ( '--dest' , type = click . Choice ( [ 'production' , 'staging' , 'localhost' , 'vagrant' , 'custom' ] ) , help = 'Deployment target' , required = True ) #NEWLINE# @ click . option ( '-i' , '--inventory' , type = str , default = None , help = 'Path to an inventory file. Should be specified only when "--dest custom" is set' ) #NEWLINE# @ click . option ( '--vagrant-machine' , type = str , default = '' , help = 'Vagrant machine to provision' ) #NEWLINE# @ click . option ( '--sudo/--no-sudo' , default = False ) #NEWLINE# @ click . option ( '--ask-sudo-pass/--no-ask-sudo-pass' , default = False ) #NEWLINE# def deploy( dest , sudo , ask_sudo_pass , vagrant_machine , inventory ) : #NEWLINE# #INDENT# prepare_source_package ( ) #NEWLINE# ansible = ensure_ansible ( ) #NEWLINE# if ( dest == 'vagrant' ) : #NEWLINE# #INDENT# environ = os . environ . copy ( ) #NEWLINE# environ [ 'PATH' ] = '{}:{}' . format ( os . path . dirname ( ansible ) , environ [ 'PATH' ] ) #NEWLINE# click . echo ( click . style ( 'Running deployment on Vagrant. This may take a while...' , fg = 'magenta' ) ) #NEWLINE# subprocess . check_call ( ( 'vagrant up ' + vagrant_machine ) , shell = True , env = environ ) #NEWLINE# subprocess . check_call ( ( 'vagrant provision ' + vagrant_machine ) , shell = True , env = environ ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( dest == 'custom' ) : #NEWLINE# #INDENT# if ( inventory is None ) : #NEWLINE# #INDENT# raise click . ClickException ( '-i/--inventory should be specified together with "--dest custom"' ) #NEWLINE# #UNINDENT# if ( not os . path . exists ( inventory ) ) : #NEWLINE# #INDENT# raise click . ClickException ( "Custom inventory file {} doesn't exist" . format ( inventory ) ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( inventory is not None ) : #NEWLINE# #INDENT# raise click . ClickException ( '-i/--inventory should be specified only when "--dest custom" is specified' ) #NEWLINE# #UNINDENT# inventory = from_project_root ( 'ansible' , 'inventories' , dest ) #NEWLINE# #UNINDENT# click . echo ( click . style ( 'Running deployment on {}. This may take a while...' . format ( inventory ) , fg = 'magenta' ) ) #NEWLINE# cmd = [ ansible , '-i' , inventory ] #NEWLINE# if ( dest in ( 'localhost' , ) ) : #NEWLINE# #INDENT# cmd . extend ( [ '-c' , 'local' ] ) #NEWLINE# if ( dest == 'localhost' ) : #NEWLINE# #INDENT# cmd . append ( '--sudo' ) #NEWLINE# #UNINDENT# #UNINDENT# if sudo : #NEWLINE# #INDENT# cmd . append ( '--sudo' ) #NEWLINE# #UNINDENT# if ask_sudo_pass : #NEWLINE# #INDENT# cmd . append ( '--ask-sudo-pass' ) #NEWLINE# #UNINDENT# cmd . append ( from_project_root ( 'ansible' , 'site.yml' ) ) #NEWLINE# subprocess . check_call ( cmd )