@ -84,7 +84,9 @@ options:
description :
description :
- The Python executable used for creating the virtual environment .
- The Python executable used for creating the virtual environment .
For example C ( python3 .5 ) , C ( python2 .7 ) . When not specified , the
For example C ( python3 .5 ) , C ( python2 .7 ) . When not specified , the
Python version used to run the ansible module is used .
Python version used to run the ansible module is used . This parameter
should not be used when C ( virtualenv_command ) is using C ( pyvenv ) or
the C ( - m venv ) module .
required : false
required : false
default : null
default : null
state :
state :
@ -457,16 +459,27 @@ def main():
if ' --no-site-packages ' in cmd_opts :
if ' --no-site-packages ' in cmd_opts :
cmd + = ' --no-site-packages '
cmd + = ' --no-site-packages '
if virtualenv_python :
# -p is a virtualenv option, not compatible with pyenv or venv
cmd + = ' -p %s ' % virtualenv_python
# this if validates if the command being used is not any of them
elif PY3 :
if not any ( ex in module . params [ ' virtualenv_command ' ] for ex in ( ' pyvenv ' , ' -m venv ' ) ) :
# Ubuntu currently has a patch making virtualenv always
if virtualenv_python :
# try to use python2. Since Ubuntu16 works without
cmd + = ' -p %s ' % virtualenv_python
# python2 installed, this is a problem. This code mimics
elif PY3 :
# the upstream behaviour of using the python which invoked
# Ubuntu currently has a patch making virtualenv always
# virtualenv to determine which python is used inside of
# try to use python2. Since Ubuntu16 works without
# the virtualenv (when none are specified).
# python2 installed, this is a problem. This code mimics
cmd + = ' -p %s ' % sys . executable
# the upstream behaviour of using the python which invoked
# virtualenv to determine which python is used inside of
# the virtualenv (when none are specified).
cmd + = ' -p %s ' % sys . executable
# if venv or pyvenv are used and virtualenv_python is defined, then
# virtualenv_python is ignored, this has to be acknowledged
elif module . params [ ' virtualenv_python ' ] :
module . fail_json (
msg = ' virtualenv_python should not be used when '
' using the venv module or pyvenv as virtualenv_command '
)
cmd = " %s %s " % ( cmd , env )
cmd = " %s %s " % ( cmd , env )
rc , out_venv , err_venv = module . run_command ( cmd , cwd = chdir )
rc , out_venv , err_venv = module . run_command ( cmd , cwd = chdir )