glennr
glennr

Reputation: 2199

Deploy a buildout using Ansible

I have a simple Python program, which implements a prometheus exporter, that uses zdaemon via buildout. How can I deploy this using Ansible, while retaining the isolated environment that buildout makes?

I've looked at Ansible's pip module but if I make a package using buildout setup ... then I just get myscript packaged without the zdaemon stuff that buildout adds.

The way I'm thinking about to do this is to install the 'bin/server' that buildout makes on the server and and run it from cron's @reboot, but of course that won't work directly because buildout uses paths on the build machine in the scripts it generates.

buildout.cfg:

develop = .
parts = server

[server]
recipe = zc.zdaemonrecipe
program = ${buildout:bin-directory}/myscript.py
eggs =
    myscript
    zdaemon

setup.py:

from setuptools import setup, find_packages
setup(
    name="myscript",
    version="0.1",
    packages=find_packages(),
    scripts=['myscript.py'],
    install_requires=['prometheus_client']
)

Upvotes: -1

Views: 206

Answers (1)

glennr
glennr

Reputation: 2199

Apparently buildout doesn't work like that and the only way to get the isolated buildout environment is to run buildout on the target machine.

If that is not desirable, then an alternative is to create a setuptools package (using buildout setup path/to/setup.py [sdist|bdist]) that can be installed via pip. This will be an ordinary Python package and won't have Buildout's isolation. In this case zdaemon has to be configured manually and it's config file included in the package. The package, which will be a .tar.gz file can then be copied to the target and installed using pip, which can be done using Ansible.

Upvotes: 0

Related Questions