20
20
import yaml
21
21
22
22
# Import salt libs
23
+ from salt .modules .cmdmod import _parse_env
23
24
import salt .utils
24
25
from salt ._compat import string_types
25
26
from salt .exceptions import (
51
52
52
53
_MODIFY_OK = frozenset (['uri' , 'comps' , 'architectures' , 'disabled' ,
53
54
'file' , 'dist' ])
55
+ DPKG_ENV_VARS = {
56
+ 'APT_LISTBUGS_FRONTEND' : 'none' ,
57
+ 'APT_LISTCHANGES_FRONTEND' : 'none' ,
58
+ 'DEBIAN_FRONTEND' : 'noninteractive' ,
59
+ 'UCF_FORCE_CONFFOLD' : '1' ,
60
+ }
54
61
55
62
# Define the module's virtual name
56
63
__virtualname__ = 'pkg'
@@ -72,14 +79,8 @@ def __init__():
72
79
non-interactive.
73
80
'''
74
81
if __virtual__ ():
75
- env_vars = {
76
- 'APT_LISTBUGS_FRONTEND' : 'none' ,
77
- 'APT_LISTCHANGES_FRONTEND' : 'none' ,
78
- 'DEBIAN_FRONTEND' : 'noninteractive' ,
79
- 'UCF_FORCE_CONFFOLD' : '1' ,
80
- }
81
82
# Export these puppies so they persist
82
- os .environ .update (env_vars )
83
+ os .environ .update (DPKG_ENV_VARS )
83
84
84
85
85
86
def _get_ppa_info_from_launchpad (owner_name , ppa_name ):
@@ -484,7 +485,9 @@ def install(name=None,
484
485
if refreshdb :
485
486
refresh_db ()
486
487
487
- __salt__ ['cmd.run' ](cmd , env = kwargs .get ('env' ), python_shell = False )
488
+ env = _parse_env (kwargs .get ('env' ))
489
+ env .update (DPKG_ENV_VARS .copy ())
490
+ __salt__ ['cmd.run' ](cmd , python_shell = False , env = env )
488
491
__context__ .pop ('pkg.list_pkgs' , None )
489
492
new = list_pkgs ()
490
493
return salt .utils .compare_dicts (old , new )
@@ -608,6 +611,11 @@ def upgrade(refresh=True, dist_upgrade=True):
608
611
609
612
salt '*' pkg.upgrade
610
613
'''
614
+ ret = {'changes' : {},
615
+ 'result' : True ,
616
+ 'comment' : '' ,
617
+ }
618
+
611
619
if salt .utils .is_true (refresh ):
612
620
refresh_db ()
613
621
@@ -618,10 +626,19 @@ def upgrade(refresh=True, dist_upgrade=True):
618
626
else :
619
627
cmd = ['apt-get' , '-q' , '-y' , '-o' , 'DPkg::Options::=--force-confold' ,
620
628
'-o' , 'DPkg::Options::=--force-confdef' , 'upgrade' ]
621
- __salt__ ['cmd.run' ](cmd , python_shell = False , output_loglevel = 'trace' , env = {'DEBIAN_FRONTEND' : 'noninteractive' })
622
- __context__ .pop ('pkg.list_pkgs' , None )
623
- new = list_pkgs ()
624
- return salt .utils .compare_dicts (old , new )
629
+ call = __salt__ ['cmd.run_all' ](cmd , python_shell = False , output_loglevel = 'trace' ,
630
+ env = DPKG_ENV_VARS .copy ())
631
+ if call ['retcode' ] != 0 :
632
+ ret ['result' ] = False
633
+ if 'stderr' in call :
634
+ ret ['comment' ] += call ['stderr' ]
635
+ if 'stdout' in call :
636
+ ret ['comment' ] += call ['stdout' ]
637
+ else :
638
+ __context__ .pop ('pkg.list_pkgs' , None )
639
+ new = list_pkgs ()
640
+ ret ['changes' ] = salt .utils .compare_dicts (old , new )
641
+ return ret
625
642
626
643
627
644
def hold (name = None , pkgs = None , sources = None , ** kwargs ): # pylint: disable=W0613
0 commit comments