@ -72,6 +72,20 @@ options:
description :
description :
- Path to svn executable to use . If not supplied ,
- Path to svn executable to use . If not supplied ,
the normal mechanism for resolving binary paths will be used .
the normal mechanism for resolving binary paths will be used .
checkout :
required : false
default : " yes "
choices : [ " yes " , " no " ]
version_added : " 2.3 "
description :
- If no , do not check out the repository if it does not exist locally
update :
required : false
default : " yes "
choices : [ " yes " , " no " ]
version_added : " 2.3 "
description :
- If no , do not retrieve new revisions from the origin repository
export :
export :
required : false
required : false
default : " no "
default : " no "
@ -94,6 +108,10 @@ EXAMPLES = '''
# Export subversion directory to folder
# Export subversion directory to folder
- subversion : repo = svn + ssh : / / an . example . org / path / to / repo dest = / src / export export = True
- subversion : repo = svn + ssh : / / an . example . org / path / to / repo dest = / src / export export = True
# Example just get information about the repository whether or not it has
# already been cloned locally.
- subversion : repo = svn + ssh : / / an . example . org / path / to / repo dest = / srv / checkout checkout = no update = no
'''
'''
import re
import re
@ -168,6 +186,12 @@ class Subversion(object):
url = re . search ( r ' ^URL:.*$ ' , text , re . MULTILINE ) . group ( 0 )
url = re . search ( r ' ^URL:.*$ ' , text , re . MULTILINE ) . group ( 0 )
return rev , url
return rev , url
def get_remote_revision ( self ) :
''' Revision and URL of subversion working directory. '''
text = ' \n ' . join ( self . _exec ( [ " info " , self . repo ] ) )
rev = re . search ( r ' ^Revision:.*$ ' , text , re . MULTILINE ) . group ( 0 )
return rev
def has_local_mods ( self ) :
def has_local_mods ( self ) :
''' True if revisioned files have been added or modified. Unrevisioned files are ignored. '''
''' True if revisioned files have been added or modified. Unrevisioned files are ignored. '''
lines = self . _exec ( [ " status " , " --quiet " , " --ignore-externals " , self . dest ] )
lines = self . _exec ( [ " status " , " --quiet " , " --ignore-externals " , self . dest ] )
@ -194,7 +218,7 @@ class Subversion(object):
def main ( ) :
def main ( ) :
module = AnsibleModule (
module = AnsibleModule (
argument_spec = dict (
argument_spec = dict (
dest = dict ( required = True , type = ' path ' ) ,
dest = dict ( type = ' path ' ) ,
repo = dict ( required = True , aliases = [ ' name ' , ' repository ' ] ) ,
repo = dict ( required = True , aliases = [ ' name ' , ' repository ' ] ) ,
revision = dict ( default = ' HEAD ' , aliases = [ ' rev ' , ' version ' ] ) ,
revision = dict ( default = ' HEAD ' , aliases = [ ' rev ' , ' version ' ] ) ,
force = dict ( default = ' no ' , type = ' bool ' ) ,
force = dict ( default = ' no ' , type = ' bool ' ) ,
@ -202,6 +226,8 @@ def main():
password = dict ( required = False , no_log = True ) ,
password = dict ( required = False , no_log = True ) ,
executable = dict ( default = None , type = ' path ' ) ,
executable = dict ( default = None , type = ' path ' ) ,
export = dict ( default = False , required = False , type = ' bool ' ) ,
export = dict ( default = False , required = False , type = ' bool ' ) ,
checkout = dict ( default = True , required = False , type = ' bool ' ) ,
update = dict ( default = True , required = False , type = ' bool ' ) ,
switch = dict ( default = True , required = False , type = ' bool ' ) ,
switch = dict ( default = True , required = False , type = ' bool ' ) ,
) ,
) ,
supports_check_mode = True
supports_check_mode = True
@ -216,19 +242,28 @@ def main():
svn_path = module . params [ ' executable ' ] or module . get_bin_path ( ' svn ' , True )
svn_path = module . params [ ' executable ' ] or module . get_bin_path ( ' svn ' , True )
export = module . params [ ' export ' ]
export = module . params [ ' export ' ]
switch = module . params [ ' switch ' ]
switch = module . params [ ' switch ' ]
checkout = module . params [ ' checkout ' ]
update = module . params [ ' update ' ]
# We screenscrape a huge amount of svn commands so use C locale anytime we
# We screenscrape a huge amount of svn commands so use C locale anytime we
# call run_command()
# call run_command()
module . run_command_environ_update = dict ( LANG = ' C ' , LC_MESSAGES = ' C ' )
module . run_command_environ_update = dict ( LANG = ' C ' , LC_MESSAGES = ' C ' )
if not dest and ( checkout or update or export ) :
module . fail_json ( msg = " the destination directory must be specified unless checkout=no, update=no, and export=no " )
svn = Subversion ( module , dest , repo , revision , username , password , svn_path )
svn = Subversion ( module , dest , repo , revision , username , password , svn_path )
if not export and not update and not checkout :
module . exit_json ( changed = False , after = svn . get_remote_revision ( ) )
if export or not os . path . exists ( dest ) :
if export or not os . path . exists ( dest ) :
before = None
before = None
local_mods = False
local_mods = False
if module . check_mode :
if module . check_mode :
module . exit_json ( changed = True )
module . exit_json ( changed = True )
if not export :
elif not export and not checkout :
module . exit_json ( changed = False )
if not export and checkout :
svn . checkout ( )
svn . checkout ( )
else :
else :
svn . export ( force = force )
svn . export ( force = force )
@ -236,7 +271,7 @@ def main():
# Order matters. Need to get local mods before switch to avoid false
# Order matters. Need to get local mods before switch to avoid false
# positives. Need to switch before revert to ensure we are reverting to
# positives. Need to switch before revert to ensure we are reverting to
# correct repo.
# correct repo.
if module . check_mode :
if module . check_mode or not update :
check , before , after = svn . needs_update ( )
check , before , after = svn . needs_update ( )
module . exit_json ( changed = check , before = before , after = after )
module . exit_json ( changed = check , before = before , after = after )
before = svn . get_revision ( )
before = svn . get_revision ( )