@ -89,6 +89,7 @@ options:
- ' If full, performs an aptitude full-upgrade. '
- ' If full, performs an aptitude full-upgrade. '
- ' If dist, performs an apt-get dist-upgrade. '
- ' If dist, performs an apt-get dist-upgrade. '
- ' Note: This does not upgrade a specific package, use state=latest for that. '
- ' Note: This does not upgrade a specific package, use state=latest for that. '
- ' Note: Since 2.4, apt-get is used as a fall-back if aptitude is not present. '
version_added : " 1.1 "
version_added : " 1.1 "
required : false
required : false
default : " no "
default : " no "
@ -126,14 +127,21 @@ options:
required : false
required : false
default : false
default : false
version_added : " 2.1 "
version_added : " 2.1 "
force_apt_get :
description :
- Force usage of apt - get instead of aptitude
required : false
default : false
version_added : " 2.4 "
requirements :
requirements :
- python - apt ( python 2 )
- python - apt ( python 2 )
- python3 - apt ( python 3 )
- python3 - apt ( python 3 )
- aptitude
- aptitude ( before 2.4 )
author : " Matthew Williams (@mgwilliams) "
author : " Matthew Williams (@mgwilliams) "
notes :
notes :
- Three of the upgrade modes ( C ( full ) , C ( safe ) and its alias C ( yes ) ) require C ( aptitude ) , otherwise
- Three of the upgrade modes ( C ( full ) , C ( safe ) and its alias C ( yes ) )
C ( apt - get ) suffices .
required C ( aptitude ) up to 2.3 , since 2.4 C ( apt - get ) is used as a
fall - back .
'''
'''
EXAMPLES = '''
EXAMPLES = '''
@ -711,6 +719,7 @@ def cleanup(m, purge=False, force=False, operation=None,
def upgrade ( m , mode = " yes " , force = False , default_release = None ,
def upgrade ( m , mode = " yes " , force = False , default_release = None ,
use_apt_get = False ,
dpkg_options = expand_dpkg_options ( DPKG_OPTIONS ) ) :
dpkg_options = expand_dpkg_options ( DPKG_OPTIONS ) ) :
if m . check_mode :
if m . check_mode :
check_arg = ' --simulate '
check_arg = ' --simulate '
@ -719,14 +728,18 @@ def upgrade(m, mode="yes", force=False, default_release=None,
apt_cmd = None
apt_cmd = None
prompt_regex = None
prompt_regex = None
if mode == " dist " :
if mode == " dist " or ( mode == " full " and use_apt_get ) :
# apt-get dist-upgrade
# apt-get dist-upgrade
apt_cmd = APT_GET_CMD
apt_cmd = APT_GET_CMD
upgrade_command = " dist-upgrade "
upgrade_command = " dist-upgrade "
elif mode == " full " :
elif mode == " full " and not use_apt_get :
# aptitude full-upgrade
# aptitude full-upgrade
apt_cmd = APTITUDE_CMD
apt_cmd = APTITUDE_CMD
upgrade_command = " full-upgrade "
upgrade_command = " full-upgrade "
else :
if use_apt_get :
apt_cmd = APT_GET_CMD
upgrade_command = " upgrade --with-new-pkgs --autoremove "
else :
else :
# aptitude safe-upgrade # mode=yes # default
# aptitude safe-upgrade # mode=yes # default
apt_cmd = APTITUDE_CMD
apt_cmd = APTITUDE_CMD
@ -860,6 +873,7 @@ def main():
autoremove = dict ( type = ' bool ' , default = ' no ' ) ,
autoremove = dict ( type = ' bool ' , default = ' no ' ) ,
autoclean = dict ( type = ' bool ' , default = ' no ' ) ,
autoclean = dict ( type = ' bool ' , default = ' no ' ) ,
only_upgrade = dict ( type = ' bool ' , default = False ) ,
only_upgrade = dict ( type = ' bool ' , default = False ) ,
force_apt_get = dict ( type = ' bool ' , default = False ) ,
allow_unauthenticated = dict ( default = ' no ' , aliases = [ ' allow-unauthenticated ' ] , type = ' bool ' ) ,
allow_unauthenticated = dict ( default = ' no ' , aliases = [ ' allow-unauthenticated ' ] , type = ' bool ' ) ,
) ,
) ,
mutually_exclusive = [ [ ' package ' , ' upgrade ' , ' deb ' ] ] ,
mutually_exclusive = [ [ ' package ' , ' upgrade ' , ' deb ' ] ] ,
@ -894,8 +908,11 @@ def main():
if p [ ' upgrade ' ] == ' no ' :
if p [ ' upgrade ' ] == ' no ' :
p [ ' upgrade ' ] = None
p [ ' upgrade ' ] = None
if not APTITUDE_CMD and p . get ( ' upgrade ' , None ) in [ ' full ' , ' safe ' , ' yes ' ] :
use_apt_get = p [ ' force_apt_get ' ]
module . fail_json ( msg = " Could not find aptitude. Please ensure it is installed. " )
if not use_apt_get and not APTITUDE_CMD and p . get ( ' upgrade ' , None ) in [ ' full ' , ' safe ' , ' yes ' ] :
module . warn ( " Could not find aptitude. Using apt-get instead " )
use_apt_get = True
updated_cache = False
updated_cache = False
updated_cache_time = 0
updated_cache_time = 0
@ -956,7 +973,7 @@ def main():
force_yes = p [ ' force ' ]
force_yes = p [ ' force ' ]
if p [ ' upgrade ' ] :
if p [ ' upgrade ' ] :
upgrade ( module , p [ ' upgrade ' ] , force_yes , p [ ' default_release ' ] , dpkg_options)
upgrade ( module , p [ ' upgrade ' ] , force_yes , p [ ' default_release ' ] , use_apt_get, dpkg_options)
if p [ ' deb ' ] :
if p [ ' deb ' ] :
if p [ ' state ' ] != ' present ' :
if p [ ' state ' ] != ' present ' :
@ -976,7 +993,7 @@ def main():
if latest and all_installed :
if latest and all_installed :
if packages :
if packages :
module . fail_json ( msg = ' unable to install additional packages when ugrading all installed packages ' )
module . fail_json ( msg = ' unable to install additional packages when ugrading all installed packages ' )
upgrade ( module , ' yes ' , force_yes , p [ ' default_release ' ] , dpkg_options)
upgrade ( module , ' yes ' , force_yes , p [ ' default_release ' ] , use_apt_get, dpkg_options)
if packages :
if packages :
for package in packages :
for package in packages :