Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

So here's a snippet from my manifest (based on this module: https://github.com/stankevich/puppet-python):

python::virtualenv { $virtualenv_dir:
ensure => present,
version => 'system',
systempkgs => false,
distribute => false,
owner => $user,
group => $group,
}

That works fine when I run puppet apply for the first time. Second time it fails though:

Already using interpreter /usr/bin/python
Traceback (most recent call last):
File "/usr/bin/virtualenv", line 3, in 
virtualenv.main()
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 938, in main
never_download=options.never_download)
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1039, in create_environment
site_packages=site_packages, clear=clear))
File "/usr/lib/python2.7/dist-packages/virtualenv.py", line 1274, in install_python
shutil.copyfile(executable, py_executable)
File "/usr/lib/python2.7/shutil.py", line 83, in copyfile
with open(dst, 'wb') as fdst:
IOError: [Errno 26] Text file busy: '/usr/local/myapp/venv/bin/python'

This is probably because I have a bunch of background processes running that using the Python binary from virtualenv (Celery workers, uwsgi workers etc).

Is there a way to only init the virtualenv first time? There is no need to run virtualenv command once the directory is created, right?

share|improve this question
    
Could this be related to the 'Fix path for unless statement' commit (Jan 1, 2014)? Looking at the code, that may have something to do with this type of issue. There are several other updates recently so you might look into updating the module. –  jdkindy Jan 7 at 14:37

1 Answer 1

The following class will create a virtual env. "creates" limits the command to only be run if the virtualenv doesn't exist

class virtualenv ( $virtualenv_dir ) {
  package{'python-virtualenv':
    ensure => installed,
  }

  exec{'create_virtualenv':
    creates => $virtualenv_dir,
    command => "virtualenv $virtualen_dir",
    require => Package['python-virtualenv'],
  } 
}

Call the class with the following:

class {'virtualenv':
  virtualenv_dir => '/path/to/virtualenv',
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.